BUILD-10827: make config-npm skip path safe from template parsing error#246
Conversation
|
It is possible to add a call to config-npm here for validation: https://github.com/SonarSource/sonar-dummy-js/blob/master/.github/workflows/build.yml#L59 |
SummaryFixes noisy template parsing errors when The fix makes the expression null-safe by short-circuiting to an empty string if the vault output is missing—a one-line change using the exact pattern already proven stable in What reviewers should knowWhat to focus on:
Non-obvious points:
Test coverage note: The PR relies on workflow-level observation to verify the fix (author's test plan), not automated tests. Check that the merge-queue CI still passes to confirm the first-invocation path is unchanged.
|
There was a problem hiding this comment.
Pull request overview
This PR updates the config-npm composite GitHub Action to avoid GitHub Actions template parsing errors when the action is invoked more than once in the same job and takes the “skip” path (where the Vault step doesn’t run and produces no outputs).
Changes:
- Make
ARTIFACTORY_ACCESS_TOKENevaluation null-safe by short-circuiting whensteps.secrets.outputs.vaultis empty, matching the established pattern used in other actions in this repo.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.



Summary
Fix noisy
##[error]annotations whenconfig-npmis invoked a second time in the same job (e.g. viaSonarSource/sonarqube-cloud-github-actions/parse-cdk-nag-output@master, which nests a call toconfig-npm).Root cause. In
config-npm/action.yml, theConfigure NPM authenticationstep declares:On the skip path (when
CONFIG_NPM_COMPLETEDis already set), thesecretsstep is gated out byif: steps.config-npm-completed.outputs.skip != 'true'and therefore does not produce any output. GitHub Actions still evaluates the step-levelenvexpression, sofromJSON('')raises a template parsing error (Error reading JToken from JsonReader). The job may still pass, but the##[error]annotation is reported and can hide real failures.Fix. Make the expression null-safe using the exact same pattern already used in
config-maven/action.yml,config-gradle/action.ymlandget-build-number/action.yml:When
steps.secrets.outputs.vaultis empty (skip path), the expression short-circuits to''andfromJSONis never called. First-invocation behaviour is unchanged becausesteps.secrets.outputs.vaultis always a non-empty JSON string when the secrets step runs.JIRA: https://sonarsource.atlassian.net/browse/BUILD-10827
Notes on test coverage
spec/config-npm_spec.shShellSpec suite covers the shell scripts (npm_config.sh,npm_set_project_version.sh), not the composite action's YAML. There is no existing harness for double-invocation of the composite action itself, so this fix is verified by workflow-level observation rather than unit tests.config-maven/config-gradlewas introduced for the same reason and has been stable since; this change bringsconfig-npmin line with them.Test plan
test-shell-scripts.ymlstill passes (first-invocation path unchanged).config-npmtwice in the same job (e.g. viaSonarSource/sonarqube-cloud-github-actions/parse-cdk-nag-output) and confirm:##[error]Error reading JToken from JsonReaderannotation on the second call.Action already called by ..., execution skipped.and exits cleanly.~/.npmrcandjfcorrectly with the Artifactory token.