name: Test App on: merge_group: workflow_dispatch: push: branches: - develop pull_request: types: - opened - synchronize concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true permissions: {} jobs: Test: timeout-minutes: 20 runs-on: ubuntu-24.04 permissions: contents: read pull-requests: write packages: read steps: - name: Harden Runner uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0 with: egress-policy: audit - name: Checkout branch uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Setup Node uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 with: node-version-file: .nvmrc cache: npm cache-dependency-path: package-lock.json registry-url: 'https://npm.pkg.github.com' scope: '@kong' - name: Install packages run: npm ci env: NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' - name: Lint run: npm run lint - name: Type checks run: npm run type-check - name: Unit Tests run: npm test - name: Check autocomplete snippets are up to date run: | npm run generate:autocomplete -w insomnia-scripting-environment if ! git diff --exit-code packages/insomnia-scripting-environment/src/autocomplete-snippets.json; then echo "::error::autocomplete-snippets.json is out of date. Run 'npm run generate:autocomplete -w insomnia-scripting-environment' and commit the result." exit 1 fi - name: Check Insomnia JSON schema is up to date run: | npm run generate:schema -w insomnia # `git add -N` marks any newly-generated versioned file (e.g. after a # schema version bump) as intent-to-add so `git diff` flags it too. git add -N schemas/ if ! git diff --exit-code schemas/; then echo "::error::schemas/ is out of date. Run 'npm run generate:schema -w insomnia' and commit the result." exit 1 fi - name: Install sandbox-vendored packages and check pins never exceed app versions run: npm run sandbox:vendored:ci -w insomnia - name: Check sandbox-vendored bundles are up to date run: | npm run sandbox:vendored:generate -w insomnia if ! git diff --exit-code packages/insomnia/src/templating/sandbox/vendored/*.generated.ts; then echo "::error::Sandbox-vendored bundles are out of date or hand-edited. Run 'npm run sandbox:vendored:ci -w insomnia && npm run sandbox:vendored:generate -w insomnia' and commit the result." exit 1 fi - name: Check for sandbox-vendored changes id: vendor-changed if: github.event_name == 'pull_request' env: BASE_SHA: ${{ github.event.pull_request.base.sha }} run: | git fetch origin "$BASE_SHA" --depth=1 if git diff --name-only "$BASE_SHA"...HEAD | grep -qE '^packages/insomnia/src/templating/sandbox/(vendored/(pkg/|.*\.generated\.ts$)|module-registry\.ts$)'; then echo "changed=true" >> "$GITHUB_OUTPUT" fi - name: Sandbox-vendored regression suite if: github.event_name != 'pull_request' || steps.vendor-changed.outputs.changed == 'true' run: npm run sandbox:vendored:test-regression -w insomnia - name: Check circular references id: check-cycles continue-on-error: true shell: bash # Exit code 1 (a new cycle) and 2 (a stale baseline) are reported differently below, so # capture it rather than letting `-e` collapse both into a generic step failure. run: | set +e npm run check-cycle-references | tee cycle-report.txt status=${PIPESTATUS[0]} set -e echo "status=$status" >> "$GITHUB_OUTPUT" exit "$status" - name: Post circular references PR comment if: github.event_name == 'pull_request' && always() && steps.check-cycles.outcome != 'skipped' uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const fs = require('fs'); // 0 = matches baseline, 1 = a new cycle appeared, 2 = baseline is stale. Anything // else means the check itself blew up, which is not a claim about cycles either way. const status = '${{ steps.check-cycles.outputs.status }}'; const passed = status === '0'; const summaryByStatus = { '0': { icon: '✅', text: 'No new circular references' }, '1': { icon: '⚠️', text: 'New circular references detected' }, '2': { icon: '♻️', text: 'No new circular references, but the baseline is stale — regenerate and commit it' }, }; const { icon, text } = summaryByStatus[status] ?? { icon: '💥', text: 'The circular reference check failed to run' }; const report = fs.readFileSync('cycle-report.txt', 'utf8').trim(); const markdownContent = `
${icon} Circular References Report **Status:** ${text} \`\`\` ${report} \`\`\`
`; const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, }); const botComment = comments.find(comment => comment.user?.type === 'Bot' && comment.body?.includes('Circular References Report') ); if (passed) { if (botComment) { await github.rest.issues.deleteComment({ owner: context.repo.owner, repo: context.repo.repo, comment_id: botComment.id, }); console.log('Deleted stale PR comment (no new circular references)'); } else { console.log('No new circular references, skipping PR comment'); } } else if (botComment) { await github.rest.issues.updateComment({ owner: context.repo.owner, repo: context.repo.repo, comment_id: botComment.id, body: markdownContent }); console.log('Updated existing PR comment'); } else { await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, body: markdownContent }); console.log('Created new PR comment'); } # Fails on a stale baseline too, not just on new cycles: the baseline is a ratchet, so a # cycle left in it after being fixed would silently keep permitting its reintroduction. - name: Fail if the circular reference check did not pass if: steps.check-cycles.outcome == 'failure' run: exit 1