ci(sync): update GitHub Actions#90
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the shared composite pre-commit GitHub Action to better align Node.js dependency caching with the package manager actually used by the repository (based on detected lockfiles).
Changes:
- Add lockfile-based detection to choose the appropriate
actions/setup-nodecache mode (npm/yarn/pnpm) and dependency path. - Add validation logic around Node hook detection vs. presence of supported lockfiles.
- Wire
setup-nodeto use the dynamically detected cache settings.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Detect Node package manager cache strategy from lockfile presence. | ||
| NODE_CACHE="" | ||
| NODE_CACHE_DEPENDENCY_PATH="" | ||
| if [[ -f "pnpm-lock.yaml" ]]; then | ||
| NODE_CACHE="pnpm" | ||
| NODE_CACHE_DEPENDENCY_PATH="pnpm-lock.yaml" | ||
| elif [[ -f "package-lock.json" ]]; then | ||
| NODE_CACHE="npm" | ||
| NODE_CACHE_DEPENDENCY_PATH="package-lock.json" | ||
| elif [[ -f "npm-shrinkwrap.json" ]]; then | ||
| NODE_CACHE="npm" | ||
| NODE_CACHE_DEPENDENCY_PATH="npm-shrinkwrap.json" | ||
| elif [[ -f "yarn.lock" ]]; then | ||
| NODE_CACHE="yarn" | ||
| NODE_CACHE_DEPENDENCY_PATH="yarn.lock" | ||
| fi |
| IS_NPM=$(grep -E "(npm|node)" "$_CONFIG" | grep -cv "language: node") | ||
| if [[ "$IS_NPM" -gt 0 && -z "$NODE_CACHE" ]]; then | ||
| echo "[ERROR] Node hooks detected in ${_CONFIG}, but no supported lockfile found." | ||
| echo "[ERROR] Expected one of: pnpm-lock.yaml, package-lock.json, npm-shrinkwrap.json, yarn.lock" | ||
| exit 1 | ||
| fi |
6152de4 to
e8ad8cd
Compare
| echo "IS_TERRAFORM=$(grep -c "terraform" "$_CONFIG")" | ||
| echo "IS_GOLANG=${IS_GOLANG:-$(grep -E "\<(go|golang)\>" "$_CONFIG" | grep -vEc "(language: go|gone|- repo)")}" |
e8ad8cd to
6dc1456
Compare
| case "${NPM_CACHE:-}" in | ||
| pnpm) | ||
| pnpm install --frozen-lockfile --ignore-scripts | ||
| ;; | ||
| npm) |
| uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 - https://github.com/actions/setup-node/releases | ||
| with: | ||
| node-version: latest | ||
| node-version-file: "package.json" | ||
| cache: "npm" | ||
| node-version-file: ${{ steps.action-prep.outputs.NODE_VERSION_FILE }} | ||
| cache: ${{ steps.action-prep.outputs.NODE_CACHE }} | ||
| cache-dependency-path: ${{ steps.action-prep.outputs.NODE_CACHE_DEPENDENCY_PATH }} |
| if [[ -f "package.json" ]]; then | ||
| NODE_VERSION_FILE="package.json" | ||
| PACKAGE_MANAGER=$(python3 -c 'import json,sys; print(json.load(open("package.json")).get("packageManager", ""))' 2>/dev/null || true) | ||
| if [[ "$PACKAGE_MANAGER" == pnpm@* ]]; then | ||
| PNPM_VERSION="${PACKAGE_MANAGER#pnpm@}" | ||
| fi | ||
| fi |
6dc1456 to
3e214b7
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
.github/actions/pre-commit/action.yaml:185
actions/setup-nodeis configured with onlynode-version-file, butNODE_VERSION_FILEcan be empty when a repo has Node hooks/lockfiles without a rootpackage.json(e.g., workspace setups). Passing an emptynode-version-filecan cause the setup step to fail; add a fallback that sets an explicit Node version whenNODE_VERSION_FILEis empty.
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 - https://github.com/actions/setup-node/releases
with:
node-version-file: ${{ steps.action-prep.outputs.NODE_VERSION_FILE }}
cache: ${{ steps.action-prep.outputs.NODE_PM }}
cache-dependency-path: ${{ steps.action-prep.outputs.NODE_PM_LOCKFILE }}
.github/actions/pre-commit/action.yaml:102
- The
grep -c/ grep pipeline results are used to populate outputs, butgrepreturns exit status 1 when there are no matches; with the default GitHub Actions bash options (-e/pipefail), that can terminate the step even though a 0 count is expected. Consider making these greps non-fatal and defaulting the count to 0.
echo "IS_TERRAFORM=$(grep -c "terraform" "$_CONFIG")"
echo "IS_GOLANG=${IS_GOLANG:-$(grep -E "\<(go|golang)\>" "$_CONFIG" | grep -vEc "(language: go|gone|- repo)")}"
3e214b7 to
30c0382
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
.github/actions/pre-commit/action.yaml:185
actions/setup-nodeno longer sets an explicit Node version. WhenNODE_VERSION_FILEis empty (e.g., nopackage.json), the job will fall back to the runner’s preinstalled Node version, which can drift over time and make pre-commit runs less reproducible. Consider adding an explicit fallback version (keeping the previouslatestbehavior) while still allowingnode-version-fileto override when present.
with:
node-version-file: ${{ steps.action-prep.outputs.NODE_VERSION_FILE }}
cache: ${{ steps.action-prep.outputs.NODE_PM }}
cache-dependency-path: ${{ steps.action-prep.outputs.NODE_PM_LOCKFILE }}
30c0382 to
e249de2
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
.github/actions/pre-commit/action.yaml:185
actions/setup-nodeis now configured with onlynode-version-file. WhenNODE_VERSION_FILEis empty (e.g., no rootpackage.json) or the file doesn’t contain an engines-based Node version,setup-nodecan fail because no Node version is specified. Consider keeping a safe fallback (e.g.,node-version: latest) so Node hooks still work when a version file is absent or non-informative.
- name: setup/node
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 - https://github.com/actions/setup-node/releases
with:
node-version-file: ${{ steps.action-prep.outputs.NODE_VERSION_FILE }}
cache: ${{ steps.action-prep.outputs.NODE_PM }}
cache-dependency-path: ${{ steps.action-prep.outputs.NODE_PM_LOCKFILE }}
| # Ensure pnpm can resolve private @fortawesome packages during setup/pre-commit. | ||
| # HACK: workaround for 'frontend-monorepo', TBD for generic cases | ||
| if [[ -n "${NODE_AUTH_TOKEN:-}" ]]; then | ||
| { | ||
| echo "@fortawesome:registry=https://npm.fontawesome.com/" | ||
| echo "//npm.fontawesome.com/:_authToken=${NODE_AUTH_TOKEN}" | ||
| } >>"${HOME}/.npmrc" | ||
| fi |
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
e249de2 to
0cdd121
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
.github/actions/pre-commit/action.yaml:102
- The bash snippet writing outputs to $GITHUB_OUTPUT has unescaped nested double-quotes in the command substitutions (e.g.,
grep -c "terraform"andgrep -E "\<(go|golang)\>"), which will cause a syntax error when this step runs.
echo "IS_TERRAFORM=$(grep -c "terraform" "$_CONFIG")"
echo "IS_GOLANG=${IS_GOLANG:-$(grep -E "\<(go|golang)\>" "$_CONFIG" | grep -vEc "(language: go|gone|- repo)")}"
.github/actions/pre-commit/action.yaml:189
actions/setup-nodeis always invoked withnode-version-filesourced fromNODE_VERSION_FILE, butNODE_VERSION_FILEis set only whenpackage.jsonexists. If a repo has Node hooks + a supported lockfile but nopackage.json(or uses a different version file like.nvmrc), this will pass an empty path and likely fail the action.
- name: setup/node
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 - https://github.com/actions/setup-node/releases
with:
node-version-file: ${{ steps.action-prep.outputs.NODE_VERSION_FILE }}
cache: ${{ steps.action-prep.outputs.NODE_PM }}
cache-dependency-path: ${{ steps.action-prep.outputs.NODE_PM_LOCKFILE }}
if: >-
steps.action-prep.outputs.PRE_COMMIT_RUN == '1'
&& steps.action-prep.outputs.IS_NPM > 0
&& ((github.event_name != 'pull_request' && !steps.cache.outputs.cache-hit) || github.event_name == 'pull_request')
Automatically generated PR to sync GitHub Actions and related configs.