-
Notifications
You must be signed in to change notification settings - Fork 3
150 lines (140 loc) · 6.08 KB
/
check-and-test.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
name: Cargo check and test
on: [pull_request]
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
get-version:
name: Get version
runs-on: ubuntu-latest
outputs:
toolchain: ${{ steps.get_toolchain.outputs.TOOLCHAIN }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git fetch --tags
- run: pip3 install yq==2.13.0
- name: Get Build Version
id: get_version
run: ./scripts/check-version.sh
shell: bash
- name: Get Toolchain Version
id: get_toolchain
run: |
echo "TOOLCHAIN=$(cat rust-toolchain.toml | tomlq .toolchain.channel)" >> $GITHUB_OUTPUT
check-weights-have-changes:
name: Check Weights
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: check
id: check
run: |
URL="https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files"
files_changed_data=$(curl -s --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -X GET -G "$URL")
files_changed="$(echo $files_changed_data | jq -r '.[] | .filename')"
# Adding || true to avoid "Process exited with code 1" errors
pallet_dirs_changed="$(echo "${files_changed}" | xargs dirname | grep -v "pallets/traits/*" | grep -v "pallets/doas/*" | grep -v "pallets/transaction-payment-free/*" | grep -o "pallets/[^/]*" | sort | uniq || true)"
pallets_requiring_weights=()
for pallet_dir in ${pallet_dirs_changed}; do
weights="$(echo "${files_changed}" | grep -o "${pallet_dir}/src/weights.rs" || true)"
if [[ -z "$weights" ]]; then pallets_requiring_weights+=($(basename $pallet_dir)); fi
done
echo "pallets=${pallets_requiring_weights[*]}" >> $GITHUB_OUTPUT
- name: Find Comment
id: find
uses: peter-evans/find-comment@v2
if: steps.check.outputs.pallets != ''
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: This PR updates the following pallets
- name: Create comment
uses: peter-evans/create-or-update-comment@v3
if: ${{ steps.find.outputs.comment-id == '' && steps.find.outcome == 'success' }}
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
This PR updates the following pallets - they may also require updates to their extrinsic weights:
**${{ steps.check.outputs.pallets }}**
For the author and any reviewers:
- consider whether the changes could significantly affect the weight of any extrinsics
- consider whether benchmarks need updating to correctly cover weight variations over inputs
For a guide on running benchmarks to update weights see [calculating weights](https://github.com/digicatapult/dscp-node#calculating-weights)
check:
name: Check and test
runs-on: ubuntu-latest
needs: [get-version]
steps:
- uses: actions/checkout@v4
- name: Install toolchains
run: |
rustup toolchain install ${{ needs.get-version.outputs.toolchain }}
rustup target add wasm32-unknown-unknown --toolchain ${{ needs.get-version.outputs.toolchain }}
- name: install protobuf compiler
run: sudo apt-get install protobuf-compiler
- name: Install sccache
env:
TEMP: ${{ runner.temp }}
run: |
curl -L https://github.com/gruntwork-io/fetch/releases/download/v0.3.7/fetch_linux_amd64 --output $TEMP/fetch
chmod +x $TEMP/fetch
$TEMP/fetch --repo="https://github.com/mozilla/sccache" --tag="~>0.2.15" --release-asset="^sccache-v[0-9.]*-x86_64-unknown-linux-musl.tar.gz$" $TEMP
tar -xvf $TEMP/sccache-v*-x86_64-unknown-linux-musl.tar.gz -C $TEMP
mv $TEMP/sccache-v*-x86_64-unknown-linux-musl/sccache $TEMP/sccache
rm -rf $TEMP/sccache-v*-x86_64-unknown-linux-musl $TEMP/sccache-v*-x86_64-unknown-linux-musl.tar.gz $TEMP/fetch
chmod +x $TEMP/sccache
- name: Install rustfmt
run: rustup component add rustfmt
- name: Cache cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
${{ runner.os }}-cargo-registry-
- name: Cache cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
${{ runner.os }}-cargo-index-
- name: Cache sccache
uses: actions/cache@v3
with:
path: ${{ runner.temp }}/cache
key: ${{ runner.os }}-cargo-build-cache-debug-${{ hashFiles('**/Cargo.lock') }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-cargo-build-cache-debug-${{ hashFiles('**/Cargo.lock') }}
${{ runner.os }}-cargo-build-cache-debug-
- name: Cargo format
env:
RUSTC_WRAPPER: ${{ runner.temp }}/sccache
SCCACHE_DIR: ${{ runner.temp }}/cache
SCCACHE_CACHE_SIZE: "1G"
run: cargo fmt --check
- name: Cargo check
env:
RUSTC_WRAPPER: ${{ runner.temp }}/sccache
SCCACHE_DIR: ${{ runner.temp }}/cache
SCCACHE_CACHE_SIZE: "1G"
run: cargo check
- name: Cargo test
env:
RUSTC_WRAPPER: ${{ runner.temp }}/sccache
SCCACHE_DIR: ${{ runner.temp }}/cache
SCCACHE_CACHE_SIZE: "1G"
run: cargo test