MC/.forgejo/workflows/web-deploy.yml

93 lines
3.7 KiB
YAML

name: DuneRealms Web CI
on:
push:
branches:
- main
paths:
- 'website/**'
- '.forgejo/workflows/web-deploy.yml'
- '.forgejo/tests/web-deploy.test.mjs'
workflow_dispatch:
jobs:
web:
if: github.repository == 'unimatrix/web' || (github.repository == 'dev/MC' && github.event_name == 'workflow_dispatch')
runs-on: dune-ci
steps:
- name: Check out exact revision
shell: bash
env:
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
git init .
git -c http.extraheader="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$REPO_TOKEN" | base64 -w0)" fetch --depth=1 "https://www.dunerealms.com/git/${GITHUB_REPOSITORY}.git" "$GITHUB_SHA"
git checkout --detach FETCH_HEAD
test "$(git rev-parse HEAD)" = "$GITHUB_SHA"
- name: Install Node 22
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Prepare publication comparison
if: github.repository == 'unimatrix/web' && github.ref == 'refs/heads/main'
shell: bash
env:
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BEFORE=$(node -e 'const fs=require("fs");const p=process.env.GITHUB_EVENT_PATH;const e=p&&fs.existsSync(p)?JSON.parse(fs.readFileSync(p)):{};process.stdout.write(e.before||"");')
if [[ ! "$BEFORE" =~ ^[0-9a-f]{40}$ || "$BEFORE" =~ ^0+$ ]]; then
git -c http.extraheader="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$REPO_TOKEN" | base64 -w0)" fetch --deepen=1 https://www.dunerealms.com/git/unimatrix/web.git "$GITHUB_SHA"
BEFORE=$(git rev-parse HEAD^)
else
git -c http.extraheader="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$REPO_TOKEN" | base64 -w0)" fetch --depth=1 https://www.dunerealms.com/git/unimatrix/web.git "$BEFORE"
fi
node website/scripts/publication-changes.mjs "$BEFORE" "$GITHUB_SHA"
- name: Verify deployment policy
run: |
node --test .forgejo/tests/web-deploy.test.mjs
python3 -m unittest discover -s website/ops -p 'test_*.py'
bash -n website/ops/dunerealms-ci-trigger website/ops/dunerealms-build-release
- name: Build and test website
working-directory: website
run: |
corepack enable
corepack pnpm install --frozen-lockfile
corepack pnpm build
corepack pnpm test
- name: Upload tested deployment scripts
uses: actions/upload-artifact@v3
with:
name: DuneRealms-Website-Operations
path: website/dist/deployment/
if-no-files-found: error
retention-days: 7
- name: Upload website build
if: github.repository == 'unimatrix/web' && github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v3
with:
name: DuneRealms-Website
path: website/dist/
if-no-files-found: error
retention-days: 1
- name: Trigger deployment after successful CI
if: github.repository == 'unimatrix/web' && github.ref == 'refs/heads/main'
shell: bash
env:
DEPLOY_KEY: ${{ secrets.DUNEREALMS_DEPLOY_KEY }}
run: |
install -m 700 -d ~/.ssh
printf '%s\n' "$DEPLOY_KEY" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
trap 'rm -f ~/.ssh/deploy_key' EXIT
printf '%s\n' '91.107.196.242 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIC8x/XocsIz41fWHGty0DbZhSvafSQFt9jaHHgzdr55W root@ubuntu-4gb-fsn1-1' >> ~/.ssh/known_hosts
ssh -p 22 -i ~/.ssh/deploy_key -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=yes dunedeploy@91.107.196.242 "$GITHUB_SHA"
rm -f ~/.ssh/deploy_key