-
Notifications
You must be signed in to change notification settings - Fork 3
82 lines (75 loc) · 2.57 KB
/
publish.yaml
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
name: Publish
on:
release:
types: [created] # will be triggered when a NON-draft release is created and published.
jobs:
distribute:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: master # otherwise it defaults to the version tag missing bump commit
fetch-depth: 0 # fetch all history
- uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Clear dist folder
run: rm -rfv dist/
- name: Compile
run: npm run compile
- name: Amend dist folder to the commit
run: |-
if [[ -z $(git status -s) ]]; then
echo 'There are no changes in the distribution (dist folder)'
exit 0
fi
lastCommitSha=$(git rev-parse HEAD)
bumpCommitSha=$(git rev-list "${{ github.event.release.tag_name }}"..master | tail -1)
if [ "$lastCommitSha" != "$bumpCommitSha" ]; then
echo "Last commit ($lastCommitSha) is not same as ($bumpCommitSha)."
echo "Exiting as amending to the commit may have side effects"
exit 1
fi
git config user.name "$(git log -1 --pretty=format:'%an')" || exit 1
git config user.email "$(git log -1 --pretty=format:'%ae')" || exit 1
git add 'dist/' || exit 1
git commit --amend --no-edit || exit 1
git push -f || exit 1
create-package:
needs: distribute
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: master # otherwise it defaults to the version tag missing bump commit
fetch-depth: 0 # fetch all history
- name: Checkout to bump commit
run: git checkout "$(git rev-list "${{ github.event.release.tag_name }}"..master | tail -1)"
- run: |
mkdir "../artifact"
cp -r . "../artifact"
rm -rf "../artifact/.git"
rm -rf "../artifact/.github"
rm -rf "../artifact/node_modules"
- uses: actions/upload-artifact@v1
with:
name: package
path: ../artifact
publish-package:
needs: create-package
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v1
with:
node-version: 14.x
registry-url: https://registry.npmjs.org/
- uses: actions/download-artifact@v1
with:
name: package
- run: cd package && npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}