-
Notifications
You must be signed in to change notification settings - Fork 0
64 lines (52 loc) · 2.24 KB
/
build-and-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
59
60
61
62
63
64
name: Build and Publish to GitHub Packages
on:
push:
jobs:
build_and_publish:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
- name: Cache npm dependencies
uses: actions/cache@v2
with:
path: ~/.npm # This caches the npm cache, not node_modules directly
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Install dependencies
run: npm ci
- name: Run Jest tests
run: npm test
- name: Just build don't ship
if: github.ref != 'refs/heads/main'
run: |
npm run build
- name: Set next version
run: |
next_version=$(git for-each-ref --sort=-creatordate --format '%(refname:short)' refs/tags/v* | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1 | awk -F '.' '{print $1 "." $2 "." $3+1}')
next_version=${next_version#v}
echo "next_version=$next_version"
echo "next_version=$next_version" >> $GITHUB_ENV
- name: Bump version and create new tag
if: github.ref == 'refs/heads/main'
run: |
echo '//npm.pkg.github.com/:_authToken=${NPM_TOKEN}' >> .npmrc
git config user.name "GitHub Actions"
git config user.email "<[email protected]>"
# Update package.json with the new version
jq ".version = \"${{ env.next_version }}\"" package.json > tmp.json && mv tmp.json package.json
git tag -a v${{ env.next_version }} -m "Release v${{ env.next_version }}"
npm run ship
git push origin v${{ env.next_version }}
env:
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}