-
Notifications
You must be signed in to change notification settings - Fork 37
248 lines (226 loc) · 12.2 KB
/
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
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# TODO the next great simplification might be deploying multiple examples to one dfx replica instance: https://forum.dfinity.org/t/use-the-same-local-replica-for-multiple-projects/11900
# TODO this might allow us to avoid spinning up so many jobs in the matrix
# This GitHub Action flow works as follows:
# The tests are currently simple example-based integration tests.
# Each directory in the examples directory represents an example project and is intended to have tests that ensure the canisters contained in that example function properly.
# These tests are currently written in TypeScript and are intended to be run in a Node.js environment.
# This GitHub Action takes care of deploying to npm and GitHub.
# Tests can either run against the current code of Azle found in the repository, or the code deployed by the GitHub Action to npm.
# Feature branch pull requests (pull requests without release-- in the base branch name) will run all tests against the code found in the repository.
# Release branch pull requests (pull requests with release-- in the base branch name) will run all tests against the code found in the repository and the code deployed by the GitHub Action to npm.
# Pushes to main will run all tests against the code in the repository if the latest commit was not a merge of a release branch, and will run tests against the code in the repository and the code deployed by the GitHub Action to npm otherwise.
# The run-test matrix spins up one job per combination of example directory and code source (repo or npm).
# The check-run-test-success job is designed to ensure that all jobs spun up from the matrix in the run-test have succeeded
## TODO make variable for isRelease
## TODO make sure comments are throughout and not all at the top
name: Tests
on:
push:
branches:
- main
pull_request: # Runs on pull requests to any branch
env:
IS_RELEASE_CANDIDATE: ${{ contains(github.head_ref, 'release--') }}
jobs:
generate-tests:
name: Generate Tests
runs-on: ubuntu-latest
outputs:
all_tests: ${{ steps.get_all_tests.outputs.all_tests }}
steps:
- uses: actions/checkout@v4
- name: Generate Tests
id: get_all_tests
run: echo "all_tests=$(./.github/scripts/generate_tests.sh | base64 -d)" >> "$GITHUB_OUTPUT"
determine-should-run-tests:
name: Determine If Tests Should Run
runs-on: ubuntu-latest
outputs:
should_run_tests: ${{ steps.determine_should_run_tests.outputs.should_run_tests }}
steps:
- uses: actions/checkout@v4
- id: determine_should_run_tests
run: |
BRANCH_NAME="${{ github.head_ref }}"
RELEASE_VERSION="${BRANCH_NAME:9}"
COMMIT_MESSAGE=$(git log -1 --pretty=format:"%s")
IS_RELEASE_CANDIDATE="${{ contains(github.head_ref, 'release--') }}"
IS_AUTOMATED_RELEASE="false"
if [[ "$COMMIT_MESSAGE" == "azle-bot automated release $RELEASE_VERSION" ]]; then
IS_AUTOMATED_RELEASE="true"
fi
if [[ "${{env.IS_RELEASE_CANDIDATE}}" == "true" && "$IS_AUTOMATED_RELEASE" == "false" ]]; then
echo "should_run_tests=false" >> "$GITHUB_OUTPUT"
else
echo "should_run_tests=true" >> "$GITHUB_OUTPUT"
fi
- id: make_sure_im_not_crazy
name: Crazy Check
run: |
echo "Hello from crazy check"
if [[ "${{env.IS_RELEASE_CANDIDATE}}" == "true" && "$IS_AUTOMATED_RELEASE" == "false" ]]; then
echo "1 I'm not going to see this since I'm not doing a release"
else
echo "2 I'm going to see this since I'm not doing a release"
fi
if [[ "${{env.IS_RELEASE_CANDIDATE}}" == "false" && "$IS_AUTOMATED_RELEASE" == "false" ]]; then
echo "3 I'm going to see this since I'm not doing a release"
else
echo "4 I'm not going to see this since I'm not doing a release"
fi
if [[ "${{env.IS_RELEASE_CANDIDATE}}" == "false" ]]; then
echo "5 I'm going to see this since I'm not doing a release"
else
echo "6 I'm not going to see this since I'm not doing a release"
fi
echo "false"
echo "${{env.IS_RELEASE_CANDIDATE}}"
echo false
echo ${{env.IS_RELEASE_CANDIDATE}}
release-candidate-deploy:
name: Deploy Release Candidate for Release Branches
if: ${{ contains(github.head_ref, 'release--') }}
needs:
- generate-tests
- determine-should-run-tests
runs-on: ubuntu-latest
env:
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }} # All commits must be verified
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SHOULD_RUN_TEST: ${{ needs.determine-should-run-tests.outputs.should_run_tests }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref || github.ref }}
token: ${{ secrets.LASTMJS_GITHUB_TOKEN || github.token }}
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Install dfx
run: |
DFXVM_INIT_YES=true DFX_VERSION=0.21.0 sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)"
echo "$HOME/.local/share/dfx/bin" >> $GITHUB_PATH
# TODO we should use some Action-specific bot account
- if: contains(github.head_ref, 'release--')
name: Configure git for Publishing Release
run: |
git config --global user.name 'Jordan Last'
git config --global user.email '[email protected]'
git config --global commit.gpgsign true
echo -n "$GPG_SIGNING_KEY" | base64 --decode | gpg --import
git config --global user.signingkey C8B77BCBE16CD2B94B43F9C8757397B82D4ED7B0
- if: ${{ !env.SHOULD_RUN_TEST }}
name: Publish Release
run: ./.github/scripts/publish_github_action.sh $RELEASE_VERSION ${{ toJSON(needs.generate-tests.outputs.all_tests) }}
run-test:
name: '${{matrix.tests.name}} | ${{matrix.tests.type}} | ${{matrix.tests.syntax}} | ${{matrix.tests.api}} | ${{matrix.azle_source}}'
needs:
- determine-should-run-tests
- generate-tests
if: ${{ needs.determine-should-run-tests.outputs.should_run_tests }}
runs-on: ${{ matrix.os }}
env:
ETHEREUM_URL: ${{ secrets.ETHEREUM_URL }}
AZLE_IDENTITY_STORAGE_MODE: 'plaintext'
AZLE_END_TO_END_TEST_LINK_AZLE: ${{ matrix.azle_source == 'repo' }}
AZLE_TEST_RUN_ON_RELEASE: ${{ contains(github.head_ref, 'release--') }}
SHOULD_RUN_TEST: ${{ needs.determine-should-run-tests.outputs.should_run_tests }}
strategy:
fail-fast: false # We want to see which example tests succeed and which ones fail, we don't want one example test to cancel the rest
matrix:
# os: [macos-latest]
os: [ubuntu-latest]
include_npm:
# Only include npm in the matrix if you've pushed to main and the last commit was a merge of a release branch, or the base branch of the pull request is a release branch
- ${{ (github.ref == 'refs/heads/main' && contains(github.event.head_commit.message, 'Merge pull request') && contains(github.event.head_commit.message, 'demergent-labs/release--')) || contains(github.head_ref, 'release--') }}
azle_source:
- npm
- repo
exclude:
- include_npm: false
azle_source: npm
- include_npm: true
azle_source: repo
# If should_run_tests is false, we still want the steps of this job to execute so that check-run-test-success will run. We do this by creating an array with one dummy element
tests: ${{ needs.determine-should-run-tests.outputs.should_run_tests == 'true' && fromJSON(needs.generate-tests.outputs.all_tests) || fromJSON('["dummy"]') }}
steps:
- if: ${{env.SHOULD_RUN_TEST}}
name: Report full path of test
run: echo ${{matrix.tests.path}}
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- if: ${{ env.SHOULD_RUN_TEST }}
name: Run Pre-Test Azle Setup
run: |
# Install dfx
DFXVM_INIT_YES=true DFX_VERSION=0.21.0 sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)"
echo "$HOME/.local/share/dfx/bin" >> $GITHUB_PATH
# MacOS-specific DNS configuration
if [[ "${{ matrix.os }}" == "macos-latest" ]]; then
sudo networksetup -setdnsservers Ethernet 9.9.9.9
fi
# Install dependencies
npm install
# Link azle if the source is repo
if [[ "${{ matrix.azle_source }}" == "repo" ]]; then
npm link
fi
# Run linting
npm run lint
shell: bash -l {0}
- if: ${{env.SHOULD_RUN_TEST}}
name: Run Pre-Test Test Setup
run: |
npm install
# Link azle in the test directory if the source is repo
if [[ "${{ matrix.azle_source }}" == "repo" ]]; then
npm link azle
fi
# Install the azle dfx extension
npx azle install-dfx-extension
working-directory: ${{ matrix.tests.path }}
shell: bash -l {0}
- if: ${{ env.SHOULD_RUN_TEST }}
name: Start dfx
working-directory: ${{ matrix.tests.path }}
run: dfx start --clean --background --host 127.0.0.1:8000
- if: ${{ env.SHOULD_RUN_TEST }}
name: Run Test
run: |
BRANCH_NAME="${{ github.head_ref }}"
MAIN_BRANCH='refs/heads/main'
COMMIT_MESSAGE="${{ github.event.head_commit.message }}"
RELEASE_TAG='release--'
RELEASE_PR_MERGE_MSG='Merge pull request'
RELEASE_REPO_MSG='demergent-labs/release--'
if [[ $BRANCH_NAME != *"$RELEASE_TAG"* && ${{ github.ref }} != "$MAIN_BRANCH" && !($COMMIT_MESSAGE == *"$RELEASE_PR_MERGE_MSG"* && $COMMIT_MESSAGE == *"$RELEASE_REPO_MSG"*) ]]; then
RUNS=5
elif [[ $BRANCH_NAME == *"$RELEASE_TAG"* && ${{ github.ref }} != "$MAIN_BRANCH" && !($COMMIT_MESSAGE == *"$RELEASE_PR_MERGE_MSG"* && $COMMIT_MESSAGE == *"$RELEASE_REPO_MSG"*) ]]; then
RUNS=10
elif [[ ${{ github.ref }} == "$MAIN_BRANCH" && $COMMIT_MESSAGE == *"$RELEASE_PR_MERGE_MSG"* && $COMMIT_MESSAGE == *"$RELEASE_REPO_MSG"* ]]; then
RUNS=100
else
RUNS=5
fi
AZLE_PROPTEST_NUM_RUNS=$RUNS AZLE_PROPTEST_VERBOSE=true npm test
shell: bash -l {0}
working-directory: ${{ matrix.tests.path }}
check-basic-integration-test-success:
name: Check Azle Tests Succeeded
needs: run-test
runs-on: ubuntu-latest
if: success()
steps:
- run: exit 0
check-basic-integration-test-failure:
name: Check Azle Tests Didn't Fail
needs: run-test
runs-on: ubuntu-latest
if: failure()
steps:
- run: exit 1