70 lines
1.6 KiB
YAML
70 lines
1.6 KiB
YAML
|
|
name: Moorly Website CI
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- dev
|
|
- main
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: linux-x64
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Check Node version
|
|
run: |
|
|
node --version
|
|
npm --version
|
|
test "$(node -p 'process.versions.node.split(".")[0]')" = "24"
|
|
|
|
- name: Install dependencies
|
|
run: npm ci
|
|
|
|
- name: Check
|
|
run: npm run check
|
|
|
|
- name: Build
|
|
run: npm run build
|
|
|
|
- name: Security audit
|
|
run: npm audit
|
|
|
|
|
|
- name: Deploy website
|
|
if: github.event_name == 'push' && (github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/main')
|
|
env:
|
|
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
|
|
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
|
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
|
run: |
|
|
set -eu
|
|
|
|
case "$GITHUB_REF" in
|
|
refs/heads/dev)
|
|
DEPLOY_PATH="/var/MoorlyWeb/dev/"
|
|
;;
|
|
refs/heads/main)
|
|
DEPLOY_PATH="/var/MoorlyWeb/production/"
|
|
;;
|
|
*)
|
|
echo "Unsupported branch: $GITHUB_REF"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
KEY_FILE="$(mktemp)"
|
|
trap 'rm -f "$KEY_FILE"' EXIT
|
|
|
|
printf '%s\n' "$DEPLOY_SSH_KEY" > "$KEY_FILE"
|
|
chmod 600 "$KEY_FILE"
|
|
|
|
rsync -az --delete \
|
|
-e "ssh -i $KEY_FILE -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile=$HOME/.ssh/known_hosts" \
|
|
dist/ "${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}"
|
|
|