Skip to content

Commit 2c39942

Browse files
authored
Add metadata and spec version CI checks (#681)
# Goal The goal of this PR is to add metadata check with the following rules 1. The freshly built metadata on PR branch will be compared against the latest metadata from the main branch. 1. Assigns `metadata-mismatch` label if metadata doesn't match between 2 binaries 1. Removes `metadata-mismatch` label if metadata matches between 2 binaries and the label exists 1. Fail CI if encoded metadata is different and the `spec_version` value has not been incremented. Part of #624
1 parent 9e000ff commit 2c39942

File tree

4 files changed

+119
-93
lines changed

4 files changed

+119
-93
lines changed

.github/workflows/merge-pr.yml

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -116,62 +116,3 @@ jobs:
116116
with:
117117
fail_ci_if_error: false # optional (default = false)
118118
verbose: true # optional (default = false)
119-
120-
save-binary-and-encoded-metadata:
121-
name: Save Binary and Encoded Metadata
122-
runs-on: [self-hosted, Linux, X64]
123-
env:
124-
NETWORK: mainnet
125-
steps:
126-
- name: Set Env Vars
127-
run: |
128-
echo "HOME=/root" >> $GITHUB_ENV
129-
echo "BIN_DIR=target/$BUILD_PROFILE" >> $GITHUB_ENV
130-
echo "BUILT_BIN_FILENAME=frequency" >> $GITHUB_ENV
131-
export SAVED_BIN_FILENAME=frequency-${{env.NETWORK}}-${{github.ref_name}}.amd64; echo "SAVED_BIN_FILENAME=$SAVED_BIN_FILENAME" >> $GITHUB_ENV
132-
echo "SAVED_METADATA_FILENAME=$SAVED_BIN_FILENAME.encoded-metadata.txt" >> $GITHUB_ENV
133-
- name: Check Out Repo
134-
uses: actions/checkout@v3
135-
# # XXX Keep this step as it lets us skip full binary builds during development/testing
136-
# - name: Cache Binary for Testing
137-
# id: cache-binary
138-
# uses: actions/cache@v3
139-
# with:
140-
# path: ${{env.BIN_DIR}}/${{env.BUILT_BIN_FILENAME}}
141-
# key: ${{runner.os}}-${{env.NETWORK}}-${{github.ref_name}}
142-
- name: Save/Restore Dependencies from Cache
143-
if: steps.cache-binary.outputs.cache-hit != 'true'
144-
uses: Swatinem/rust-cache@v2
145-
with:
146-
shared-key: ${{env.RUST_TOOLCHAIN}}
147-
- name: Install Rust Toolchain
148-
if: steps.cache-binary.outputs.cache-hit != 'true'
149-
uses: actions-rs/toolchain@v1
150-
with:
151-
default: true
152-
profile: minimal
153-
target: wasm32-unknown-unknown
154-
toolchain: stable
155-
- name: Compile Mainnet Binary
156-
if: steps.cache-binary.outputs.cache-hit != 'true'
157-
run: |
158-
CARGO_INCREMENTAL=0 RUSTFLAGS="-D warnings" cargo build --locked --release \
159-
--features frequency
160-
- name: Rename Binary
161-
working-directory: ${{env.BIN_DIR}}
162-
run: |
163-
ls -la
164-
cp -p ${{env.BUILT_BIN_FILENAME}} ${{env.SAVED_BIN_FILENAME}}
165-
- name: Extract Encoded Metadata
166-
working-directory: ${{env.BIN_DIR}}
167-
run: |
168-
./${{env.BUILT_BIN_FILENAME}} export-metadata metadata.json
169-
cat metadata.json | jq -r .result > ${{env.SAVED_METADATA_FILENAME}}
170-
- name: Upload Binary with Metadata
171-
uses: actions/upload-artifact@v3
172-
with:
173-
if-no-files-found: error
174-
name: binary-with-encoded-metadata-latest-main
175-
path: |
176-
${{env.BIN_DIR}}/${{env.SAVED_BIN_FILENAME}}
177-
${{env.BIN_DIR}}/${{env.SAVED_METADATA_FILENAME}}

.github/workflows/verify-pr-commit.yml

Lines changed: 116 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ on:
99
env:
1010
BUILD_PROFILE: release
1111
RUST_TOOLCHAIN: nightly-2022-09-22 # Update this when updating the Rust toolchain
12-
1312
jobs:
1413
changes:
1514
name: Determine Changed Files
@@ -43,28 +42,39 @@ jobs:
4342
- '**/Cargo.toml'
4443
- '**/Cargo.lock'
4544
46-
build-binary:
45+
build-binaries:
4746
needs: changes
4847
if: needs.changes.outputs.build-binary == 'true'
49-
name: Compile Frequency Project
48+
name: Build Binary on ${{matrix.branch_name}} Branch
49+
strategy:
50+
matrix:
51+
git_branch: ["${{github.head_ref}}", main]
52+
include:
53+
- git_branch: ${{github.head_ref}}
54+
branch_name: PR
55+
- git_branch: main
56+
branch_name: Main
5057
runs-on: [self-hosted, Linux, X64]
5158
env:
5259
NETWORK: mainnet
5360
steps:
5461
- name: Set Env Vars
5562
run: |
5663
echo "BIN_DIR=target/$BUILD_PROFILE" >> $GITHUB_ENV
57-
echo "BUILT_BIN_FILENAME=frequency" >> $GITHUB_ENV
64+
export BUILT_BIN_FILENAME=frequency; echo "BUILT_BIN_FILENAME=$BUILT_BIN_FILENAME" >> $GITHUB_ENV
65+
echo "REF_BIN_FILENAME=$BUILT_BIN_FILENAME-ref" >> $GITHUB_ENV
5866
echo "HOME=/root" >> $GITHUB_ENV
5967
- name: Check Out Repo
6068
uses: actions/checkout@v3
69+
with:
70+
ref: ${{matrix.git_branch}}
6171
# # XXX Keep this step as it lets us skip full binary builds during development/testing
6272
# - name: Cache Binary for Testing
6373
# id: cache-binary
6474
# uses: actions/cache@v3
6575
# with:
6676
# path: ${{env.BIN_DIR}}/${{env.BUILT_BIN_FILENAME}}
67-
# key: ${{runner.os}}-${{env.NETWORK}}-${{github.ref_name}}
77+
# key: ${{runner.os}}-${{env.NETWORK}}-${{github.head_ref}}
6878
- name: Install Rust Toolchain
6979
if: steps.cache-binary.outputs.cache-hit != 'true'
7080
uses: actions-rs/toolchain@v1
@@ -88,15 +98,15 @@ jobs:
8898
run: |
8999
file ${{env.BUILT_BIN_FILENAME}} && \
90100
./${{env.BUILT_BIN_FILENAME}} --version
91-
- name: Archive Artifact
92-
run: |
93-
tar -cvf frequency-binary-${{env.NETWORK}}-${{github.sha}}.amd64.tar \
94-
${{env.BIN_DIR}}/${{env.BUILT_BIN_FILENAME}}
101+
- name: Rename Reference Binary
102+
if: matrix.git_branch == 'main'
103+
working-directory: ${{env.BIN_DIR}}
104+
run: mv ${{env.BUILT_BIN_FILENAME}} ${{env.REF_BIN_FILENAME}}
95105
- name: Upload Artifact
96106
uses: actions/upload-artifact@v3
97107
with:
98108
name: artifacts-${{github.run_id}}
99-
path: frequency-binary-${{env.NETWORK}}-${{github.sha}}.amd64.tar
109+
path: ${{env.BIN_DIR}}/${{env.BUILT_BIN_FILENAME}}*
100110
if-no-files-found: error
101111

102112
check-for-vulnerable-crates:
@@ -339,11 +349,13 @@ jobs:
339349
--root
340350
341351
verify-js-api-augment:
342-
needs:
343-
- build-binary
352+
needs: build-binaries
344353
name: Verify JS API Augment
345354
runs-on: ubuntu-20.04
346355
steps:
356+
- name: Set Env Vars
357+
run: |
358+
echo "BIN_DIR=target/$BUILD_PROFILE" >> $GITHUB_ENV
347359
- name: Check Out Repo
348360
uses: actions/checkout@v3
349361
- name: Set up NodeJs
@@ -358,17 +370,18 @@ jobs:
358370
- name: Lint
359371
run: npm run lint
360372
working-directory: js/api-augment
361-
- name: Download Binary Artifacts
362-
id: download
373+
- name: Download Binary
363374
uses: actions/download-artifact@v3
364375
with:
365376
name: artifacts-${{github.run_id}}
366-
path: .
367-
- name: Extract Binary
377+
path: ${{env.BIN_DIR}}
378+
- name: Set Binary Permissions
379+
working-directory: ${{env.BIN_DIR}}
368380
run: |
369-
tar -xvf frequency-binary-mainnet-${{github.sha}}.amd64.tar
381+
set -x
382+
chmod 755 frequency
370383
- name: Output Metadata
371-
run: target/${{env.BUILD_PROFILE}}/frequency export-metadata ./js/api-augment/metadata.json
384+
run: ${{env.BIN_DIR}}/frequency export-metadata ./js/api-augment/metadata.json
372385
- name: Build
373386
run: npm run build
374387
working-directory: js/api-augment
@@ -380,10 +393,13 @@ jobs:
380393
working-directory: js/api-augment/dist
381394

382395
verify-docker-images:
383-
needs: build-binary
396+
needs: build-binaries
384397
name: Verify Docker Images
385398
runs-on: ubuntu-20.04
386399
steps:
400+
- name: Set Env Vars
401+
run: |
402+
echo "BIN_DIR=target/$BUILD_PROFILE" >> $GITHUB_ENV
387403
- name: Check Out Repo
388404
uses: actions/checkout@v3
389405
- name: Install Rust Toolchain
@@ -396,16 +412,16 @@ jobs:
396412
uses: Swatinem/rust-cache@v2
397413
with:
398414
shared-key: ${{env.RUST_TOOLCHAIN}}
399-
- name: Download Binary Artifacts
400-
id: download
415+
- name: Download Binary
401416
uses: actions/download-artifact@v3
402417
with:
403418
name: artifacts-${{github.run_id}}
404-
path: .
405-
- name: Extract Binary
419+
path: ${{env.BIN_DIR}}
420+
- name: Set Binary Permissions
421+
working-directory: ${{env.BIN_DIR}}
406422
run: |
407-
ls -la
408-
tar -xvf frequency-binary-mainnet-${{github.sha}}.amd64.tar
423+
set -x
424+
chmod 755 frequency
409425
- name: Set up QEMU
410426
uses: docker/setup-qemu-action@v2
411427
with:
@@ -430,10 +446,13 @@ jobs:
430446
file: docker/${{env.IMAGE_NAME}}.dockerfile
431447

432448
execute-binary-checks:
433-
needs: build-binary
449+
needs: build-binaries
434450
name: Execute Binary Checks
435451
runs-on: ubuntu-20.04
436452
steps:
453+
- name: Set Env Vars
454+
run: |
455+
echo "BIN_DIR=target/$BUILD_PROFILE" >> $GITHUB_ENV
437456
- name: Check Out Repo
438457
uses: actions/checkout@v3
439458
- name: Install Rust Toolchain
@@ -442,16 +461,80 @@ jobs:
442461
default: true
443462
profile: minimal
444463
toolchain: stable
445-
- name: Download Binary Artifacts
446-
id: download
464+
- name: Download Binary
447465
uses: actions/download-artifact@v3
448466
with:
449467
name: artifacts-${{github.run_id}}
450-
path: .
451-
- name: Extract Binary
468+
path: ${{env.BIN_DIR}}
469+
- name: Set Binary Permissions
470+
working-directory: ${{env.BIN_DIR}}
452471
run: |
453-
tar -xvf frequency-binary-mainnet-${{github.sha}}.amd64.tar
472+
set -x
473+
chmod 755 frequency
454474
- name: Output Binary Version
475+
working-directory: ${{env.BIN_DIR}}
455476
run: |
456-
file ./target/${{env.BUILD_PROFILE}}/frequency && \
457-
./target/${{env.BUILD_PROFILE}}/frequency --version
477+
file ./frequency && ./frequency --version
478+
479+
check-metadata-and-spec-version:
480+
needs: build-binaries
481+
name: Check Metadata and Spec Version
482+
runs-on: ubuntu-20.04
483+
env:
484+
REF_TAG: latest # tag to obtain reference binary to test against
485+
NETWORK: mainnet
486+
GITHUB_PR_LABEL: metadata-mismatch
487+
steps:
488+
- name: Set Env Vars
489+
run: |
490+
echo "BIN_DIR=target/$BUILD_PROFILE" >> $GITHUB_ENV
491+
export TEST_BIN_FILENAME=frequency; echo "TEST_BIN_FILENAME=$TEST_BIN_FILENAME" >> $GITHUB_ENV
492+
echo "REF_BIN_FILENAME=$TEST_BIN_FILENAME-ref" >> $GITHUB_ENV
493+
- name: Check Out Repo
494+
uses: actions/checkout@v3
495+
with:
496+
fetch-depth: 0
497+
- name: Download Test Binary
498+
uses: actions/download-artifact@v3
499+
with:
500+
name: artifacts-${{github.run_id}}
501+
path: ${{env.BIN_DIR}}
502+
- name: Set Binary Permissions
503+
working-directory: ${{env.BIN_DIR}}
504+
run: |
505+
set -x
506+
chmod 755 $TEST_BIN_FILENAME
507+
chmod 755 $REF_BIN_FILENAME
508+
- name: Compare Metadata
509+
id: compare-metadata
510+
working-directory: ${{env.BIN_DIR}}
511+
run: |
512+
./$REF_BIN_FILENAME export-metadata metadata-ref.json
513+
metadata_ref=$(cat metadata-ref.json | jq -r .result)
514+
./$TEST_BIN_FILENAME export-metadata metadata.json
515+
metadata=$(cat metadata.json | jq -r .result)
516+
match=$([[ $metadata == $metadata_ref ]] && echo 'true' || echo 'false')
517+
echo "Metadata matches?: $match"
518+
echo "metadata_match=$match" >> $GITHUB_OUTPUT
519+
- name: Assign Metadata Mismatch Label
520+
if: steps.compare-metadata.outputs.metadata_match != 'true'
521+
uses: actions-ecosystem/action-add-labels@v1
522+
with:
523+
labels: ${{env.GITHUB_PR_LABEL}}
524+
- name: Check Spec Version
525+
if: steps.compare-metadata.outputs.metadata_match != 'true'
526+
working-directory: ${{env.BIN_DIR}}
527+
run: |
528+
set -x
529+
spec_version_ref=$(./$REF_BIN_FILENAME export-runtime-version | jq -r .specVersion)
530+
spec_version=$(./$TEST_BIN_FILENAME export-runtime-version | jq -r .specVersion)
531+
[[ $spec_version -gt $spec_version_ref ]] || \
532+
(echo "ERROR: When metadata is updated, the new spec version \($spec_version\) \
533+
must be greater than the latest version on main \($spec_version_ref\)" && exit 10)
534+
- name: Remove Metadata Mismatch Label
535+
if: |
536+
(steps.compare-metadata.outputs.metadata_match == 'true') &&
537+
contains(github.event.pull_request.labels.*.name, env.GITHUB_PR_LABEL)
538+
uses: actions-ecosystem/action-remove-labels@v1
539+
with:
540+
labels: ${{env.GITHUB_PR_LABEL}}

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
}
99
},
1010
"cSpell.ignoreWords": [
11-
"Swatinem"
11+
"Swatinem",
12+
"jacogr",
13+
"pkill"
1214
]
1315
}

runtime/624-delete-me.rs

Whitespace-only changes.

0 commit comments

Comments
 (0)