Repository navigation
ci(workflows): add reusable pr-checks workflow - #29
Conversation
Add .github/workflows/pr-checks.yml (workflow_call) that runs npm ci, lint, build and test on pull requests. Optional inputs: node-version, working-directory, extra-run. Node version: input, else package.json, else lts/*. GITHUB_TOKEN reads @BePower packages. No secrets, no pull_request_target. extra-run goes through an env var. Document the caller and inputs in the README. Design: BePower/argus spec 49.
|
Warning Amazon Q Developer for GitHub: end of support On January 30, 2027, AWS will discontinue support for the Amazon Q Developer for GitHub App. New app installations will no longer be available starting November 18, 2026. For capabilities similar to the Amazon Q Developer for GitHub App, explore Kiro and the Kiro GitHub App. For more information about the end of support, see Amazon Q Developer end-of-support announcement on the AWS DevOps Blog. |
There was a problem hiding this comment.
Review Summary
This PR introduces a reusable pr-checks.yml workflow that covers checkout, Node version selection, npm ci, lint, build, test, and an optional extra-run step. The overall design is sound — env-var gating of extra-run correctly prevents expression injection, the concurrency / cancel-in-progress configuration is correct, and the permissions block is appropriately minimal.
Two blocking issues were found:
-
Non-existent action versions (
actions/checkout@v7,actions/setup-node@v7): Both tags do not exist — the latest major version for both isv4. Every caller repo will fail immediately when the workflow tries to resolve these steps. A one-click fix is provided. -
working-directoryignored in Node version detection: ThePick Node versionstep uses a hardcodedrequire("./package.json")path, which always resolves to the checkout root regardless ofinputs.working-directory. Monorepo callers that setworking-directorywill read the wrongpackage.jsonand may get the wrong Node version or fall back tolts/*unintentionally. A one-click fix that passesWORKING_DIRas an env var and resolves the path dynamically is provided.
You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.
| - uses: actions/checkout@v7 | ||
|
|
||
| # setup-node does not fall back by itself when package.json has no Node | ||
| # version, so decide here: input, else package.json, else lts/*. | ||
| - name: Pick Node version | ||
| id: node | ||
| env: | ||
| INPUT_NODE_VERSION: ${{ inputs.node-version }} | ||
| run: | | ||
| if [ -n "$INPUT_NODE_VERSION" ]; then | ||
| echo "mode=input" >> "$GITHUB_OUTPUT" | ||
| elif node -e ' | ||
| const p = require("./package.json"); | ||
| const rt = p.devEngines && p.devEngines.runtime; | ||
| const has = (rt && (Array.isArray(rt) ? rt.length : rt.version)) | ||
| || (p.volta && p.volta.node) || (p.engines && p.engines.node); | ||
| process.exit(has ? 0 : 1); | ||
| ' 2>/dev/null; then | ||
| echo "mode=file" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "mode=lts" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| - uses: actions/setup-node@v7 |
There was a problem hiding this comment.
🛑 Crash Risk: actions/checkout@v7 and actions/setup-node@v7 do not exist — the latest major versions for both are v4. Referencing non-existent tags will cause the workflow to fail immediately with a step resolution error on every caller repo.
| - uses: actions/checkout@v7 | |
| # setup-node does not fall back by itself when package.json has no Node | |
| # version, so decide here: input, else package.json, else lts/*. | |
| - name: Pick Node version | |
| id: node | |
| env: | |
| INPUT_NODE_VERSION: ${{ inputs.node-version }} | |
| run: | | |
| if [ -n "$INPUT_NODE_VERSION" ]; then | |
| echo "mode=input" >> "$GITHUB_OUTPUT" | |
| elif node -e ' | |
| const p = require("./package.json"); | |
| const rt = p.devEngines && p.devEngines.runtime; | |
| const has = (rt && (Array.isArray(rt) ? rt.length : rt.version)) | |
| || (p.volta && p.volta.node) || (p.engines && p.engines.node); | |
| process.exit(has ? 0 : 1); | |
| ' 2>/dev/null; then | |
| echo "mode=file" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "mode=lts" >> "$GITHUB_OUTPUT" | |
| fi | |
| - uses: actions/setup-node@v7 | |
| - uses: actions/checkout@v4 | |
| # setup-node does not fall back by itself when package.json has no Node | |
| # version, so decide here: input, else package.json, else lts/*. | |
| - name: Pick Node version | |
| id: node | |
| env: | |
| INPUT_NODE_VERSION: ${{ inputs.node-version }} | |
| run: | | |
| if [ -n "$INPUT_NODE_VERSION" ]; then | |
| echo "mode=input" >> "$GITHUB_OUTPUT" | |
| elif node -e ' | |
| const p = require("./package.json"); | |
| const rt = p.devEngines && p.devEngines.runtime; | |
| const has = (rt && (Array.isArray(rt) ? rt.length : rt.version)) | |
| || (p.volta && p.volta.node) || (p.engines && p.engines.node); | |
| process.exit(has ? 0 : 1); | |
| ' 2>/dev/null; then | |
| echo "mode=file" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "mode=lts" >> "$GITHUB_OUTPUT" | |
| fi | |
| - uses: actions/setup-node@v4 |
| env: | ||
| INPUT_NODE_VERSION: ${{ inputs.node-version }} | ||
| run: | | ||
| if [ -n "$INPUT_NODE_VERSION" ]; then | ||
| echo "mode=input" >> "$GITHUB_OUTPUT" | ||
| elif node -e ' | ||
| const p = require("./package.json"); | ||
| const rt = p.devEngines && p.devEngines.runtime; | ||
| const has = (rt && (Array.isArray(rt) ? rt.length : rt.version)) | ||
| || (p.volta && p.volta.node) || (p.engines && p.engines.node); | ||
| process.exit(has ? 0 : 1); | ||
| ' 2>/dev/null; then | ||
| echo "mode=file" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "mode=lts" >> "$GITHUB_OUTPUT" | ||
| fi |
There was a problem hiding this comment.
🛑 Logic Error: The node -e script hardcodes require("./package.json"), which always resolves relative to the runner's current working directory (the checkout root), not inputs.working-directory. When a caller sets working-directory to a monorepo subdirectory (e.g., packages/my-app), this step reads the wrong package.json (the root one) and may set the wrong Node version — or fall back to lts/* even though the subdirectory's package.json specifies a version. The working-directory default for run: steps is set at the job level, but this step runs before that context is applied to the inline node -e path resolution.
| env: | |
| INPUT_NODE_VERSION: ${{ inputs.node-version }} | |
| run: | | |
| if [ -n "$INPUT_NODE_VERSION" ]; then | |
| echo "mode=input" >> "$GITHUB_OUTPUT" | |
| elif node -e ' | |
| const p = require("./package.json"); | |
| const rt = p.devEngines && p.devEngines.runtime; | |
| const has = (rt && (Array.isArray(rt) ? rt.length : rt.version)) | |
| || (p.volta && p.volta.node) || (p.engines && p.engines.node); | |
| process.exit(has ? 0 : 1); | |
| ' 2>/dev/null; then | |
| echo "mode=file" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "mode=lts" >> "$GITHUB_OUTPUT" | |
| fi | |
| env: | |
| INPUT_NODE_VERSION: ${{ inputs.node-version }} | |
| WORKING_DIR: ${{ inputs.working-directory }} | |
| run: | | |
| if [ -n "$INPUT_NODE_VERSION" ]; then | |
| echo "mode=input" >> "$GITHUB_OUTPUT" | |
| elif node -e ' | |
| const path = require("path"); | |
| const dir = process.env.WORKING_DIR || "."; | |
| const p = require(path.resolve(dir, "package.json")); | |
| const rt = p.devEngines && p.devEngines.runtime; | |
| const has = (rt && (Array.isArray(rt) ? rt.length : rt.version)) | |
| || (p.volta && p.volta.node) || (p.engines && p.engines.node); | |
| process.exit(has ? 0 : 1); | |
| ' 2>/dev/null; then | |
| echo "mode=file" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "mode=lts" >> "$GITHUB_OUTPUT" | |
| fi |
Cosa
Workflow riutilizzabile
.github/workflows/pr-checks.yml(workflow_call), da spec 49 di BePower/argus. Funziona senza input con questo caller:Passi: checkout, scelta Node, setup-node,
npm ci, poilint,build,testcon--if-present, poiextra-run.Input opzionali (non sono segreti, scritto nelle descrizioni):
node-version,working-directory(default.),extra-run.Scelte
volta.node/devEngines.runtime/engines.nodedi package.json, altrimentilts/*. setup-node non ha fallback da solo, quindi lo decide uno step in bash (solonode, già sul runner).GITHUB_TOKENeNODE_AUTH_TOKENpassati anpm ci. In un workflow riutilizzabilesecrets.GITHUB_TOKENè disponibile senzasecrets: inherit(docs: "The called workflow is automatically granted access togithub.tokenandsecrets.GITHUB_TOKEN").package-manager-cache: false, come da design: nessuna cache condivisa tra PR (cache poisoning).npm ciè più lento. Se si vuole la cache, si cambia qui.extra-runpassa da variabile d'ambiente, mai${{ }}dentrorun:. Nientepull_request_target, niente secrets.concurrencyper PR con cancel-in-progress,timeout-minutes: 30.ci.yml,release.yml,sync-biome-schema.ymlnon toccati. README: nuova sezione.Verifica
engines,volta,devEngines(file).Come provarlo dopo il merge
Ordine: 1) questa PR; 2) PR argus #45.
Apri una PR di prova in argus con il caller sopra e guarda il job
checks / checks. Prerequisito: i pacchetti@bepowerdevono dare accesso al repo ("Manage Actions access"), altrimentinpm cifallisce con 403.Rischio: i caller usano
@main, quindi ogni modifica qui arriva a tutti i repo. Servono review e ruleset sumain.