Skip to content

Commit 7435fe4

Browse files
committed
CI: Adds publishing script for npm
1 parent 363ce3b commit 7435fe4

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

.github/workflows/CI.yml

+30
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ jobs:
2424
- name: Build
2525
run: yarn build
2626

27+
- name: Upload build artifact
28+
uses: actions/upload-artifact@v2
29+
with:
30+
name: dist
31+
path: |
32+
dist/**/*
33+
if-no-files-found: error
34+
2735
test:
2836
runs-on: ubuntu-latest
2937
env:
@@ -51,3 +59,25 @@ jobs:
5159

5260
- name: Run tests
5361
run: yarn test --runInBand
62+
63+
publishRelease:
64+
name: Potentially publish release
65+
runs-on: ubuntu-latest
66+
needs: [build, test]
67+
if: github.ref == 'refs/heads/main'
68+
env:
69+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
70+
71+
steps:
72+
- uses: actions/checkout@v2
73+
with:
74+
fetch-depth: 25
75+
76+
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
77+
78+
- name: Download build artifact
79+
uses: actions/download-artifact@v2
80+
with:
81+
name: dist
82+
83+
- run: ./scripts/publish-release.sh

scripts/publish-release.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
git describe --exact-match
4+
5+
if [[ ! $? -eq 0 ]];then
6+
echo "Nothing to publish, exiting.."
7+
exit 0;
8+
fi
9+
10+
if [[ -z "$NPM_TOKEN" ]];then
11+
echo "No NPM_TOKEN, exiting.."
12+
exit 0;
13+
fi
14+
15+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
16+
17+
if [[ $(git describe --match "v[0-9]*" --abbrev=0 HEAD 2> /dev/null) ]];then
18+
echo "Publishing version"
19+
npm publish --access public
20+
21+
# Make sure to exit script with code 1 if publish failed
22+
if [[ ! $? -eq 0 ]];then
23+
exit 1;
24+
fi
25+
fi

0 commit comments

Comments
 (0)