Skip to content

ci(workflows): add reusable pr-checks workflow - #29

Merged
NiccoloOlivieriAchille merged 1 commit into
mainfrom
ci/pr-checks-reusable
Nov 22, 2026
Merged

NiccoloOlivieriAchille merged 1 commit into
mainfrom
ci/pr-checks-reusable

Conversation

@NiccoloOlivieriAchille

Copy link
Copy Markdown
Contributor

Cosa

Workflow riutilizzabile .github/workflows/pr-checks.yml (workflow_call), da spec 49 di BePower/argus. Funziona senza input con questo caller:

name: PR checks
on: pull_request
permissions:
  contents: read
  packages: read
jobs:
  checks:
    uses: BePower/.github/.github/workflows/pr-checks.yml@main

Passi: checkout, scelta Node, setup-node, npm ci, poi lint, build, test con --if-present, poi extra-run.

Input opzionali (non sono segreti, scritto nelle descrizioni): node-version, working-directory (default .), extra-run.

Scelte

  • Node: input, altrimenti volta.node / devEngines.runtime / engines.node di package.json, altrimenti lts/*. setup-node non ha fallback da solo, quindi lo decide uno step in bash (solo node, già sul runner).
  • GITHUB_TOKEN e NODE_AUTH_TOKEN passati a npm ci. In un workflow riutilizzabile secrets.GITHUB_TOKEN è disponibile senza secrets: inherit (docs: "The called workflow is automatically granted access to github.token and secrets.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-run passa da variabile d'ambiente, mai ${{ }} dentro run:. Niente pull_request_target, niente secrets.
  • concurrency per PR con cancel-in-progress, timeout-minutes: 30.
  • ci.yml, release.yml, sync-biome-schema.yml non toccati. README: nuova sezione.

Verifica

  • actionlint 1.7.7: nessun errore.
  • Logica di scelta Node provata su package.json vuoto (lts), engines, volta, devEngines (file).
  • Non provato in Actions: serve un PR di prova dopo il merge.

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 @bepower devono dare accesso al repo ("Manage Actions access"), altrimenti npm ci fallisce con 403.

Rischio: i caller usano @main, quindi ogni modifica qui arriva a tutti i repo. Servono review e ruleset su main.

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.
@amazon-q-developer

Copy link
Copy Markdown

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.

@amazon-q-developer amazon-q-developer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Non-existent action versions (actions/checkout@v7, actions/setup-node@v7): Both tags do not exist — the latest major version for both is v4. Every caller repo will fail immediately when the workflow tries to resolve these steps. A one-click fix is provided.

  2. working-directory ignored in Node version detection: The Pick Node version step uses a hardcoded require("./package.json") path, which always resolves to the checkout root regardless of inputs.working-directory. Monorepo callers that set working-directory will read the wrong package.json and may get the wrong Node version or fall back to lts/* unintentionally. A one-click fix that passes WORKING_DIR as 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.

Comment on lines +59 to +82
- 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛑 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.

Suggested change
- 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

Comment on lines +65 to +80
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛑 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.

Suggested change
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

@NiccoloOlivieriAchille
NiccoloOlivieriAchille merged commit d4b7046 into main Nov 22, 2026
2 checks passed
@NiccoloOlivieriAchille
NiccoloOlivieriAchille deleted the ci/pr-checks-reusable branch November 22, 2026 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant