-
Notifications
You must be signed in to change notification settings - Fork 0
58 lines (46 loc) · 1.44 KB
/
publish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
name: Publish to npm
on:
push:
branches:
- main
jobs:
test-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
- name: Install dependencies
run: yarn install
- name: Install jq
run: sudo apt-get install -y jq
- name: Run tests
run: yarn test
- name: Build it
run: yarn build
- name: Get current version
id: get_version
run: echo "version=$(jq -r .version package.json)" >> $GITHUB_ENV
- name: Check if version is published
id: version_check
run: |
PUBLISHED_VERSIONS=$(yarn info . versions --json | jq -r '.data')
CURRENT_VERSION=$(jq -r .version package.json)
if echo "$PUBLISHED_VERSIONS" | jq -e ". | index(\"$CURRENT_VERSION\")" > /dev/null; then
echo "Version $CURRENT_VERSION is already published."
exit 0
else
echo "Version $CURRENT_VERSION is new and will be published."
echo "new_version=true" >> $GITHUB_ENV
fi
- name: Configure npm for authentication
if: env.new_version == 'true'
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
- name: Publish to npm
if: env.new_version == 'true'
run: yarn publish