110 lines
4.1 KiB
YAML
110 lines
4.1 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches: [ main, master ]
|
|
pull_request:
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: [macos, host]
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '20'
|
|
cache: 'npm'
|
|
|
|
- name: Install deps
|
|
run: npm ci
|
|
|
|
- name: Unit/Component tests (Vitest)
|
|
run: npm test
|
|
env:
|
|
CI: true
|
|
|
|
- name: Install Playwright browsers
|
|
run: npx playwright install --with-deps
|
|
|
|
- name: E2E tests (Playwright)
|
|
run: npm run test:e2e -- --reporter=line
|
|
env:
|
|
CI: true
|
|
|
|
- name: Upload Playwright report
|
|
if: always()
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: playwright-report
|
|
path: playwright-report
|
|
if-no-files-found: ignore
|
|
retention-days: 3
|
|
|
|
- name: Ensure artifacts export folder
|
|
run: |
|
|
set -euo pipefail
|
|
mkdir -p ./artifacts/export
|
|
|
|
- name: Verify bundle integrity (optional)
|
|
run: |
|
|
set -euo pipefail
|
|
if [ -f ./artifacts/export/assets.integrity.index.json ]; then
|
|
echo "Found integrity index; generating verify inputs"
|
|
npm run verify:make-json
|
|
echo "Running verify CLI"
|
|
npm run verify:run | tee /tmp/verify_output.json
|
|
echo "--- verify summary (for quick view) ---"
|
|
node -e '
|
|
const fs = require("fs");
|
|
try {
|
|
const txt = fs.readFileSync("/tmp/verify_output.json", "utf-8");
|
|
const obj = JSON.parse(txt);
|
|
const s = obj.summary || {};
|
|
console.log(`ok=${obj.ok} total=${s.total||0} missing=${s.missing||0} integMismatch=${s.integrityMismatches||0} sizeMismatch=${s.sizeMismatches||0} bundleHashMismatch=${s.bundleHashMismatch||false}`);
|
|
} catch (e) { console.log("(verify summary parse skipped)"); }
|
|
'
|
|
else
|
|
echo "No integrity index at ./artifacts/export/assets.integrity.index.json; skipping integrity verification"
|
|
fi
|
|
|
|
- name: Auto-merge PR on green
|
|
if: ${{ github.event_name == 'pull_request' }}
|
|
env:
|
|
CI_TOKEN: ${{ secrets.CI_TOKEN }}
|
|
GITEA_BASE_URL: https://gitea.jaybe.dev
|
|
PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
REPO: ${{ github.repository }}
|
|
run: |
|
|
set -euo pipefail
|
|
if [ -z "${CI_TOKEN:-}" ]; then
|
|
echo "CI_TOKEN not set; skipping auto-merge"; exit 0; fi
|
|
OWNER=$(echo "$REPO" | cut -d'/' -f1)
|
|
NAME=$(echo "$REPO" | cut -d'/' -f2)
|
|
echo "Checking labels for PR #$PR_NUMBER on $OWNER/$NAME"
|
|
LABELS_JSON=$(curl -sS -X GET \
|
|
-H "Authorization: token ${CI_TOKEN}" \
|
|
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/issues/${PR_NUMBER}")
|
|
echo "labels payload (first 200 chars):"; echo "$LABELS_JSON" | cut -c1-200 || true
|
|
if ! echo "$LABELS_JSON" | grep -qi '"name":"automerge"'; then
|
|
echo "Label 'automerge' not present; skipping merge"; exit 0; fi
|
|
echo "Label 'automerge' present; proceeding to merge"
|
|
# ensure PR is open
|
|
PR_JSON=$(curl -sS -X GET \
|
|
-H "Authorization: token ${CI_TOKEN}" \
|
|
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/pulls/${PR_NUMBER}")
|
|
STATE=$(echo "$PR_JSON" | sed -n 's/.*"state":"\([^"]*\)".*/\1/p')
|
|
echo "PR state: ${STATE:-unknown}"
|
|
if [ "${STATE:-}" != "open" ]; then
|
|
echo "PR state is not open; skipping merge"; exit 0; fi
|
|
echo "Merging PR #$PR_NUMBER for $OWNER/$NAME"
|
|
HTTP_CODE=$(curl -sS -o /tmp/merge_resp.json -w "%{http_code}" -X POST \
|
|
-H "Content-Type: application/json" \
|
|
-H "Authorization: token ${CI_TOKEN}" \
|
|
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/pulls/${PR_NUMBER}/merge" \
|
|
-d '{"Do":"merge","MergeMessage":"auto-merge: CI green"}' || true)
|
|
echo "merge http: $HTTP_CODE"
|
|
echo "merge resp:"; cat /tmp/merge_resp.json || true
|