forked from chevdor/srtool-actions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
209 lines (170 loc) · 6.84 KB
/
action.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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
name: "Srtool"
description: "Build WASM Runtime with SRTOOL"
author: chevdor
branding:
icon: "package"
color: "blue"
inputs:
chain:
description: >
Name of the chain, ie. tidechain
required: true
package:
description: >
Runtime package to build, ie. tidechain-runtime.
If your runtime follows this pattern, you don't have and should not provide this input.
If not provided, it will be set to <chain>-runtime
required: false
image:
description: >
You can use an alternate image, use with caution!
required: true
default: "tidelabs/srtool"
tag:
description: >
Tag of the srtool image to use. Omit to use the latest (recommended)
required: false
workdir:
description: >
Path of the project, this is where your main Cargo.toml is located. This is relative to $GITHUB_WORKSPACE.
required: true
runtime_dir:
description: >
Location of the runtime in your repo. The default is 'runtime/<chain_name>'
required: false
outputs:
json:
description: >
The full json output of srtool. If you need more information than this action provides by default,
you can use this json output and extract some content using 'jq'.
value: ${{ steps.build.outputs.json }}
proposal_hash:
description: The proposal hash as it will show on-chain
value: ${{ steps.build.outputs.proposal_hash }}
version:
description: The version of srtool
value: ${{ steps.build.outputs.version }}
info:
description: Some information from srtool about the current project
value: ${{ steps.build.outputs.info }}
ipfs:
description: ipfs hash
value: ${{ steps.build.outputs.ipfs }}
wasm:
description: Path of the produced compact runtime
value: ${{ steps.build.outputs.wasm }}
wasm_compressed:
description: Path of the produced compressed runtime
value: ${{ steps.build.outputs.wasm_compressed }}
runs:
using: "composite"
steps:
- id: check_latest_srtool
name: Check the version of the latest srtool
shell: bash
run: |
RUSTC_VERSION_URL=https://raw.githubusercontent.com/tidelabs/srtool/tidechain/RUSTC_VERSION
echo Fetching RUSTC_VERSION from $RUSTC_VERSION_URL
RUSTC_VERSION=`curl -s $RUSTC_VERSION_URL`
SRTOOL_VERSION_URL=https://raw.githubusercontent.com/tidelabs/srtool/tidechain/VERSION
echo Fetching SRTOOL_VERSION from $SRTOOL_VERSION_URL
SRTOOL_VERSION=`curl -s $SRTOOL_VERSION_URL`
echo "RUSTC_VERSION=$RUSTC_VERSION" >> $GITHUB_ENV
echo "SRTOOL_VERSION=$SRTOOL_VERSION" >> $GITHUB_ENV
echo "SRTOOL_LATEST=$RUSTC_VERSION" >> $GITHUB_ENV
- id: env_setup
name: Setting Env
shell: bash
run: |
echo ::group::Debug
echo "RUSTC_VERSION=$RUSTC_VERSION"
echo "SRTOOL_VERSION=$SRTOOL_VERSION"
echo "SRTOOL_LATEST=$RUSTC_VERSION"
echo ::endgroup
echo ::group::Environment setup
SRTOOL_TAG=${{ inputs.tag || env.SRTOOL_LATEST }}
echo "SRTOOL_TAG=$SRTOOL_TAG" >> $GITHUB_ENV
echo "SRTOOL_IMAGE=${{ inputs.image }}:$SRTOOL_TAG" >> $GITHUB_ENV
echo "WORKDIR=${{ inputs.workdir || github.workspace }}" >> $GITHUB_ENV
RUNTIME_DIR=${{ inputs.runtime_dir}}
RUNTIME_DIR=${RUNTIME_DIR:-'runtime/'${{ inputs.chain}}}
echo "RUNTIME_DIR=$RUNTIME_DIR" >> $GITHUB_ENV
PACKAGE=${{ inputs.package }}
PACKAGE=${PACKAGE:-${{ inputs.chain }}'-runtime'}
echo "PACKAGE=$PACKAGE" >> $GITHUB_ENV
echo "BUILD_OPTS=${{ env.BUILD_OPTS }}" >> $GITHUB_ENV
PARACHAIN_PALLET_ID=${{ env.PARACHAIN_PALLET_ID }}
PARACHAIN_PALLET_ID=${PARACHAIN_PALLET_ID:-0x01}
AUTHORIZE_UPGRADE_PREFIX=${{ env.AUTHORIZE_UPGRADE_PREFIX }}
AUTHORIZE_UPGRADE_PREFIX=${AUTHORIZE_UPGRADE_PREFIX:-0x03}
echo "PARACHAIN_PALLET_ID=$PARACHAIN_PALLET_ID" >> $GITHUB_ENV
echo "AUTHORIZE_UPGRADE_PREFIX=$AUTHORIZE_UPGRADE_PREFIX" >> $GITHUB_ENV
echo ::endgroup
- id: env_check
name: Checking Env
shell: bash
run: |
echo ::group::Environment check
echo ℹ️ SRTOOL_LATEST: ${{ env.SRTOOL_LATEST }}
echo ℹ️ image: ${{ env.SRTOOL_IMAGE }}
echo ℹ️ chain: ${{ inputs.chain }}
echo ℹ️ package: ${{ env.PACKAGE }}
echo ℹ️ workdir: ${{ env.WORKDIR }}
echo ℹ️ runtime_dir: ${{ env.RUNTIME_DIR }}
echo ℹ️ build_opts: ${{ env.BUILD_OPTS }}
echo ℹ️ parachain_pallet_id: ${{ env.PARACHAIN_PALLET_ID }}
echo ℹ️ authorize_upgrade_prefix: ${{ env.AUTHORIZE_UPGRADE_PREFIX }}
echo ℹ️ .git folder: `ls -ald ${{ env.WORKDIR }}/.git`
echo ℹ️ Cargo.toml: `ls -al ${{ env.WORKDIR }}/Cargo.toml`
echo ::endgroup
- id: pulling_srtool
name: Build ${{ env.PACKAGE }} using ${{ env.SRTOOL_IMAGE }}
shell: bash
run: |
echo ::group::Pulling the srtool docker image: ${{ env.SRTOOL_IMAGE }}
docker pull ${{ env.SRTOOL_IMAGE }}
echo ::endgroup
- id: version
shell: bash
run: |
echo ::group::Srtool version
CMD="docker run -i --rm -v ${{ env.WORKDIR }}:/build ${{ env.SRTOOL_IMAGE }} version -cM"
JSON=`$CMD`
echo $JSON | jq .
echo "version=$JSON" >> $GITHUB_OUTPUT
echo ::endgroup
- id: info
shell: bash
run: |
echo ::group::srtool info
CMD="docker run -i --rm -v ${{ env.WORKDIR }}:/build ${{ env.SRTOOL_IMAGE }} info -cM"
JSON=`$CMD`
echo $JSON | jq .
echo "info=$JSON" >> $GITHUB_OUTPUT
echo ::endgroup
- id: build
name: Build ${{ env.PACKAGE }} using ${{ env.SRTOOL_IMAGE }}
shell: bash
run: |
echo ::group::Srtool build of chain ${{ inputs.chain }}
CMD="docker run -i --rm -e PACKAGE=${{ env.PACKAGE }} -e RUNTIME_DIR=${{ env.RUNTIME_DIR }} -e BUILD_OPTS -e PARACHAIN_PALLET_ID -e AUTHORIZE_UPGRADE_PREFIX -v ${{ env.WORKDIR }}:/build ${{ env.SRTOOL_IMAGE }} build --app --json -cM"
echo ::debug::build::docker_run $CMD
# here we keep streaming the progress and fetch the last line for the json result
stdbuf -oL $CMD | {
while IFS= read -r line
do
echo ║ $line
JSON="$line"
done
echo "json=$JSON" >> $GITHUB_OUTPUT
echo $JSON | jq .
PROP=`echo $JSON | jq -r .runtimes.compact.prop`
echo "proposal_hash=$PROP" >> $GITHUB_OUTPUT
WASM=`echo $JSON | jq -r .runtimes.compact.wasm`
echo "wasm=$WASM" >> $GITHUB_OUTPUT
Z_WASM=`echo $JSON | jq -r .runtimes.compressed.wasm`
echo "wasm_compressed=$Z_WASM" >> $GITHUB_OUTPUT
IPFS=`echo $JSON | jq -r .runtimes.compact.ipfs`
echo "ipfs=$IPFS" >> $GITHUB_OUTPUT
}
echo ::endgroup