Skip to content

Commit 51aed2e

Browse files
authored
ci: separate next version resolver to sub job (#1321)
* ci: separate next version resolver to sub job * chore: fix typos
1 parent 03b9ba5 commit 51aed2e

File tree

2 files changed

+50
-35
lines changed

2 files changed

+50
-35
lines changed

.github/workflows/dev-publish.yml

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,24 @@ jobs:
3434
package-lite.json
3535
retention-days: 1
3636

37+
version:
38+
runs-on: ubuntu-latest
39+
outputs:
40+
v: ${{ steps.ref.outputs.ZX_VERSION }}
41+
lite: ${{ steps.ref.outputs.ZX_VERSION }}-lite
42+
dev: ${{ steps.ref.outputs.ZX_VERSION }}-dev.${{ steps.ref.outputs.SHA_SHORT }}
43+
lite-dev: ${{ steps.ref.outputs.ZX_VERSION }}-lite-dev.${{ steps.ref.outputs.SHA_SHORT }}
44+
steps:
45+
- uses: actions/checkout@v4
46+
with:
47+
persist-credentials: false
48+
- id: ref
49+
run: |
50+
echo SHA_SHORT=$(git rev-parse --short HEAD) >> $GITHUB_OUTPUT
51+
echo ZX_VERSION=$(jq -r '.version' package.json) >> $GITHUB_OUTPUT
52+
3753
npm-publish:
38-
needs: build
54+
needs: [build, version]
3955
runs-on: ubuntu-latest
4056
permissions:
4157
checks: read
@@ -48,6 +64,9 @@ jobs:
4864
GOOGLE_NPM_TOKEN: ${{ secrets.AUTH_TOKEN }}
4965
GH_NPM_REGISTRY: npm.pkg.github.com
5066
GH_NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
ZX_VERSION: ${{ needs.version.outputs.v }}
68+
ZX_DEV_VERSION: ${{ needs.version.outputs.dev }}
69+
ZX_LITE_DEV_VERSION: ${{ needs.version.outputs.lite-dev }}
5170
steps:
5271
- uses: actions/checkout@v4
5372
with:
@@ -56,13 +75,6 @@ jobs:
5675
with:
5776
node-version: 22
5877
cache: 'npm'
59-
- name: Get zx version info
60-
run: |
61-
echo SHA_SHORT=$(git rev-parse --short HEAD) >> $GITHUB_ENV
62-
echo ZX_VERSION=$(jq -r '.version' package.json) >> $GITHUB_ENV
63-
- run: |
64-
echo ZX_DEV_VERSION="${{ env.ZX_VERSION }}-dev.${{ env.SHA_SHORT }}" >> $GITHUB_ENV
65-
echo ZX_LITE_DEV_VERSION="${{ env.ZX_VERSION }}-lite-dev.${{ env.SHA_SHORT }}" >> $GITHUB_ENV
6678
- name: Configure npmrc
6779
run: |
6880
echo "//${{ env.GOOGLE_NPM_REGISTRY }}/:_authToken=$GOOGLE_NPM_TOKEN" >> .npmrc
@@ -89,11 +101,13 @@ jobs:
89101
npm publish --provenance --access=public --no-git-tag-version --tag dev --registry https://${{ env.GOOGLE_NPM_REGISTRY }}
90102
91103
jsr-publish:
92-
needs: build
104+
needs: [build, version]
93105
runs-on: ubuntu-latest
94106
permissions:
95107
contents: read
96108
id-token: write
109+
env:
110+
ZX_DEV_VERSION: ${{ needs.version.outputs.dev }}
97111
steps:
98112
- uses: actions/checkout@v4
99113
with:
@@ -105,32 +119,27 @@ jobs:
105119
- uses: actions/download-artifact@v4
106120
with:
107121
name: build-${{ github.run_id }}
108-
- name: Get zx version info
109-
run: |
110-
echo SHA_SHORT=$(git rev-parse --short HEAD) >> $GITHUB_ENV
111-
echo ZX_VERSION=$(jq -r '.version' package.json) >> $GITHUB_ENV
112-
- run: |
113-
echo ZX_DEV_VERSION="${{ env.ZX_VERSION }}-dev.${{ env.SHA_SHORT }}" >> $GITHUB_ENV
114122
- name: pushing to jsr.io
115123
run: |
116124
cat <<< $(jq '.version="${{ env.ZX_DEV_VERSION }}"' jsr.json) > jsr.json
117125
npx jsr publish --allow-dirty
118126
119127
# https://docs.github.com/en/actions/use-cases-and-examples/publishing-packages/publishing-docker-images
120128
docker-publish:
121-
needs: build
129+
needs: [build, version]
122130
runs-on: ubuntu-latest
123-
# 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.
124-
env:
125-
REGISTRY: ghcr.io
126-
IMAGE_NAME: ${{ github.repository }}
127-
128131
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
129132
permissions:
130133
contents: read
131134
packages: write
132135
attestations: write
133136
id-token: write
137+
138+
# 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.
139+
env:
140+
REGISTRY: ghcr.io
141+
IMAGE_NAME: ${{ github.repository }}
142+
ZX_DEV_VERSION: ${{ needs.version.outputs.dev }}
134143
steps:
135144
- name: Checkout repository
136145
uses: actions/checkout@v4
@@ -141,11 +150,6 @@ jobs:
141150
with:
142151
name: build-${{ github.run_id }}
143152

144-
- name: Set zx version
145-
run: |
146-
echo SHA_SHORT=$(git rev-parse --short HEAD) >> $GITHUB_ENV
147-
echo ZX_VERSION=$(jq -r '.version' package.json) >> $GITHUB_ENV
148-
149153
# 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.
150154
- name: Log in to the Container registry
151155
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 #v3.4.0
@@ -161,7 +165,7 @@ jobs:
161165
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
162166
tags: |
163167
type=sha
164-
type=semver,pattern={{version}},value=v${{ env.ZX_VERSION }}-dev.${{ env.SHA_SHORT }}
168+
type=semver,pattern={{version}},value=v${{ env.ZX_DEV_VERSION }}
165169
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
166170
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see [Usage](https://github.com/docker/build-push-action#usage) in the README of the `docker/build-push-action` repository.
167171
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.

.github/workflows/publish.yml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,27 @@ jobs:
3131
name: build-${{ github.run_id }}
3232
path: |
3333
build
34+
jsr.json
3435
package.json
3536
package-lite.json
36-
jsr.json
3737
retention-days: 1
3838

39+
version:
40+
runs-on: ubuntu-latest
41+
outputs:
42+
v: ${{ steps.ref.outputs.ZX_VERSION }}
43+
lite: ${{ steps.ref.outputs.ZX_VERSION }}-lite
44+
steps:
45+
- uses: actions/checkout@v4
46+
with:
47+
persist-credentials: false
48+
- id: ref
49+
run: |
50+
echo SHA_SHORT=$(git rev-parse --short HEAD) >> $GITHUB_OUTPUT
51+
echo ZX_VERSION=$(jq -r '.version' package.json) >> $GITHUB_OUTPUT
52+
3953
npm-publish:
40-
needs: build
54+
needs: [build, version]
4155
runs-on: ubuntu-latest
4256
permissions:
4357
checks: read
@@ -50,6 +64,7 @@ jobs:
5064
GOOGLE_NPM_TOKEN: ${{ secrets.AUTH_TOKEN }}
5165
GH_NPM_REGISTRY: npm.pkg.github.com
5266
GH_NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
ZX_VERSION: ${{ needs.version.outputs.v }}
5368
steps:
5469
- uses: actions/checkout@v4
5570
with:
@@ -58,8 +73,6 @@ jobs:
5873
with:
5974
node-version: 22
6075
cache: 'npm'
61-
- name: Get zx version info
62-
run: echo ZX_VERSION=$(jq -r '.version' package.json) >> $GITHUB_ENV
6376
- name: Configure npmrc
6477
run: |
6578
echo "//${{ env.GOOGLE_NPM_REGISTRY }}/:_authToken=$GOOGLE_NPM_TOKEN" >> .npmrc
@@ -102,12 +115,13 @@ jobs:
102115
run: npx jsr publish --allow-dirty
103116

104117
docker-publish:
105-
needs: build
118+
needs: [build, version]
106119
runs-on: ubuntu-latest
107120
# 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.
108121
env:
109122
REGISTRY: ghcr.io
110123
IMAGE_NAME: ${{ github.repository }}
124+
ZX_VERSION: ${{ needs.version.outputs.v }}
111125

112126
permissions:
113127
contents: read
@@ -124,9 +138,6 @@ jobs:
124138
with:
125139
name: build-${{ github.run_id }}
126140

127-
- name: Get zx version
128-
run: echo ZX_VERSION=$(jq -r '.version' package.json) >> $GITHUB_ENV
129-
130141
- name: Log in to the Container registry
131142
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 #v3.4.0
132143
with:

0 commit comments

Comments
 (0)