Skip to content

Commit 098ed1e

Browse files
committedJul 2, 2023
chore: improved release workflow
1 parent cc2663b commit 098ed1e

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed
 

‎.github/workflows/release.yml

+3-10
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,16 @@ jobs:
5555
needs: [checks, security]
5656
steps:
5757
- uses: actions/checkout@v3
58-
# Setup .npmrc file to publish to npm
5958
- uses: actions/setup-node@v3
6059
with:
6160
node-version: '10'
61+
# Setup .npmrc file to publish to npm
6262
registry-url: 'https://registry.npmjs.org'
6363
- uses: actions/cache@v3
6464
with:
65-
# This is cache where npm installs from before going out to the network
66-
path: ~/.npm
65+
path: ~/.npm # this is cache where npm installs from before going out to the network
6766
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
6867
- run: npm install --prefer-offline
69-
- if: ${{ !contains(github.ref_name, '-test.') }}
70-
run: npm publish --tag latest-v3.x
71-
env:
72-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
73-
# If "test" prerelease is present, pretend to publish package.
74-
- if: ${{ contains(github.ref_name, '-test.') }}
75-
run: npm publish --tag latest-v3.x --dry-run
68+
- run: ./release
7669
env:
7770
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

‎release

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash -xv
2+
3+
# Removes "v" prefix
4+
version=${GITHUB_REF_NAME:1}
5+
6+
# Major of the version being handled by the current workflow
7+
workflow_major=$(echo $version | cut -d. -f1)
8+
9+
workflow_track="latest-v${workflow_major}.x"
10+
11+
# Major of the version published under the current "latest" npm tag
12+
latest_major=$(npm view cross-fetch@latest version | cut -d. -f1)
13+
14+
15+
# If it's test prerelease, we just want to test the release workflow (dry run it!)
16+
if [[ "$version" == *"-test."* ]]; then
17+
npm publish --tag $workflow_track --dry-run && \
18+
exit 0
19+
fi
20+
21+
npm publish --tag $workflow_track
22+
23+
if [[ "$workflow_major" == "$latest_major" ]]; then
24+
npm dist-tag add cross-fetch@$version latest
25+
fi
26+
27+
if [[ "$workflow_major" == "$(($latest_major + 1))" ]]; then
28+
npm dist-tag add cross-fetch@$version next
29+
fi

0 commit comments

Comments
 (0)
Please sign in to comment.