Skip to content

Commit e08e994

Browse files
Merge pull request #222 from Bogomil-Stoyanov/publish-npm-from-branch
Extract GitHub Actions changes for branch-based publishing
2 parents b71a623 + 809159a commit e08e994

File tree

1 file changed

+49
-13
lines changed

1 file changed

+49
-13
lines changed

.github/workflows/publish.yml

+49-13
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,59 @@ jobs:
88
ci:
99
uses: ./.github/workflows/ci.yml
1010
cd:
11+
needs:
12+
- ci
1113
runs-on: ubuntu-latest
1214
steps:
13-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
14-
- uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4
15-
with:
16-
cache: 'npm'
17-
node-version-file: '.nvmrc'
18-
registry-url: 'https://registry.npmjs.org'
15+
- name: Debug info
16+
run: |
17+
cat <<EOF
18+
Release tag name: ${{ github.event.release.tag_name }}
19+
Release target commit-ish: ${{ github.event.release.target_commitish }}
20+
EOF
21+
22+
- name: Determine NPM tag
23+
id: npm_tag
24+
shell: bash
25+
run: |
26+
case ${{ github.event.release.target_commitish }} in
27+
develop | main | master)
28+
if [[ ${{ github.event.release.prerelease }} == true ]]; then
29+
npm_tag=beta
30+
else
31+
npm_tag=latest
32+
fi
33+
;;
34+
*)
35+
# use the branch name
36+
npm_tag="${{ github.event.release.target_commitish }}"
37+
;;
38+
esac
39+
echo "Determined NPM tag: [$npm_tag]"
40+
echo "npm_tag=${npm_tag}" >> "$GITHUB_OUTPUT"
41+
- name: Check NPM tag
42+
run: |
43+
if [ -z "${{ steps.npm_tag.outputs.npm_tag }}" ]; then
44+
echo "Refusing to publish with empty NPM tag."
45+
exit 1
46+
fi
1947
2048
- name: Config GitHub user
2149
shell: bash
2250
run: |
2351
git config --global user.name 'GitHub Actions'
2452
git config --global user.email 'github-actions@localhost'
2553
54+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
55+
with:
56+
token: ${{ secrets.PAT_RELEASE_PUSH }} # persists the token for pushing to the repo later
57+
58+
- uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4
59+
with:
60+
cache: 'npm'
61+
node-version-file: '.nvmrc'
62+
registry-url: 'https://registry.npmjs.org'
63+
2664
- uses: ./.github/actions/install-dependencies
2765

2866
- name: Update the version in the package files
@@ -32,28 +70,28 @@ jobs:
3270
NEW_VERSION="${GIT_TAG/v/}"
3371
3472
npm version "$NEW_VERSION" --no-git-tag-version
35-
git add package* && git commit -m "Release $NEW_VERSION"
73+
git add package* && git commit -m "chore(release): $NEW_VERSION [skip ci]"
3674
3775
- name: Build packages
3876
run: npm run build
3977

4078
- name: Publish scratch-svg-renderer
41-
run: npm publish --access=public --workspace=@scratch/scratch-svg-renderer
79+
run: npm publish --access=public --tag="${{steps.npm_tag.outputs.npm_tag}}" --workspace=@scratch/scratch-svg-renderer
4280
env:
4381
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
4482

4583
- name: Publish scratch-render
46-
run: npm publish --access=public --workspace=@scratch/scratch-render
84+
run: npm publish --access=public --tag="${{steps.npm_tag.outputs.npm_tag}}" --workspace=@scratch/scratch-render
4785
env:
4886
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
4987

5088
- name: Publish scratch-vm
51-
run: npm publish --access=public --workspace=@scratch/scratch-vm
89+
run: npm publish --access=public --tag="${{steps.npm_tag.outputs.npm_tag}}" --workspace=@scratch/scratch-vm
5290
env:
5391
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
5492

5593
- name: Publish scratch-gui
56-
run: npm publish --access=public --workspace=@scratch/scratch-gui
94+
run: npm publish --access=public --tag="${{steps.npm_tag.outputs.npm_tag}}" --workspace=@scratch/scratch-gui
5795
env:
5896
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
5997

@@ -110,5 +148,3 @@ jobs:
110148
publish_dir: ./packages/scratch-gui/build
111149
destination_dir: scratch-gui
112150
full_commit_message: "Build for ${{ github.sha }} ${{ github.event.head_commit.message }}"
113-
needs:
114-
- ci

0 commit comments

Comments
 (0)