-
Notifications
You must be signed in to change notification settings - Fork 36
172 lines (162 loc) · 7.5 KB
/
solidity.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
# TODO: Reusify and combine with the `check-lurk-compiles` action and/or make a reusable open-issue action
#
# This workflow runs autogenerated `solidity-verifier` compatibility tests on Arecibo PRs and notifies if compatibility is broken
# The workflow is intended to be a required status check only to make sure the Rust test & basic job steps work
# It is NOT intended to block breaking changes from merging, only to noisily surface them for review
#
# If the Rust template fails to generate the Solidity test or the job errors for another reason, the workflow fails immediately
# If the Solidity test fails on `pull_request`, it writes a PR comment to ensure the author/reviewer are notified
# If the Solidity test fails on `merge_group`, it opens an issue in `solidity-verifier` downstream that compatibility has been broken
# `merge_group` failures should only happen intentionally when breaking changes need to be merged in Arecibo
#
# Implementation note:
# `falnyr/replace-env-vars-action`, `micalevisk/last-issue-action` and `peter-evans/create-issue-from-file` replace
# equivalent functionality in `JasonEtco/create-an-issue`. We can't use the latter because it doesn't allow creating
# the issue in another repo. See https://github.com/JasonEtco/create-an-issue/issues/40
name: Test `solidity-verifier` compatibility
on:
merge_group:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches:
- dev
- 'feat/**'
- release-candidate
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
solidity-compat:
runs-on: buildjet-16vcpu-ubuntu-2204
steps:
- uses: actions/checkout@v4
with:
repository: argumentcomputer/ci-workflows
- uses: ./.github/actions/ci-env
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: taiki-e/install-action@nextest
- uses: Swatinem/rust-cache@v2
- name: Run Solidity test generator
run: |
# Runs all tests with the `test_solidity_compatibility` prefix, e.g. `test_solidity_compatibility_ipa`
cargo nextest run -E 'test(test_solidity_compatibility)' --release --run-ignored all --nocapture > test-output
working-directory: ${{ github.workspace }}
- name: Check out `solidity-verifier` for tests
uses: actions/checkout@v4
with:
repository: argumentcomputer/solidity-verifier
path: solidity-verifier
submodules: recursive
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Prep Solidity test files
run: |
# Get test names from output, extracting the final word after the final `_` in the test output
# E.g. `test provider::tests::ipa_pc::test::test_solidity_compatibility_ipa ... ok` returns `ipa`
# Expects all tests to live in the `provider` module, but can be changed/strengthened in future
TEST_NAMES=$(grep 'test provider::*' test-output | awk -F'[_(.*?)\b...]' '{ print $(NF-3) }')
echo "$TEST_NAMES"
# Print output of each test to `<test_name>.t.sol` file
awk -v names="$TEST_NAMES" 'BEGIN {
file_counter = 0
buffer = ""
# Convert test names to array
split(names, elements, " ")
for (i in elements) {
print "Element:", elements[i]
}
}
/running 1 test/ {
between = 1
buffer = ""
}
between {
buffer = buffer $0 ORS
}
/^test provider.*$/ {
between = 0
if (buffer != "") {
++file_counter
print buffer > elements[file_counter]".t.sol"
buffer = ""
}
}' test-output
# Clean up
shopt -s nullglob
for file in *.t.sol; do
cat $file | sed '1d' | head -n -2 > tmp.file && mv tmp.file solidity-verifier/test/$file
done
shopt -u nullglob
working-directory: ${{ github.workspace }}
- name: Run Forge tests
id: solidity-test
run: forge test -vvv
working-directory: ${{ github.workspace }}/solidity-verifier
continue-on-error: true
# Prepares env vars for use in a PR comment or issue in `solidity-verifier`
- name: Set env vars
if: steps.solidity-test.outcome != 'success'
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
COMMIT=$(echo ${{ github.event.pull_request.head.sha }} | cut -c -7)
PR_NUMBER=${{ github.event.pull_request.number }}
else
COMMIT=$(echo ${{ github.event.merge_group.head_sha }} | cut -c -7)
PR_NUMBER=$(echo ${{ github.event.merge_group.head_ref }} | sed -e 's/.*pr-\(.*\)-.*/\1/')
fi
GITHUB_URL=https://github.com/${{ github.repository }}
WORKFLOW_URL=$GITHUB_URL/actions/runs/${{ github.run_id }}
echo "WORKFLOW_FILE=$WORKFLOW_URL/workflow" | tee -a $GITHUB_ENV
echo "WORKFLOW_URL=$WORKFLOW_URL" | tee -a $GITHUB_ENV
echo "COMMIT_URL=$GITHUB_URL/commit/$COMMIT" | tee -a $GITHUB_ENV
echo "PR_URL=$GITHUB_URL/pull/$PR_NUMBER" | tee -a $GITHUB_ENV
echo "COMMIT=$COMMIT" | tee -a $GITHUB_ENV
# Comment on PR when test fails on `pull_request`
- name: Comment on failing run
if: steps.solidity-test.outcome != 'success' && github.event_name == 'pull_request'
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
`solidity-verifier` compatibility test failed :x:
${{ env.WORKFLOW_URL }}
# Substitutes env vars for their values in `SOLIDITY_COMPAT_ISSUE.md`
- uses: falnyr/replace-env-vars-action@master
if: steps.solidity-test.outcome != 'success' && (github.event_name != 'pull_request' || github.event.action == 'enqueued')
env:
WORKFLOW_URL: ${{ env.WORKFLOW_URL }}
WORKFLOW_FILE: ${{ env.WORKFLOW_FILE }}
COMMIT: ${{ env.COMMIT }}
COMMIT_URL: ${{ env.COMMIT_URL }}
PR_URL: ${{ env.PR_URL }}
with:
filename: .github/SOLIDITY_COMPAT_ISSUE.md
# Finds the last open issue matching given labels
- name: Find the last open compatibility issue
id: last-issue
if: steps.solidity-test.outcome != 'success' && (github.event_name != 'pull_request' || github.event.action == 'enqueued')
uses: micalevisk/last-issue-action@v2
with:
repository: argumentcomputer/solidity-verifier
state: open
# Find the last updated open issue that has these labels:
labels: |
compatibility
debt
automated issue
# Update existing issue in `solidity-verifier` or create new one
- uses: peter-evans/create-issue-from-file@v5
if: steps.solidity-test.outcome != 'success' && (github.event_name != 'pull_request' || github.event.action == 'enqueued')
with:
token: ${{ secrets.REPO_TOKEN }}
repository: argumentcomputer/solidity-verifier
issue-number: ${{ steps.last-issue.outputs.issue-number }}
title: ":rotating_light: Arecibo compatibility is broken"
content-filepath: .github/SOLIDITY_COMPAT_ISSUE.md
labels: |
compatibility
debt
automated issue