Skip to content

CI/CD - Deploy to VM #20

CI/CD - Deploy to VM

CI/CD - Deploy to VM #20

Workflow file for this run

# Created with assistance from GPT-5.6 Terra High
name: CI/CD - Deploy to VM
on:
workflow_run:
workflows: ["CI/CD - Linter, formatter and tests"]
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