@l1pz/publish-test
v1.0.6
Published
Depending on the repository, the process of setting up publishing to npm when creating a release on GitHub may differ. However, there is a common pattern you can rely on.
Readme
Introduction
Depending on the repository, the process of setting up publishing to npm when creating a release on GitHub may differ. However, there is a common pattern you can rely on.
This guide is updated for the shared publish action hosted in the build-system repository:
https://github.com/DevExpress/testcafe-build-system/blob/main/actions/publish/action.yml
Preparing the Repository Codebase
Add a release workflow in
.github/workflows/(for example,on-release.yml) that runs when a release is published.Configure a release workflow (
on-release.yml) to call the shared action directly:
name: On-release
on:
release:
types: [published]
permissions:
id-token: write
contents: read
jobs:
publish:
if: ${{ !github.event.release.draft }}
runs-on: ubuntu-latest
environment: npmjs
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.release.target_commitish }}
- uses: DevExpress/testcafe-build-system/actions/publish@main
with:
token: ${{ secrets.NPM_TOKEN }}
version: ${{ github.event.release.tag_name }}
branch: ${{ github.event.release.target_commitish }}
pre-publish-script: npm testImportant: you do not need to copy a local publish.yml into each repository. The publish logic is centralized in the shared action and is referenced from on-release.yml.
The shared publish action is documented here:
https://github.com/DevExpress/testcafe-build-system/blob/main/actions/publish/action.yml
Use release tags in the format
v<release_version>and keeppackage.jsonversion as<release_version>.Example:
- If
package.jsonversion is1.2.3, release tag should bev1.2.3. - The shared publish action strips the leading
vfrom theversioninput before checkingpackage.json. - A plain value like
1.2.3inversioninput is invalid and will fail.
- If
Ensure your package can be published from CI (
npm publishworks with your package configuration and access level).(Optional) Add additional inputs in the release workflow if needed:
with:
pre-publish-script: npm test
post-publish-script: npm run smoke
publish-command: npm publish
publish-tag: latest
audit-level: critical
branch: ${{ github.event.release.target_commitish }}
version: ${{ github.event.release.tag_name }}Publish Workflow Inputs
The shared publish action (DevExpress/testcafe-build-system/actions/publish) supports these inputs.
Reference:
https://github.com/DevExpress/testcafe-build-system/blob/main/actions/publish/action.yml
version(required)- Version passed from release tag in
v<release_version>format (for examplev1.2.3). - Action normalizes this to
1.2.3forpackage.jsoncomparison.
- Version passed from release tag in
branch(optional, default:master)- Branch/ref used for checkout before validation/publish.
- Recommended to always pass
github.event.release.target_commitishfrom release workflows. - Important: if your repository default branch is
main, do not rely on the defaultmastervalue.
pre-publish-script(optional)- Command executed before publish (for example
npm test).
- Command executed before publish (for example
post-publish-script(optional)- Command executed after successful publish.
publish-command(optional, default:npm publish)- Base publish command; workflow appends
--tag <publish-tag>.
- Base publish command; workflow appends
publish-tag(optional, default:latest)- npm dist-tag used during publishing.
audit-level(optional, default:critical)- Passed to
npm audit --omit=dev --audit-level=<value>. - Allowed values in current docs:
low,moderate,high,critical.
- Passed to
What the Workflow Validates
Before publishing, the shared action validates:
- A git tag exists on the checked-out commit.
- The
versioninput starts withv(for examplev1.2.3). - The commit tag matches the provided
versioninput exactly. package.jsonversion equals normalized input version (without leadingv).npm audit --omit=devpasses at configuredaudit-level.
If a step fails, check the GitHub Actions step summary first, then open logs for full command output.
Manual Run (workflow_dispatch)
You can run your repository workflow (for example, on-release.yml) from the Actions tab if it also supports workflow_dispatch.
Example inputs:
version:v1.2.3branch:main(or your target release branch)pre-publish-script:npm test(optional)
Notes:
versionmust start withv.- The git tag on the selected commit must exactly match
version. package.jsonversion must match normalized version (v1.2.3→1.2.3).
Configuring Secrets
- Go to
Settings → Secrets and variables → Actions. - Ensure that
NPM_TOKENexists.
Trusted Publishing (OIDC)
This publish flow supports npm Trusted Publishing via GitHub OIDC.
Known repositories already using Trusted Publishing:
testcafegulp-qunit-harnessqunit-harnessauce-tunnel
To make OIDC publishing work for a package, it must be configured in npm. Contact Roman Reshetnikov about this.
Notes:
- The caller workflow (for example,
on-release.yml) must includepermissions: id-token: write, which is required for OIDC. - npm CLI uses OIDC in trusted environments and can still authenticate with
NPM_TOKENwhen needed.
Conclusion
- If all steps were completed correctly, create a new GitHub release in the repository.
- Create release tags using
v<release_version>(for example,v1.2.3). - Monitor the publishing workflow execution. If any validation or publish step fails, the package will not be published to npm.
- If your default branch is not
master, always passbranchexplicitly in the release workflow to avoid publishing from the wrong ref. - If you need to republish after fixing an issue, delete both the incorrect release and its tag on GitHub, then create a new release and tag that points to the latest commit.
- Both release deletion and tag deletion can be done from the GitHub Web UI.
