The deploy job lived in lint.yml and needed only eslint, while jest and npm audit ran in separate workflows. A merge that failed its tests still deployed to production. (#45 phase 1) - Combine everything into .gitea/workflows/ci.yml with jobs lint, test, audit, deploy and notify. Deploy needs all three checks and runs only on push to main. - Builds are reproducible: npm ci everywhere, eslint from the lockfile (new `npm run lint`), and setup-node pinned to Node 20 (production). - Actions are pinned to full commit SHAs, with the version in a comment, following tinker_tickets. - Workflow permissions default to contents: read; only deploy can write (for its tag). A deploy-production concurrency group queues deploys instead of running two at once. Superseded branch runs are cancelled. - The deploy payload now carries the sha and a timestamp, so signatures differ per deploy (the server verifies them in phase 2). After the webhook, CI waits until Pulse is serving again before tagging. - The Matrix alert now fires for any failed job on main, for the weekly audit, and for every successful deploy. - New lint step: fail on em or en dashes in Pulse-owned files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
151 lines
5.8 KiB
YAML
151 lines
5.8 KiB
YAML
name: CI
|
|
|
|
# One pipeline: lint, test and audit must all pass before main deploys (#45).
|
|
# Actions are pinned to full commit SHAs (version in the trailing comment).
|
|
|
|
on:
|
|
push:
|
|
branches: ["**"]
|
|
pull_request:
|
|
branches: ["**"]
|
|
schedule:
|
|
- cron: '0 6 * * 1' # weekly dependency audit against new advisories
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
concurrency:
|
|
group: ci-${{ github.ref }}
|
|
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
|
|
|
|
env:
|
|
NODE_VERSION: '20' # matches production (CT 122) and the worker (CT 153)
|
|
|
|
jobs:
|
|
lint:
|
|
name: Lint (eslint)
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
|
|
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
|
|
with:
|
|
node-version: ${{ env.NODE_VERSION }}
|
|
cache: npm
|
|
- name: Install dependencies (lockfile only)
|
|
run: npm ci
|
|
- name: Run ESLint
|
|
run: npm run lint
|
|
- name: No em or en dashes (house style)
|
|
run: |
|
|
# Pulse-owned files only: the vendored design system is fixed upstream.
|
|
if git grep -nP '[\x{2013}\x{2014}]|—|–|\\u201[34]|̵[12];|ȁ[34];' \
|
|
-- . ':!public/web_template' ':!package-lock.json'; then
|
|
echo "::error::Em or en dashes found (listed above). Use a hyphen, colon, comma or 'to'."
|
|
exit 1
|
|
fi
|
|
|
|
test:
|
|
name: Test (jest)
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
|
|
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
|
|
with:
|
|
node-version: ${{ env.NODE_VERSION }}
|
|
cache: npm
|
|
- name: Install dependencies (lockfile only)
|
|
run: npm ci
|
|
- name: Run jest with coverage
|
|
run: npm test -- --ci
|
|
|
|
audit:
|
|
name: Security (npm audit)
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
|
|
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
|
|
with:
|
|
node-version: ${{ env.NODE_VERSION }}
|
|
- name: Audit production and dev dependencies
|
|
run: npm audit --audit-level=high
|
|
|
|
deploy:
|
|
name: Deploy
|
|
runs-on: ubuntu-latest
|
|
needs: [lint, test, audit]
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
# Never run two deploys at once; queue instead of cancelling a deploy mid-way.
|
|
concurrency:
|
|
group: deploy-production
|
|
cancel-in-progress: false
|
|
permissions:
|
|
contents: write # deploy tag
|
|
steps:
|
|
- name: Trigger webhook
|
|
env:
|
|
WEBHOOK_SECRET: ${{ secrets.WEBHOOK_SECRET }}
|
|
GIT_REF: ${{ github.ref }}
|
|
GIT_SHA: ${{ github.sha }}
|
|
run: |
|
|
# sha and timestamp make every signature unique; the server starts
|
|
# verifying them in #45 phase 2 (until then it deploys origin/main).
|
|
PAYLOAD="{\"ref\":\"${GIT_REF}\",\"sha\":\"${GIT_SHA}\",\"ts\":$(date +%s)}"
|
|
SIG=$(echo -n "$PAYLOAD" | openssl dgst -sha256 -hmac "$WEBHOOK_SECRET" | awk '{print $2}')
|
|
curl -sf --connect-timeout 10 \
|
|
-X POST \
|
|
-H "Content-Type: application/json" \
|
|
-H "X-Gitea-Signature: ${SIG}" \
|
|
-d "$PAYLOAD" \
|
|
"http://10.10.10.65:9000/hooks/pulse-deploy"
|
|
|
|
- name: Wait for Pulse to come back
|
|
run: |
|
|
# Liveness only: the webhook returns before the restart finishes, so this
|
|
# can't prove the new commit is running. /healthz with the git SHA
|
|
# replaces it in #45 phase 2. The unauthenticated root answers 401 when up.
|
|
sleep 30
|
|
for i in $(seq 1 24); do
|
|
code=$(curl -s -o /dev/null -w '%{http_code}' --connect-timeout 5 http://10.10.10.65:8080/ || true)
|
|
if [ "$code" = "401" ]; then echo "Pulse is serving (HTTP $code)"; exit 0; fi
|
|
sleep 5
|
|
done
|
|
echo "::error::Pulse did not come back within 2 minutes after deploy"
|
|
exit 1
|
|
|
|
- name: Tag deployed commit
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
TAG="deploy-$(date -u +%Y.%m.%d)-${{ github.run_number }}"
|
|
curl -sf -X POST \
|
|
-H "Authorization: token $GITHUB_TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"tag_name\":\"${TAG}\",\"target\":\"${{ github.sha }}\",\"message\":\"Deployed to production\"}" \
|
|
"https://code.lotusguild.org/api/v1/repos/${{ github.repository }}/tags"
|
|
|
|
notify:
|
|
name: Notify
|
|
runs-on: ubuntu-latest
|
|
needs: [lint, test, audit, deploy]
|
|
# Alert on any failure on main or in the weekly audit, and on every deploy outcome.
|
|
if: >-
|
|
always() && (
|
|
(failure() && (github.ref == 'refs/heads/main' || github.event_name == 'schedule')) ||
|
|
needs.deploy.result == 'success'
|
|
)
|
|
steps:
|
|
- name: Send Matrix alert
|
|
env:
|
|
MATRIX_WEBHOOK_URL: ${{ secrets.MATRIX_WEBHOOK_URL }}
|
|
REPO: ${{ github.repository }}
|
|
BRANCH: ${{ github.ref_name }}
|
|
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
|
RESULTS: "lint=${{ needs.lint.result }} test=${{ needs.test.result }} audit=${{ needs.audit.result }} deploy=${{ needs.deploy.result }}"
|
|
DEPLOYED: ${{ needs.deploy.result == 'success' }}
|
|
run: |
|
|
if [ -z "$MATRIX_WEBHOOK_URL" ] || [ "$MATRIX_WEBHOOK_URL" = "CONFIGURE_ME" ]; then exit 0; fi
|
|
if [ "$DEPLOYED" = "true" ]; then MSG="DEPLOYED: ${REPO} @ ${BRANCH} (${GITHUB_SHA:0:7})"; else MSG="CI FAILED: ${REPO} @ ${BRANCH} [${RESULTS}]"; fi
|
|
curl -sf -X POST "$MATRIX_WEBHOOK_URL" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"text\":\"${MSG}: ${RUN_URL}\"}"
|