Skip to content

Commit 9511ba3

Browse files
authored
ci: enable additional publish flows (#1176)
1 parent bce4c06 commit 9511ba3

File tree

2 files changed

+92
-9
lines changed

2 files changed

+92
-9
lines changed

.github/workflows/dev-publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ jobs:
117117
- name: Set zx version
118118
run: |
119119
echo SHA_SHORT=$(git rev-parse --short HEAD) >> $GITHUB_ENV
120-
echo ZX_VERSION=$(npm pkg get version | tr -d \") >> $GITHUB_ENV
120+
echo ZX_VERSION=$(jq -r '.version' package.json) >> $GITHUB_ENV
121121
122122
# Uses the `docker/login-action` action to log in to the Container registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
123123
- name: Log in to the Container registry

.github/workflows/npm-publish.yml

+91-8
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,19 @@ jobs:
2222
- run: npm test
2323
env:
2424
FORCE_COLOR: 3
25-
- run: node scripts/prepublish-clean.mjs
25+
- run: |
26+
node scripts/build-jsr.mjs
27+
node scripts/prepublish-clean.mjs
2628
- uses: actions/upload-artifact@v4
2729
with:
2830
name: build-${{ github.run_id }}
2931
path: |
3032
build
3133
package.json
34+
jsr.json
3235
retention-days: 1
3336

34-
publish:
37+
npm-publish:
3538
needs: build
3639
runs-on: ubuntu-latest
3740
permissions:
@@ -40,6 +43,11 @@ jobs:
4043
contents: write
4144
packages: write
4245
id-token: write
46+
env:
47+
GOOGLE_NPM_REGISTRY: wombat-dressing-room.appspot.com
48+
GOOGLE_NPM_TOKEN: ${{ secrets.AUTH_TOKEN }}
49+
GH_NPM_REGISTRY: npm.pkg.github.com
50+
GH_NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4351
steps:
4452
- uses: actions/checkout@v4
4553
with:
@@ -48,13 +56,88 @@ jobs:
4856
with:
4957
node-version: 22
5058
cache: 'npm'
59+
- name: Get zx version info
60+
run: echo ZX_VERSION=$(jq -r '.version' package.json) >> $GITHUB_ENV
61+
- name: Configure npmrc
62+
run: |
63+
echo "//${{ env.GOOGLE_NPM_REGISTRY }}/:_authToken=$GOOGLE_NPM_TOKEN" >> .npmrc
64+
echo "//${{ env.GH_NPM_REGISTRY }}/:_authToken=$GH_NPM_TOKEN" >> .npmrc
5165
- uses: actions/download-artifact@v4
5266
with:
5367
name: build-${{ github.run_id }}
54-
- run: echo "//wombat-dressing-room.appspot.com/:_authToken=$AUTH_TOKEN" >> .npmrc
55-
env:
56-
AUTH_TOKEN: ${{ secrets.AUTH_TOKEN }}
57-
- run: |
58-
npm publish --provenance --access=public
68+
69+
- name: pushing to ${{ env.GOOGLE_NPM_REGISTRY }}
70+
run: npm publish --provenance --access=public --registry https://${{ env.GOOGLE_NPM_REGISTRY }}
71+
72+
- name: pushing to ${{ env.GH_NPM_REGISTRY }}
73+
run: |
74+
cat <<< $(jq '.name="@${{ github.repository }}"' package.json) > package.json
75+
npm publish --no-git-tag-version --access=public --registry https://${{ env.GH_NPM_REGISTRY }}
76+
77+
- name: pushing lite snapshot to ${{ env.GOOGLE_NPM_REGISTRY }}
78+
run: |
79+
cat <<< $(jq '.name="zx"' package.json) > package.json
5980
node scripts/prepublish-lite.mjs
60-
npm publish --provenance --access=public --no-git-tag-version --tag lite
81+
npm publish --provenance --access=public --no-git-tag-version --tag lite --registry https://${{ env.GOOGLE_NPM_REGISTRY }}
82+
83+
- name: pushing to jsr.io
84+
run: npx jsr publish --allow-dirty
85+
86+
# https://docs.github.com/en/actions/use-cases-and-examples/publishing-packages/publishing-docker-images
87+
docker-publish:
88+
needs: build
89+
runs-on: ubuntu-latest
90+
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
91+
env:
92+
REGISTRY: ghcr.io
93+
IMAGE_NAME: ${{ github.repository }}
94+
95+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
96+
permissions:
97+
contents: read
98+
packages: write
99+
attestations: write
100+
id-token: write
101+
steps:
102+
- name: Checkout repository
103+
uses: actions/checkout@v4
104+
with:
105+
persist-credentials: false
106+
107+
- uses: actions/download-artifact@v4
108+
with:
109+
name: build-${{ github.run_id }}
110+
111+
- name: Get zx version
112+
run: echo ZX_VERSION=$(jq -r '.version' package.json) >> $GITHUB_ENV
113+
114+
- name: Log in to the Container registry
115+
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772
116+
with:
117+
registry: ${{ env.REGISTRY }}
118+
username: ${{ github.actor }}
119+
password: ${{ secrets.GITHUB_TOKEN }}
120+
- name: Extract metadata (tags, labels) for Docker
121+
id: meta
122+
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804
123+
with:
124+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
125+
tags: |
126+
type=sha
127+
type=semver,pattern={{version}},value=v${{ env.ZX_VERSION }}
128+
- name: Build and push Docker image
129+
id: push
130+
uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4
131+
with:
132+
context: ./
133+
file: ./dcr/Dockerfile
134+
push: true
135+
tags: ${{ steps.meta.outputs.tags }}
136+
labels: ${{ steps.meta.outputs.labels }}
137+
138+
- name: Generate artifact attestation
139+
uses: actions/attest-build-provenance@v2
140+
with:
141+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
142+
subject-digest: ${{ steps.push.outputs.digest }}
143+
push-to-registry: true

0 commit comments

Comments
 (0)