The GitHub Action
Publish npm packages and push images from GitHub Actions in one step, with no Token stored in GitHub.
PolyPack's GitHub Action, cool-studio/polypack-actions@v1, sets a workflow job up to publish one Pack with trusted publishing. It installs the polypack CLI, exchanges GitHub's ID token for a Publisher Token that publishes only that Pack for 15 minutes, and sets npm, or docker and helm, up with it. The steps after it publish as usual. No PolyPack Token is stored in GitHub.
permissions:
contents: read
id-token: write
steps:
- uses: cool-studio/polypack-actions@v1
with:
team: hopper
pack: '@hopper/ui'
Before you use it
- The Pack exists: publish its first version the usual way, with a Token that can publish.
- An Admin adds a trusted publisher on the Pack's page: the repository, the workflow file and, optionally, a GitHub environment. The workflow must match it exactly.
- The job has
permissions: id-token: write, so GitHub gives it an ID token.
The Pack's Publish tab in PolyPack shows the whole workflow, filled in for that Pack and its trusted publisher.
Publish to npm
After the action, a plain npm publish works: the action writes your Team's registry for the Pack's scope, and the Token, into the runner's npm config. Put actions/setup-node before it, as here.
on:
release:
types: [published]
jobs:
publish:
runs-on: ubuntu-latest
environment: npm
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24
- uses: cool-studio/polypack-actions@v1
with:
team: hopper
pack: '@hopper/ui'
- run: npm ci
- run: npm publish
Push an image or a chart
For an image, the action runs docker login to your Team's image host, and helm registry login too when the runner has helm, both with a Token that can push only that image.
on:
push:
tags: ['v*']
jobs:
image:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v7
- uses: cool-studio/polypack-actions@v1
with:
team: hopper
pack: api
- run: |
docker build -t hopper.cr.polypack.io/api:${{ github.ref_name }} .
docker push hopper.cr.polypack.io/api:${{ github.ref_name }}
A Helm chart is a Pack of its own: helm push api-0.1.0.tgz oci://hopper.cr.polypack.io/charts pushes charts/api, so a job pushing it runs the action with pack: charts/api, and that Pack needs its own trusted publisher.
Publish Files
For a Files Pack, give the action the Files and the Version: it exchanges the ID token, uploads each File straight to storage with a Token that can publish only that Pack, and publishes the Version once all of them are in. A tag such as v1.2.0 becomes Version 1.2.0.
on:
release:
types: [published]
jobs:
binaries:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v7
- run: make dist # builds hopper-cli for each platform into dist/
- uses: cool-studio/polypack-actions@v1
with:
team: hopper
pack: hopper-cli
files: dist/*
version: ${{ github.ref_name }}
A Version is published only once, with all its Files: if the job fails part way, run it again, and the draft's Files are replaced. Versions published this way carry signed provenance, a subject per File.
Push a gem
For a RubyGems Pack, give the action the gems you built: it exchanges the ID token and runs gem push for each, with a Token that can push only that gem. Set up Ruby before it. Push every platform gem of a version from the same job, or within 72 hours of the first. Each gem pushed this way carries signed provenance of its own, which polypack verify gem checks.
on:
release:
types: [published]
jobs:
gem:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v7
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.4'
- run: gem build hopper-widgets.gemspec
- uses: cool-studio/polypack-actions@v1
with:
team: hopper
pack: hopper-widgets
rubygems: '*.gem'
Inputs
| Input | Required | What it is |
|---|---|---|
team | yes | Your Team's slug, as in hopper.pkg.polypack.io. |
pack | yes | The Pack to publish: an npm name such as @hopper/ui, an image such as api, a Files Pack such as hopper-cli (with files), or a gem such as hopper-widgets (with rubygems). Quote names starting with @ in YAML. |
files | for Files | For a Files Pack: the Files to upload, as a pattern such as dist/*. |
rubygems | for gems | For a RubyGems Pack: the built gems to push, as a pattern such as pkg/*.gem. |
version | for Files | For a Files Pack: the Version to publish, such as ${{ github.ref_name }}; a leading v is dropped. |
registry | no | The npm Registry's URL, only for a PolyPack instance other than polypack.io. |
oci | no | The image host's URL, only for a PolyPack instance other than polypack.io. |
cli-version | no | The polypack CLI release to run, such as v0.10.0. By default, the one this action release pins. |
The Token is masked in the job's log and expires 15 minutes after the exchange. Each job that publishes runs the action itself; a Token is never passed between jobs.
Versions
The action lives in the public cool-studio/polypack-actions repository. cool-studio/polypack-actions@v1, as the examples here use, moves to each v1.x.y release, so fixes reach you as they come; pin a release such as v1.0.0, which never moves, or its commit SHA, to change only when you choose. A breaking change would be v2. The CLI it installs comes from PolyPack, checked against PolyPack's signature.
Workflows using the earlier cool-studio/polypack-cli@v0.x keep working; move to cool-studio/polypack-actions@v1 when you next edit them.
If the step fails
- The step fails with PolyPack's own reason, so the publish never runs with no Token.
- "No trusted publisher of … matches this workflow": the repository, workflow file or environment differs from the trusted publisher's, or the Pack name is wrong.
- "No GitHub ID token": add
id-token: writeto the job'spermissions. Workflows run for pull requests from forks never get an ID token. - "This is not a valid GitHub Actions ID token for this Registry": the
team(orregistry,oci) is not the Team the Pack belongs to.
Not what you need?
- To install private Packs in CI, use a read-only Team Token: see Installing in CI.
- Composer Packs need no action: their versions come from GitHub through Sync (see Composer).
- Outside GitHub Actions, publish with a Team Token that can publish.