|
| 1 | +# vim: set colorcolumn=: |
| 2 | +name: deployment |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - develop |
| 8 | + |
| 9 | +env: |
| 10 | + PHP_VERSION: '8.1' |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + |
| 15 | +jobs: |
| 16 | + linter: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - name: Checkout |
| 20 | + uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Update apt cache |
| 23 | + run: sudo apt-get update |
| 24 | + |
| 25 | + - name: Install php ${{ env.PHP_VERSION }} |
| 26 | + run: sudo apt-get install php${{ env.PHP_VERSION }}-cli |
| 27 | + |
| 28 | + - name: Validate composer.json and composer.lock |
| 29 | + run: composer validate --strict |
| 30 | + |
| 31 | + - name: Cache Composer packages |
| 32 | + id: composer-cache |
| 33 | + uses: actions/cache@v4 |
| 34 | + with: |
| 35 | + path: lib |
| 36 | + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} |
| 37 | + restore-keys: | |
| 38 | + ${{ runner.os }}-php- |
| 39 | +
|
| 40 | + - name: Install composer/vendor dependencies |
| 41 | + run: composer install --prefer-dist --no-progress --ignore-platform-reqs |
| 42 | + |
| 43 | + - name: Validate PHP syntax |
| 44 | + run: bash -c 'set -e;for file in $(find ./src -type f -regex ".*\.\(php\|phtml\)" -print); do php -e -l -f "$file"; done' |
| 45 | + |
| 46 | + deploy: |
| 47 | + name: Deploy to VPS |
| 48 | + needs: linter |
| 49 | + runs-on: ubuntu-latest |
| 50 | + environment: production |
| 51 | + steps: |
| 52 | + - name: Checkout Code |
| 53 | + uses: actions/checkout@v4 |
| 54 | + |
| 55 | + - name: Compress Artifacts |
| 56 | + run: zip -r project.zip . |
| 57 | + |
| 58 | + - name: Deploy to VPS |
| 59 | + env: |
| 60 | + SSH_HOST: ${{ secrets.SSH_HOST }} |
| 61 | + SSH_PORT: ${{ secrets.SSH_PORT }} |
| 62 | + SSH_USER: ${{ secrets.SSH_USER }} |
| 63 | + SSH_KEY: ${{ secrets.SSH_KEY }} # SSH private key stored as a GitHub secret |
| 64 | + SSH_WEB_PATH: ${{ secrets.SSH_WEB_PATH }} |
| 65 | + run: | |
| 66 | + # Save the private key for SSH |
| 67 | + mkdir -p ~/.ssh |
| 68 | + echo "$SSH_KEY" > "~/.ssh/id_$SSH_USER" |
| 69 | + chmod 600 "~/.ssh/id_$SSH_USER" |
| 70 | +
|
| 71 | + # Copy the artifact to the VPS |
| 72 | + scp -i "~/.ssh/id_$SSH_USER" -P "$SSH_PORT" project.zip "$SSH_USER@$SSH_HOST:${SSH_WEB_PATH:.}" |
| 73 | +
|
| 74 | + # Connect to the VPS and unzip the project |
| 75 | + ssh -i "~/.ssh/id_$SSH_USER" -p "$SSH_PORT" "$SSH_USER@$SSH_HOST" << 'EOF' |
| 76 | + cd ${SSH_WEB_PATH:.}/ |
| 77 | + unzip ./project.zip |
| 78 | + rm ./project.zip |
| 79 | +EOF |
0 commit comments