11on :
22 workflow_call :
33 inputs :
4- version :
5- description : ' Version number to release e.g., v1.2.3 or v1.2.3-rc.1 '
6- required : true
4+ expected_pkg_name :
5+ description : >
6+ Expected package.json name. If provided, must match.
77 type : string
8+ required : false
9+
10+ expected_pkg_version :
11+ description : >
12+ Expected package.json version. If provided, must match.
13+ May include optional leading 'v' (e.g. v1.2.3).
14+ type : string
15+ required : false
816
917 dist_tag :
1018 description : ' Dist tag to release e.g., latest, alpha, beta, rc, etc.'
11- required : true
1219 type : string
20+ required : false
21+
22+ node_auth_token :
23+ description : >
24+ Token used to authenticate to GitHub Packages (usually GITHUB_TOKEN).
25+ type : string
26+ required : false
27+ default : ${{ secrets.GITHUB_TOKEN }}
1328
1429 dry_run :
1530 description : ' Run all checks but do not actually publish packages.'
31+ type : boolean
32+ required : false
1633 default : false
34+
35+ cwd :
36+ description : >
37+ Working directory containing package.json (relative to repo root).
38+ type : string
1739 required : false
18- type : boolean
40+ default : " . "
1941
2042 runner_label :
2143 description : ' Label for the runner to be used for the jobs.'
2244 default : ' ubuntu-latest'
2345 required : false
2446 type : string
2547
26-
2748jobs :
2849 publish-javascript-github :
2950 runs-on : ${{ inputs.runner_label }}
@@ -39,48 +60,21 @@ jobs:
3960 uses : actions/setup-node@v6
4061 with :
4162 node-version : ' lts/*'
42- registry-url : ' https://registry.npmjs.org'
43-
44- - name : Get package name
45- shell : bash
46- run : |
47- set -euo pipefail
48- PACKAGE_NAME="$(npm pkg get name | tr -d '"')"
49- echo "PACKAGE_NAME=${PACKAGE_NAME}" >> "$GITHUB_ENV"
50-
51- - name : Validate package.json version
52- shell : bash
53- run : |
54- EXPECTED_VERSION="${{ inputs.version }}"
55- PKG_VERSION="$(npm pkg get version | tr -d '"')"
56-
57- if [[ "$PKG_VERSION" != "$EXPECTED_VERSION" ]]; then
58- echo "::error::package.json version ($PKG_VERSION) does not match release version ($EXPECTED_VERSION)"
59- exit 1
60- fi
6163
6264 - name : Install npm dependencies
6365 shell : bash
6466 run : npm ci
6567
6668 - name : Publish to GitHub Packages
6769 id : publish_github
68- env :
69- NODE_AUTH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
70- continue-on-error : true
71- run : |
72- set -euo pipefail
73-
74- npm config set "@fastly:registry" "https://npm.pkg.github.com/"
75- npm config set "//npm.pkg.github.com/:_authToken" "$NODE_AUTH_TOKEN"
76-
77- DIST_TAG="${{ inputs.dist_tag }}"
78- echo "Publishing ${PACKAGE_NAME} to pkg.github.com using dist-tag: ${DIST_TAG}"
79- if [[ '${{ inputs.dry_run }}' == 'true' ]]; then
80- npm publish --dry-run --tag "$DIST_TAG"
81- else
82- npm publish --tag "$DIST_TAG"
83- fi
70+ uses : fastly/devex-reusable-workflows/actions/publish-javascript-github-v1@kats/publish-javascript-packages
71+ with :
72+ expected_pkg_name : ${{ inputs.expected_pkg_name }}
73+ expected_pkg_version : ${{ inputs.expected_pkg_version }}
74+ dist_tag : ${{ inputs.dist_tag }}
75+ node_auth_token : ${{ secrets.GITHUB_TOKEN }}
76+ dry_run : ${{ inputs.dry_run }}
77+ cwd : ${{ inputs.cwd }}
8478
8579 - name : Publish status
8680 if : always()
9690 echo "github outcome : ${{ steps.publish_github.outcome || 'skipped' }}"
9791 if [[ "${{ steps.publish_github.outcome }}" == 'failure' ]]; then
9892 echo "::error::Publish to GitHub Packages failed."
99- echo "::notice::Hint : Ensure the caller workflow grants 'permissions: packages: write' ."
93+ echo "::notice::Hint : Ensure the caller repo/ workflow is able to write this package ."
10094 exit 1
10195 fi
0 commit comments