feat(ci): deploy verified releases with rollback

This commit is contained in:
2026-09-07 00:18:34 +03:30
parent 2aa140bbb0
commit bc2feba49a
2 changed files with 229 additions and 0 deletions

115
.gitea/workflows/ci-cd.yml Normal file
View File

@@ -0,0 +1,115 @@
name: Test and deploy
on:
pull_request:
push:
branches:
- main
workflow_dispatch:
jobs:
verify:
name: Verify production build
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- name: Install dependencies
run: npm ci
- name: Lint
run: npm run lint
- name: Type-check
run: npm run typecheck
- name: Build static site
run: npm run build
- name: Test static export
run: npm test
- name: Audit production dependencies
run: npm audit --omit=dev --audit-level=high
deploy:
name: Deploy production
needs: verify
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 20
environment: production
env:
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }}
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
DEPLOY_KNOWN_HOSTS: ${{ secrets.DEPLOY_KNOWN_HOSTS }}
SSH_PRIVATE_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Configure SSH
shell: bash
run: |
set -Eeuo pipefail
: "${DEPLOY_HOST:?DEPLOY_HOST secret is required}"
: "${DEPLOY_USER:?DEPLOY_USER secret is required}"
: "${DEPLOY_PATH:?DEPLOY_PATH secret is required}"
: "${DEPLOY_KNOWN_HOSTS:?DEPLOY_KNOWN_HOSTS secret is required}"
: "${SSH_PRIVATE_KEY:?DEPLOY_SSH_KEY secret is required}"
DEPLOY_PORT="${DEPLOY_PORT:-22}"
echo "DEPLOY_PORT=$DEPLOY_PORT" >> "$GITHUB_ENV"
install -d -m 700 "$HOME/.ssh"
printf '%s\n' "$SSH_PRIVATE_KEY" > "$HOME/.ssh/deploy_key"
chmod 600 "$HOME/.ssh/deploy_key"
printf '%s\n' "$DEPLOY_KNOWN_HOSTS" > "$HOME/.ssh/known_hosts"
chmod 600 "$HOME/.ssh/known_hosts"
- name: Package release
shell: bash
run: |
set -Eeuo pipefail
git archive \
--format=tar.gz \
--output="$RUNNER_TEMP/portfolio-$GITHUB_SHA.tar.gz" \
HEAD
- name: Upload and activate release
shell: bash
run: |
set -Eeuo pipefail
remote_archive="/tmp/portfolio-$GITHUB_SHA.tar.gz"
ssh_options=(
-i "$HOME/.ssh/deploy_key"
-o BatchMode=yes
-o StrictHostKeyChecking=yes
-p "$DEPLOY_PORT"
)
scp \
-i "$HOME/.ssh/deploy_key" \
-o BatchMode=yes \
-o StrictHostKeyChecking=yes \
-P "$DEPLOY_PORT" \
"$RUNNER_TEMP/portfolio-$GITHUB_SHA.tar.gz" \
"$DEPLOY_USER@$DEPLOY_HOST:$remote_archive"
printf -v remote_command \
'bash -s -- %q %q %q' \
"$DEPLOY_PATH" "$GITHUB_SHA" "$remote_archive"
ssh "${ssh_options[@]}" \
"$DEPLOY_USER@$DEPLOY_HOST" \
"$remote_command" \
< scripts/deploy-release.sh