Skip to content

Commit 310c685

Browse files
committed
Add publish job
1 parent 54e8f2d commit 310c685

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Publish package on NPM
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
release:
8+
types:
9+
- prereleased
10+
- released
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
16+
with:
17+
fetch-depth: 1
18+
- uses: actions/setup-node@v3
19+
with:
20+
node-version: 18
21+
- name: Releasing tag ${{ github.event.release.tag_name }}
22+
run: |
23+
corepack enable; yarn
24+
25+
# Get tag name from event
26+
tag_name="${{ github.event.release.tag_name }}"
27+
28+
if [[ ! "$tag_name" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
29+
cd $(echo $tag_name | rev | cut -d'/' -f2- | rev)
30+
fi
31+
32+
yarn_major_version=$(yarn --version | cut -d'.' -f1)
33+
if [ "$yarn_major_version" -ge 2 ] && [ "$yarn_major_version" -le 4 ]; then
34+
cmd="yarn npm publish --access public"
35+
elif [ "$yarn_major_version" -eq 1 ]; then
36+
cmd="yarn publish --access public"
37+
else
38+
echo "Unsupported Yarn version: $yarn_major_version"
39+
exit 1
40+
fi
41+
42+
if [ "${{ github.event.release.prerelease }}" == "true" ]; then
43+
cmd+=" --tag=beta"
44+
else
45+
cmd+=" --tag=latest"
46+
fi
47+
48+
eval $cmd
49+
env:
50+
NPM_AUTH_TOKEN: ${{ secrets.YARN_NPM_AUTH_TOKEN }}
51+
YARN_NPM_AUTH_TOKEN: ${{ secrets.YARN_NPM_AUTH_TOKEN }}
52+
COREPACK_ENABLE_DOWNLOAD_PROMPT: 0

0 commit comments

Comments
 (0)