-
Notifications
You must be signed in to change notification settings - Fork 59
152 lines (129 loc) · 4.54 KB
/
release-plz.yml
File metadata and controls
152 lines (129 loc) · 4.54 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: Release-plz PR
permissions:
pull-requests: write
contents: write
on:
push:
branches:
- main
jobs:
release-plz:
name: Release-plz
runs-on: ubuntu-latest
outputs:
pr: ${{ steps.release-plz.outputs.pr }}
prs_created: ${{ steps.release-plz.outputs.prs_created }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.RELEASE_PLZ_TOKEN }}
- name: Setup toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Run release-plz
uses: MarcoIeni/release-plz-action@v0.5
id: release-plz
with:
command: release-pr
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_PLZ_TOKEN }}
release-plz-pr-npm-update:
name: Update release PR for npm
runs-on: ubuntu-latest
needs:
- release-plz
if: success() && needs.release-plz.outputs.prs_created == 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.RELEASE_PLZ_TOKEN }}
- name: Setup toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: wasm32-unknown-unknown
# this disables default behavior of `setup-rust-toolchain` to put `-D warnings` which overwrites `.cargo/config.toml`
rustflags: ""
- name: Install dependencies
uses: taiki-e/install-action@v2
with:
tool: wasm-pack@0.13.1
- name: Bump lumina-node npm version
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_PLZ_TOKEN }}
run: |
set -xeuo pipefail
pr_branch_name="${{ fromJSON(needs.release-plz.outputs.pr).head_branch }}"
# switch to the branch created by release-plz
git fetch
git checkout "$pr_branch_name"
node_wasm_version="$(cargo pkgid --manifest-path=node-wasm/Cargo.toml | cut -d@ -f 2)"
cd node-wasm/js
# Update lumina-node version
if ! npm version $node_wasm_version >/dev/null; then
echo "Version up to date"
exit
fi
wasm-pack build ..
# Update lockfile with new node-wasm version
npm install --save ../pkg
npm clean-install
# Update the types definition for lumina-node
npm run tsc
# Update the readme for lumina-node
npm run update-readme
# push a commit to release-plz's pr
# prepare graphql query
branch_sha="$(git rev-parse "$pr_branch_name")"
package_json="$(base64 --wrap 0 package.json)"
package_lock_json="$(base64 --wrap 0 package-lock.json)"
readme="$(base64 --wrap 0 README.md)"
types_definitions="$(base64 --wrap 0 index.d.ts)"
query='{"query": "mutation {
createCommitOnBranch(input: {
branch: {
repositoryNameWithOwner: \"celestiaorg/lumina\",
branchName: \"'"$pr_branch_name"'\"
},
message: {
headline: \"update lumina-node npm package\"
},
expectedHeadOid: \"'"$branch_sha"'\",
fileChanges: {
additions: [
{
path: \"node-wasm/js/package.json\",
contents: \"'"$package_json"'\"
},
{
path: \"node-wasm/js/package-lock.json\",
contents: \"'"$package_lock_json"'\"
},
{
path: \"node-wasm/js/README.md\",
contents: \"'"$readme"'\"
},
{
path: \"node-wasm/js/index.d.ts\",
contents: \"'"$types_definitions"'\"
}
]
}
})
{ commit { commitUrl } }
}"}'
# create new commit with changes
result=$(echo "$query" | tr -d '\n' |
curl -sS https://api.github.com/graphql \
-H "Accept: application/vnd.github+json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
--data @-)
if echo "$result" | jq -e '.errors | length != 0' >/dev/null; then
echo "Commit failed: $(echo "$result" | jq '.errors')" >&2
exit 1
else
echo "Version updated: ${node_wasm_version}"
fi