From fde2c49ecaa642da06fa2a10e448d2a798c68810 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Sun, 22 Nov 2026 02:02:07 -0500 Subject: [PATCH 1/2] CI: one pipeline, deploy gated on lint, test and audit 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 --- .gitea/workflows/ci.yml | 150 ++++++++++++++++++++++++++++++++++ .gitea/workflows/lint.yml | 71 ---------------- .gitea/workflows/security.yml | 22 ----- .gitea/workflows/test.yml | 20 ----- README.md | 2 +- package.json | 3 +- 6 files changed, 153 insertions(+), 115 deletions(-) create mode 100644 .gitea/workflows/ci.yml delete mode 100644 .gitea/workflows/lint.yml delete mode 100644 .gitea/workflows/security.yml delete mode 100644 .gitea/workflows/test.yml diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..4ab44f7 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,150 @@ +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}\"}" diff --git a/.gitea/workflows/lint.yml b/.gitea/workflows/lint.yml deleted file mode 100644 index 11d0826..0000000 --- a/.gitea/workflows/lint.yml +++ /dev/null @@ -1,71 +0,0 @@ -name: Lint - -on: - push: - branches: ["**"] - pull_request: - branches: ["**"] - -jobs: - js-lint: - name: JS (eslint) - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Install ESLint - run: npm install --save-dev eslint@8 - - - name: Run ESLint - run: npx eslint --ext .js . - - notify-failure: - name: Notify on failure - runs-on: ubuntu-latest - needs: [js-lint] - if: failure() && github.event_name == 'push' - 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 }} - run: | - if [ -z "$MATRIX_WEBHOOK_URL" ] || [ "$MATRIX_WEBHOOK_URL" = "CONFIGURE_ME" ]; then exit 0; fi - curl -sf -X POST "$MATRIX_WEBHOOK_URL" \ - -H "Content-Type: application/json" \ - -d "{\"text\":\"CI FAILED: ${REPO} @ ${BRANCH} - ${RUN_URL}\"}" - - deploy: - name: Deploy - runs-on: ubuntu-latest - needs: [js-lint] - if: github.event_name == 'push' && github.ref == 'refs/heads/main' - permissions: - contents: write - steps: - - name: Trigger webhook - env: - WEBHOOK_SECRET: ${{ secrets.WEBHOOK_SECRET }} - GIT_REF: ${{ github.ref }} - run: | - PAYLOAD="{\"ref\":\"${GIT_REF}\"}" - 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: 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" diff --git a/.gitea/workflows/security.yml b/.gitea/workflows/security.yml deleted file mode 100644 index beab61d..0000000 --- a/.gitea/workflows/security.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Security - -on: - push: - branches: ["**"] - pull_request: - branches: ["**"] - schedule: - - cron: '0 6 * * 1' - -jobs: - npm-audit: - name: JS Security (npm audit) - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Install dependencies - run: npm install - - - name: Run npm audit - run: npm audit --audit-level=high diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml deleted file mode 100644 index cafa40b..0000000 --- a/.gitea/workflows/test.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Test - -on: - push: - branches: ["**"] - pull_request: - branches: ["**"] - -jobs: - jest: - name: JS Tests (jest) - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Install dependencies - run: npm install - - - name: Run jest - run: npm test diff --git a/README.md b/README.md index d0bfbc8..1bd47dc 100644 --- a/README.md +++ b/README.md @@ -589,7 +589,7 @@ MIT License - See LICENSE file for details | `security.yml` | `npm audit --audit-level=high` | Every push, PR, and weekly Monday 6am | | `deploy` job in `lint.yml` | Calls the `pulse-deploy` webhook on CT122 (10.10.10.65) to pull + restart | Push to `main` only, after lint passes | -Branch protection is enabled on `main`: the `lint.yml` check must pass before any PR can merge. +All CI lives in `.gitea/workflows/ci.yml`. Branch protection on `main` requires its `Lint (eslint)`, `Test (jest)` and `Security (npm audit)` checks, and the `Deploy` job only runs after all three pass on a push to `main`. Tests live in `tests/utils.test.js` and cover the pure utility functions in `lib/utils.js`: `validateWebhookUrl`, `applyParams`, `evalCondition`, `calculateNextRun`. diff --git a/package.json b/package.json index 72a4e1d..73ba602 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "main": "server.js", "scripts": { "start": "node server.js", - "test": "jest --coverage" + "test": "jest --coverage", + "lint": "eslint --ext .js ." }, "keywords": [], "author": "", From 6da2d1539781e9e4e42081da4b0243f28071c0c6 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Sun, 22 Nov 2026 02:04:26 -0500 Subject: [PATCH 2/2] CI: fix dash check matching itself; npm audit fix for production advisories - The dash check's own pattern contained the literal entities it searches for. Use &[mn]dash; so the check doesn't flag itself. - npm audit fix (lockfile only, no major bumps): proxy-addr 2.0.8 (critical), body-parser 2.4.0 (high), follow-redirects 1.16.3 (high, used by the worker through axios), qs 6.17.1, ip-address. The remaining glob/minimatch advisories are moderate, dev-only (jest) and need a breaking upgrade, so they stay below the high threshold. Co-Authored-By: Claude Opus 5.5 --- .gitea/workflows/ci.yml | 2 +- package-lock.json | 64 ++++++++++++++++++++++------------------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 4ab44f7..10d3d85 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -38,7 +38,7 @@ jobs: - 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];' \ + if git grep -nP '[\x{2013}\x{2014}]|&[mn]dash;|\\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 diff --git a/package-lock.json b/package-lock.json index fa9e2f5..c745d44 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1128,9 +1128,9 @@ } }, "node_modules/@jest/reporters/node_modules/glob": { - "version": "13.0.6", - "resolved": "https://registry.npmjs.org/glob/-/glob-13.0.6.tgz", - "integrity": "sha512-Wjlyrolmm8uDpm/ogGyXZXb1Z+Ca2B8NbJwqBVg0axK9GbBeoS7yGV6vjXnYdGm6X53iehEuxxbyiKp8QmN4Vw==", + "version": "13.0.7", + "resolved": "https://registry.npmjs.org/glob/-/glob-13.0.7.tgz", + "integrity": "sha512-wfsFgXQ8A3SEI9XGf7Nl3Y9l7ffSrGh7SUCT7vU/2CzYPep9kjxAn1S40F9OPKxAMGCVl7HtNlJhrCJUeUq83g==", "dev": true, "license": "BlueOak-1.0.0", "dependencies": { @@ -2366,9 +2366,9 @@ } }, "node_modules/babel-plugin-istanbul": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/babel-plugin-istanbul/-/babel-plugin-istanbul-8.0.0.tgz", - "integrity": "sha512-18wCskrN3DgbuBmp1gr7LBGT8xdz5xhQQqFvFhVxbkl8VBCrMKQ2YtqBWtUal1Zrc1HTuX0011+Brjw78TCFkg==", + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/babel-plugin-istanbul/-/babel-plugin-istanbul-8.0.2.tgz", + "integrity": "sha512-bXWZeWQvvCZcD2uHLWVbitr4s1+YqILBbWB/szXKtHXt6crLlD6mqxHZ0qWy2X/Xx5RtQvqqW80JHAXMlp+y1Q==", "dev": true, "license": "BSD-3-Clause", "workspaces": [ @@ -2461,18 +2461,18 @@ } }, "node_modules/body-parser": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.3.0.tgz", - "integrity": "sha512-2cGmJupaNgg+QUwVLAucDuWuoMZ6EX9iHDRswZ5lsNYEmwPaRknMPCLZz07yTzVq/83p4o/wzbDZbBrTvGGTIw==", + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.4.0.tgz", + "integrity": "sha512-Ifk1KcLrxaGt1occQagQNFNNOqRt1LFuehEnHHzB8Z6cRgIxRU1TBaiIsUiCdA+gy5PL7Y1IX31DNKkRmxtXjQ==", "license": "MIT", "dependencies": { "bytes": "^3.1.2", - "content-type": "^2.0.0", + "content-type": "^2.1.0", "debug": "^4.4.3", "http-errors": "^2.0.1", - "iconv-lite": "^0.7.2", + "iconv-lite": "^0.7.3", "on-finished": "^2.4.1", - "qs": "^6.15.2", + "qs": "^6.16.1", "raw-body": "^3.0.2", "type-is": "^2.1.0" }, @@ -3528,9 +3528,9 @@ "dev": true }, "node_modules/follow-redirects": { - "version": "1.16.1", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.16.1.tgz", - "integrity": "sha512-FNvFGzoMLWmE6Yj9spb/zjd7yiNCHiAW9/Tg9CXrQ8wuu32HtlJOwWO11OJafl5FfY3DxTdQ0vj42zU1kvv5jg==", + "version": "1.16.3", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.16.3.tgz", + "integrity": "sha512-toOSoqN6d51Wjf1aOFJYcoVv1aND9rj/CwjLU0Vz40oDuSpWDayCeKe4JpL5NL0WdFvoOOCI3BRo69HahjbR1A==", "funding": [ { "type": "individual", @@ -4004,9 +4004,9 @@ "license": "ISC" }, "node_modules/ip-address": { - "version": "10.7.3", - "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.7.3.tgz", - "integrity": "sha512-A1kdq/tSb5QjvKvAMgIoEvDBIgL7qaqVP/jkvSwYYRZ9iEzvPpopxp2wQfu3SuZRHtpHNxMn8Fs0bS+gf5Xmwg==", + "version": "10.7.6", + "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.7.6.tgz", + "integrity": "sha512-00LYkM6byILa9eQIx6qoaXCM40xTLd56AZ4vyaPW3YTyb49VZYPo5xsiAq4tuQ54GH4R7gVdYScJ1B7B77PuTg==", "license": "MIT", "engines": { "node": ">= 12" @@ -4408,9 +4408,9 @@ } }, "node_modules/jest-config/node_modules/glob": { - "version": "13.0.6", - "resolved": "https://registry.npmjs.org/glob/-/glob-13.0.6.tgz", - "integrity": "sha512-Wjlyrolmm8uDpm/ogGyXZXb1Z+Ca2B8NbJwqBVg0axK9GbBeoS7yGV6vjXnYdGm6X53iehEuxxbyiKp8QmN4Vw==", + "version": "13.0.7", + "resolved": "https://registry.npmjs.org/glob/-/glob-13.0.7.tgz", + "integrity": "sha512-wfsFgXQ8A3SEI9XGf7Nl3Y9l7ffSrGh7SUCT7vU/2CzYPep9kjxAn1S40F9OPKxAMGCVl7HtNlJhrCJUeUq83g==", "dev": true, "license": "BlueOak-1.0.0", "dependencies": { @@ -4734,9 +4734,9 @@ } }, "node_modules/jest-runtime/node_modules/glob": { - "version": "13.0.6", - "resolved": "https://registry.npmjs.org/glob/-/glob-13.0.6.tgz", - "integrity": "sha512-Wjlyrolmm8uDpm/ogGyXZXb1Z+Ca2B8NbJwqBVg0axK9GbBeoS7yGV6vjXnYdGm6X53iehEuxxbyiKp8QmN4Vw==", + "version": "13.0.7", + "resolved": "https://registry.npmjs.org/glob/-/glob-13.0.7.tgz", + "integrity": "sha512-wfsFgXQ8A3SEI9XGf7Nl3Y9l7ffSrGh7SUCT7vU/2CzYPep9kjxAn1S40F9OPKxAMGCVl7HtNlJhrCJUeUq83g==", "dev": true, "license": "BlueOak-1.0.0", "dependencies": { @@ -5687,9 +5687,9 @@ } }, "node_modules/proxy-addr": { - "version": "2.0.7", - "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", - "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "version": "2.0.8", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.8.tgz", + "integrity": "sha512-5nnx0yGyVUcY6t9RnWcARWtwT9F1D8O9rt08htPvnd49W1IgZtmLkhu9WfMzQj1cFxjHIO6connUNVW5k7AVyQ==", "license": "MIT", "dependencies": { "forwarded": "0.2.0", @@ -5697,6 +5697,10 @@ }, "engines": { "node": ">= 0.10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" } }, "node_modules/proxy-from-env": { @@ -5735,9 +5739,9 @@ "license": "MIT" }, "node_modules/qs": { - "version": "6.16.0", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.16.0.tgz", - "integrity": "sha512-h6fhOIaRrID2CbEY2fqs+7t+UXZo+MLAnU5gRIq85uFtdiUPCdsApMlHhXogKVM4HM2DVbIjGNTTYH2OcmP1vA==", + "version": "6.17.1", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.17.1.tgz", + "integrity": "sha512-jd3COkaKVgGUW+ZHyEHCG9bH7RoaaiWuMgzsIBjUMVjLAaWGWpoUAVwljVvBHxRu/2qEHnadLGZrkutYUBPQJA==", "license": "BSD-3-Clause", "dependencies": { "es-define-property": "^1.0.1",