-
Notifications
You must be signed in to change notification settings - Fork 1
78 lines (69 loc) · 2.9 KB
/
npm.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: NPM
on:
push:
branches:
- master
paths:
- "solidity/contracts/**"
- "solidity/package.json"
- "solidity/package-lock.json"
jobs:
publish-contracts:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: "12.x"
registry-url: "https://registry.npmjs.org"
scope: "@keep-network"
- name: Cache node modules
uses: actions/cache@v1
env:
cache-name: cache-solidity-node-modules
with:
path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Resolve latest contracts
working-directory: ./solidity
run: npm update @keep-network/keep-core @keep-network/sortition-pools
- name: Bump up version
working-directory: ./solidity
run: |
name=$(jq --raw-output .name package.json)
version=$(jq --raw-output .version package.json)
preid=$(echo $version | sed -e s/^.*-\\\([^.]*\\\).*$/\\1/)
# Check resolved `preid`. Currently only `pre` value is supported,
# other types of releases are not handled by this job.
if [ "$preid" != pre ]; then
echo "Unsupported preid. Resolved info:"
echo "$name@$version ; preid $preid"
exit 1
fi
# Find the latest published package version matching this preid.
# Note that in jq, we wrap the result in an array and then flatten;
# this is because npm show json contains a single string if there
# is only one matching version, or an array if there are multiple,
# and we want to look at an array always.
latest_version=$(npm show -json "$name@^$version" version | jq --raw-output "[.] | flatten | .[-1]")
latest_version=${latest_version:-$version}
if [ -z $latest_version ]; then
echo "Latest version calculation failed. Resolved info:"
echo "$name@$version ; preid $preid"
exit 1
fi
# Update package.json with the latest published package version matching this
# preid to prepare for bumping.
echo $(jq -M ".version=\"${latest_version}\"" package.json) > package.json
# Bump without doing any git work. Versioning is a build-time action for us.
# Consider including commit id? Would be +<commit id>.
npm version prerelease --preid=$preid --no-git-tag-version
- name: Publish package
run: npm publish --access public
working-directory: ./solidity
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}