CI/CD - Deploy to VM #18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Created with assistance from GPT-5.6 Terra High | |
| name: CI/CD - Deploy to VM | |
| on: | |
| workflow_run: | |
| workflows: ["CI/CD - Run lint and formatting checkout"] | |
| types: [completed] | |
| branches: | |
| - main | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: production-deploy | |
| cancel-in-progress: false | |
| jobs: | |
| deploy: | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| runs-on: [self-hosted] | |
| timeout-minutes: 10 | |
| env: | |
| SITE_ROOT: /var/www/html/project1 | |
| npm_config_cache: ${{ github.workspace }}/.npm-cache | |
| TMPDIR: ${{ github.workspace }}/.tmp | |
| steps: | |
| - name: Check out source | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.workflow_run.head_sha }} | |
| - name: Install dependencies | |
| run: | | |
| mkdir -p "$TMPDIR" | |
| npm ci --no-audit --no-fund | |
| - name: Build app | |
| run: npm run build | |
| - name: Deploy app to Apache | |
| run: | | |
| set -euo pipefail | |
| test -d "$SITE_ROOT" | |
| test -f dist/index.html | |
| rsync -a --delete --chmod=D755,F644 \ | |
| dist/ "$SITE_ROOT/" | |
| - name: Clean up job files | |
| if: always() | |
| run: | | |
| set -euo pipefail | |
| # Removes the checkout, node_modules, dist, npm cache, and TMPDIR. | |
| # Keeps the runner's own _work directory intact. | |
| if [ -d "$GITHUB_WORKSPACE" ]; then | |
| find "$GITHUB_WORKSPACE" -mindepth 1 -maxdepth 1 \ | |
| -exec rm -rf -- {} + | |
| fi |