Skip to content

Commit cfc993b

Browse files
committed
chore: update NPM publishing
fixes #464 Signed-off-by: Ry Jones <[email protected]>
1 parent 491b56f commit cfc993b

File tree

1 file changed

+46
-7
lines changed

1 file changed

+46
-7
lines changed

.github/workflows/release.yaml

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ on:
99
- "v[0-9]+.[0-9]+.[0-9]+"
1010
- "v[0-9]+.[0-9]+.[0-9]+-*"
1111

12+
# ---- Global permissions for Trusted Publishing & attestations ----
13+
# id-token:write is required for OIDC (npm trusted publishing, keyless attestations)
14+
# packages:write for GHCR; attestations:write for GitHub artifact attestations (optional but recommended)
15+
permissions:
16+
contents: read
17+
1218
env:
1319
IMAGE_NAME: ${{ github.repository_owner }}/fabric-nodeenv
1420

@@ -19,30 +25,39 @@ jobs:
1925
publishnpm:
2026
runs-on: ubuntu-24.04
2127
needs: test
28+
permissions:
29+
contents: read
30+
id-token: write
2231
steps:
2332
- uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
2433
with:
2534
node-version: "18.x"
2635
registry-url: "https://registry.npmjs.org"
36+
# Ensure npm 11.5.1 or later for trusted publishing support
37+
- name: Update npm
38+
run: npm install -g npm@latest
2739
- uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
2840
with:
2941
name: node-tgzs
3042
path: build/
31-
- run: |
43+
- name: Publish packages with provenance (OIDC)
44+
# No NODE_AUTH_TOKEN needed when Trusted Publishing is enabled.
45+
# --provenance tells npm to attach SLSA provenance to the package. [oai_citation:1‡The GitHub Blog](https://github.blog/security/supply-chain-security/introducing-npm-package-provenance/?utm_source=chatgpt.com)
46+
run: |
3247
set -xev
3348
ls -lart build/
3449
cd build
3550
find . -type f -name 'fabric-*.tgz' -exec npm publish {} \;
36-
env:
37-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3851
52+
# ========= Build & push per-arch images (with provenance/SBOM) =========
3953
docker-build-push:
40-
name: Push Docker image
54+
name: Build & Push Docker image (per-arch)
4155
needs: test
4256
runs-on: ${{ matrix.arch.runner }}
4357
permissions:
4458
contents: read
45-
packages: write
59+
packages: write # for ghcr.io
60+
id-token: write # for provenance/attestations
4661
strategy:
4762
fail-fast: false
4863
matrix:
@@ -53,50 +68,69 @@ jobs:
5368
runner: ubuntu-24.04-arm
5469
steps:
5570
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
71+
5672
- name: Get commit timestamp
5773
run: echo "SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)" >> "${GITHUB_ENV}"
58-
- name: Login to GitHub Container Registry
74+
75+
# ---- GHCR login via GITHUB_TOKEN (already short-lived/trusted) ----
76+
- name: Login to GitHub Container Registry (ghcr.io)
5977
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
6078
with:
6179
registry: ghcr.io
6280
username: ${{ github.actor }}
6381
password: ${{ secrets.GITHUB_TOKEN }}
82+
83+
# ---- Optional: Docker Hub login (kept for now) ----
84+
# If your Docker Hub org enables its own trusted/OIDC flow later, you can
85+
# replace this with that method; until then PAT is required. [oai_citation:2‡Docker Documentation](https://docs.docker.com/docker-hub/image-library/trusted-content/?utm_source=chatgpt.com)
6486
- name: Login to Docker Hub
87+
88+
if: ${{ secrets.DOCKERHUB_USERNAME && secrets.DOCKERHUB_TOKEN }}
6589
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
6690
with:
6791
registry: docker.io
6892
username: ${{ secrets.DOCKERHUB_USERNAME }}
6993
password: ${{ secrets.DOCKERHUB_TOKEN }}
94+
7095
- name: Set up Docker Buildx
7196
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
72-
- name: Build image
97+
98+
- name: Build image (per-arch) with provenance + SBOM
7399
id: build
74100
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
75101
with:
76102
file: docker/fabric-nodeenv/Dockerfile
77103
context: docker/fabric-nodeenv
104+
platforms: ${{ matrix.arch.platform }}
105+
# Generate and attach provenance/SBOM at build time. [oai_citation:3‡Docker Documentation](https://docs.docker.com/build/metadata/attestations/slsa-provenance/?utm_source=chatgpt.com)
106+
provenance: true
107+
sbom: true
78108
outputs: type=registry,"name=${{ format('ghcr.io/{0},docker.io/{0}', env.IMAGE_NAME) }}",push-by-digest=true,name-canonical=true
79109
env:
80110
SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
111+
81112
- name: Export digest
82113
run: |
83114
mkdir -p ${{ runner.temp }}/digests
84115
digest="${{ steps.build.outputs.digest }}"
85116
touch "${{ runner.temp }}/digests/${digest#sha256:}"
117+
86118
- name: Upload digest
87119
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
88120
with:
89121
name: digest-${{ matrix.arch.platform }}
90122
path: ${{ runner.temp }}/digests/*
91123
if-no-files-found: error
92124

125+
# =============== Manifest + tags publishing ==================
93126
docker-meta:
94127
needs: docker-build-push
95128
name: Publish Docker metadata
96129
runs-on: ubuntu-latest
97130
permissions:
98131
contents: read
99132
packages: write
133+
id-token: write
100134
strategy:
101135
fail-fast: false
102136
matrix:
@@ -110,12 +144,14 @@ jobs:
110144
path: ${{ runner.temp }}/digests
111145
pattern: digest-*
112146
merge-multiple: true
147+
113148
- name: Login to ${{ matrix.registry }}
114149
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
115150
with:
116151
registry: ${{ matrix.registry }}
117152
username: ${{ matrix.registry == 'docker.io' && secrets.DOCKERHUB_USERNAME || github.actor }}
118153
password: ${{ matrix.registry == 'docker.io' && secrets.DOCKERHUB_TOKEN || secrets.GITHUB_TOKEN }}
154+
119155
- name: Docker metadata
120156
id: meta
121157
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0
@@ -125,12 +161,15 @@ jobs:
125161
type=semver,pattern={{version}}
126162
type=semver,pattern={{major}}.{{minor}}
127163
type=semver,pattern={{major}}.{{minor}}.{{patch}}
164+
128165
- name: Set up Docker Buildx
129166
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
167+
130168
- name: Create and push manifest list
131169
working-directory: ${{ runner.temp }}/digests
132170
run: |
133171
docker buildx imagetools create $(jq -cr '.tags | map("--tag " + .) | join(" ")' <<< "${DOCKER_METADATA_OUTPUT_JSON}") \
134172
$(printf '${{ matrix.registry }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
173+
135174
- name: Inspect image
136175
run: docker buildx imagetools inspect '${{ matrix.registry }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}'

0 commit comments

Comments
 (0)