diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..301aadc --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,2 @@ +# Every pull request requests a review from the owners below. +* @codewithmmak diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..5bf161e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,24 @@ +--- +name: Bug report +about: Report a failing test, a broken script, or wrong behavior +labels: bug +--- + +## What happened + +## What you expected + +## Steps to reproduce + +1. +2. + +## Environment + +- Environment (`TEST_ENV`): +- Command run: +- Bun and Node versions (`bun --version`, `node --version`): + +## Logs or report + + diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..c1268fe --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,11 @@ +--- +name: Feature request +about: Suggest a new test, tag, environment, or framework capability +labels: enhancement +--- + +## Problem + +## Proposed change + +## Alternatives considered diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..3a3d527 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,20 @@ +## Summary + + + +## Checks + +- [ ] `bun run format:check` passes +- [ ] `bun run lint` passes +- [ ] The CI check passes (Format check, Lint, Smoke tests, CI) +- [ ] New or changed tests are tagged (`@smoke`, `@integration`, or `@prod`) +- [ ] Any `@prod` test is read-only and cannot lock an account + +## Docs + +- [ ] README and the relevant file in `docs/` are updated, if scripts, environments, tags, or quality gates changed + +## Security + +- [ ] No credentials, `.env` files, session files, or reports are committed +- [ ] Changes to `.github/workflows` keep permissions minimal and actions pinned to commit SHAs diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml new file mode 100644 index 0000000..a625aa4 --- /dev/null +++ b/.github/workflows/audit.yml @@ -0,0 +1,26 @@ +name: Dependency audit + +# Checks installed packages against the npm advisory database every week, or on demand. +on: + schedule: + - cron: "0 5 * * 1" + workflow_dispatch: + +permissions: + contents: read + +jobs: + audit: + name: Dependency audit + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - name: Checkout + uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + + - name: Setup Bun + uses: ./.github/actions/setup-bun + + - name: Audit dependencies + run: bun audit diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 917ed34..8a7d8fc 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -55,3 +55,23 @@ jobs: path: reports/ if-no-files-found: ignore retention-days: 30 + + report-failure: + name: Report scheduled failure + needs: [nightly] + if: failure() && github.event_name == 'schedule' + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + contents: read + issues: write + + steps: + - name: Checkout + uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + + - name: Open or update the failure issue + run: node scripts/report-scheduled-failure.js "Nightly" "$RUN_URL" + env: + GH_TOKEN: ${{ github.token }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} diff --git a/.github/workflows/prod-smoke.yml b/.github/workflows/prod-smoke.yml index 650c96e..6756156 100644 --- a/.github/workflows/prod-smoke.yml +++ b/.github/workflows/prod-smoke.yml @@ -56,3 +56,23 @@ jobs: path: reports/ if-no-files-found: ignore retention-days: 30 + + report-failure: + name: Report scheduled failure + needs: [prod-smoke] + if: failure() && github.event_name == 'schedule' + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + contents: read + issues: write + + steps: + - name: Checkout + uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + + - name: Open or update the failure issue + run: node scripts/report-scheduled-failure.js "Production smoke" "$RUN_URL" + env: + GH_TOKEN: ${{ github.token }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..0212173 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,20 @@ +# Security policy + +## Supported versions + +Only the latest version on `main` receives fixes. + +## Reporting a vulnerability + +Do not open a public issue for a security problem. + +Report it privately through GitHub: open the repository's **Security** tab and choose **Report a vulnerability**. +Include the affected file or workflow, the steps to reproduce, and the impact you expect. + +If private reporting is not available, contact the repository owner through their GitHub profile and ask for a private +channel. Do not send credentials, tokens, or personal data in any report. + +## Scope + +In scope: the framework code, configuration, and GitHub Actions workflows in this repository. +Out of scope: the OrangeHRM demo application and third-party services the tests call. diff --git a/docs/ci-cd.md b/docs/ci-cd.md index 56ef869..537bd16 100644 --- a/docs/ci-cd.md +++ b/docs/ci-cd.md @@ -11,6 +11,16 @@ checks. Each job uses a GitHub Environment, which scopes the credentials to that | Nightly | `.github/workflows/nightly.yml` | 02:00 UTC daily, or manual | `qa` and `staging` (matrix) | Smoke and integration | | Production smoke | `.github/workflows/prod-smoke.yml` | 06:00 UTC on weekdays, or manual | `production` | Production smoke (`@prod`) | | Sauce Labs | `.github/workflows/sauce.yml` | manual only | `dev` | Validate and run on Sauce Labs (see [sauce-labs.md](sauce-labs.md)) | +| Dependency audit | `.github/workflows/audit.yml` | 05:00 UTC on Mondays, or manual | none | `bun audit` against the npm advisory database | + +## Failed scheduled runs + +When a scheduled nightly or production smoke run fails, a `report-failure` job opens one issue titled +`Scheduled run failed: `, labelled `scheduled-failure`, and links the run. Later failures add a comment to +that open issue rather than opening another. Close the issue once the failure is fixed. Manual runs do not open issues. + +The job requests only `issues: write`, and it runs only for scheduled events. Failure issues are created only after the +scheduled-runs switch is set (see Turning on scheduled runs). ## CI stages diff --git a/renovate.json b/renovate.json index 7646b2a..1b7c1cc 100644 --- a/renovate.json +++ b/renovate.json @@ -1,6 +1,8 @@ { "$schema": "https://docs.renovatebot.com/renovate-schema.json", "extends": ["config:recommended"], + "labels": ["dependencies"], + "schedule": ["before 6am on monday"], "lockFileMaintenance": { "enabled": true, "schedule": ["before 6am on monday"] diff --git a/scripts/report-scheduled-failure.js b/scripts/report-scheduled-failure.js new file mode 100644 index 0000000..c90de1d --- /dev/null +++ b/scripts/report-scheduled-failure.js @@ -0,0 +1,71 @@ +// Opens one GitHub issue per failing scheduled workflow, or adds a comment to the open one. +// Usage: node scripts/report-scheduled-failure.js +// Needs GH_TOKEN with issues: write. Uses the gh CLI that GitHub-hosted runners provide. +const { execFileSync } = require("child_process"); + +const LABEL = "scheduled-failure"; + +/** + * @param {string[]} args + * @returns {string} + */ +function gh(args) { + return execFileSync("gh", args, { encoding: "utf8", env: process.env }).trim(); +} + +function main() { + const [workflow, runUrl] = process.argv.slice(2); + if (!workflow || !runUrl) { + throw new Error("Usage: node scripts/report-scheduled-failure.js "); + } + + const title = `Scheduled run failed: ${workflow}`; + const open = JSON.parse( + gh([ + "issue", + "list", + "--state", + "open", + "--label", + LABEL, + "--limit", + "100", + "--json", + "number,title", + ]) + ); + const existing = open.find((issue) => issue.title === title); + + if (existing) { + gh(["issue", "comment", String(existing.number), "--body", `Failed again: ${runUrl}`]); + console.log(`Commented on issue #${existing.number}.`); + return; + } + + gh([ + "label", + "create", + LABEL, + "--color", + "B60205", + "--description", + "Automatic report from a scheduled run", + "--force", + ]); + const body = [ + `A scheduled run failed: ${runUrl}`, + "", + "Open the run, read the Summary table, and download the reports artifact.", + "Close this issue once the failure is fixed. Later failures add comments to this issue.", + ].join("\n"); + const url = gh(["issue", "create", "--title", title, "--body", body, "--label", LABEL]); + console.log(`Opened ${url}`); +} + +try { + main(); +} catch (error) { + // Reporting must not hide the original failure, so report the problem and exit with an error code. + console.error(`report-scheduled-failure: ${error.message}`); + process.exitCode = 1; +}