-
Notifications
You must be signed in to change notification settings - Fork 37
269 lines (233 loc) · 11.3 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# This GitHub Action flow works as follows:
# Each directory in the examples and tests 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.
name: Tests
on:
push:
branches:
- main
pull_request: # Runs on pull requests to any branch
env:
DFX_VERSION: 0.22.0
NODE_VERSION: 20
IS_MAIN_BRANCH: ${{ github.ref == 'refs/heads/main' }}
IS_RELEASE_BRANCH_PR: ${{ contains(github.head_ref, 'release--') }}
IS_FEATURE_BRANCH_PR: ${{ !contains(github.head_ref, 'release--') }}
jobs:
see-vars:
name: See vars
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
echo "CI: $CI"
echo "ACTION: $GITHUB_ACTION"
echo "ACTION_PATH: $GITHUB_ACTION_PATH"
echo "ACTION_REPOSITORY: $GITHUB_ACTION_REPOSITORY"
echo "ACTIONS: $GITHUB_ACTIONS"
echo "ACTOR: $GITHUB_ACTOR"
echo "ACTOR_ID: $GITHUB_ACTOR_ID"
echo "API_URL: $GITHUB_API_URL"
echo "BASE_REF: $GITHUB_BASE_REF"
echo "ENV: $GITHUB_ENV"
echo "EVENT_NAME: $GITHUB_EVENT_NAME"
echo "EVENT_PATH: $GITHUB_EVENT_PATH"
echo "GRAPHQL_URL: $GITHUB_GRAPHQL_URL"
echo "HEAD_REF: $GITHUB_HEAD_REF"
echo "JOB: $GITHUB_JOB"
echo "OUTPUT: $GITHUB_OUTPUT"
echo "PATH: $GITHUB_PATH"
echo "REF: $GITHUB_REF"
echo "REF_NAME: $GITHUB_REF_NAME"
echo "REF_PROTECTED: $GITHUB_REF_PROTECTED"
echo "REF_TYPE: $GITHUB_REF_TYPE"
echo "REPOSITORY: $GITHUB_REPOSITORY"
echo "REPSOITORY ID: $GITHUB_REPOSITORY_ID"
echo "REPOSITORY_OWNER: $GITHUB_REPOSITORY_OWNER"
echo "REPSOSITRY_OWNDER_ID: $GITHUB_REPOSITORY_OWNER_ID"
echo "RETENTION_DAYS: $GITHUB_RETENTION_DAYS"
echo "RUN_ATTEMPT: $GITHUB_RUN_ATTEMPT"
echo "RUN_ID: $GITHUB_RUN_ID"
echo "RUN_NUMBER: $GITHUB_RUN_NUMBER"
echo "SERVER_URL: $GITHUB_SERVER_URL"
echo "SHA: $GITHUB_SHA"
echo "STEP_SUMMARY: $GITHUB_STEP_SUMMARY"
echo "TRIGGERING_ACTOR: $GITHUB_TRIGGERING_ACTOR"
echo "WORKFLOW: $GITHUB_WORKFLOW"
echo "WORKFLOW_REF: $GITHUB_WORKFLOW_REF"
echo "WORKFLOW_SHA: $GITHUB_WORKFLOW_SHA"
echo "WORKSPACE: $GITHUB_WORKSPACE"
echo "ARCH: $RUNNER_ARCH"
echo "DEBUG: $RUNNER_DEBUG"
echo "ENVIRONMENT: $RUNNER_ENVIRONMENT"
echo "NAME: $RUNNER_NAME"
echo "OS: $RUNNER_OS"
echo "TEMP: $RUNNER_TEMP"
echo "TOOL_CACHE: $RUNNER_TOOL_CACHE"
# Show the repository's remote URL
echo "Repository URL:"
git remote get-url origin
# Show the current branch name
echo -e "\nCurrent Branch:"
git branch --show-current
# Show the latest commit hash and message
echo -e "\nLatest Commit:"
git log -1 --pretty=format:"%h - %s"
# Show the date and author of the latest commit
echo -e "\nCommit Details:"
git log -1 --pretty=format:"Author: %an, Date: %ad"
# Show the last few commits
echo -e "\nLast 20 Commits:"
git log --oneline --graph -n 20
# Show the repository's status
echo -e "\nRepository Status:"
git status -s
# Show unpushed commits (if any)
echo -e "\nUnpushed Commits:"
git log @{u}..HEAD --oneline || echo "No unpushed commits"
# Show stashes (if any)
echo -e "\nGit Stashes:"
git stash list || echo "No stashes"
echo -e "\nDone!"
get-tests:
name: Get tests
runs-on: ubuntu-latest
outputs:
tests: ${{ steps.get_tests.outputs.tests }}
steps:
- uses: actions/checkout@v4
- name: Get tests
id: get_tests
uses: ./.github/actions/get_tests
with:
directories: |
./examples
./tests
exclude_dirs: |
${{ env.IS_FEATURE_BRANCH_PR == 'true' && format('
./examples/basic_bitcoin
./examples/bitcoin_psbt
./examples/ckbtc
./tests/end_to_end/http_server/ethers_base
./tests/end_to_end/http_server/http_outcall_fetch
./tests/end_to_end/http_server/ic_evm_rpc
./tests/property/candid_rpc/class_api/stable_b_tree_map
./tests/property/candid_rpc/functional_api/stable_b_tree_map
') || '' }}
determine-should-run-tests:
name: Determine if tests should run
runs-on: ubuntu-latest
outputs:
# If the branch should release then it shouldn't run tests.
should_run_tests: ${{ steps.determine_should_run_tests.outputs.should_release == 'false' }}
steps:
- uses: actions/checkout@v4
- name: Cool
run: echo $(git log -1 --pretty=format:"%s")
- name: Boy
run: echo ${{ github.event.head_commit.message }}
- name: Town
run: echo $(git log -1 --no-merges --pretty=format:"%s")
- name: List recent commits
run: git log --oneline -5
- id: determine_should_run_tests
uses: ./.github/actions/should_release
run-test:
name: '${{matrix.tests.name}} | ${{matrix.tests.type}} | ${{matrix.tests.syntax}} | ${{matrix.tests.api}} | ${{matrix.azle_source}}'
needs:
- determine-should-run-tests
- get-tests
if: ${{ needs.determine-should-run-tests.outputs.should_run_tests == 'true' }}
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--') }}
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: # spins up one job per combination of test and code source (repo or npm).
# 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: ${{ fromJSON(needs.get-tests.outputs.tests) }}
steps:
- name: Report full path of test
# Just in case the path isn't obvious from the name, this will remove ambiguity
run: echo ${{matrix.tests.path}}
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Run pre-test Azle setup
run: |
# Install dfx
DFXVM_INIT_YES=true DFX_VERSION=${{ env.DFX_VERSION }} 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
npm install
if [[ "${{ matrix.azle_source }}" == "repo" ]]; then
npm link
fi
npm run lint
shell: bash -l {0}
- name: Run pre-test setup for ${{ matrix.tests.name }}
run: |
npm install
if [[ "${{ matrix.azle_source }}" == "repo" ]]; then
npm link azle
fi
npx azle install-dfx-extension
working-directory: ${{ matrix.tests.path }}
shell: bash -l {0}
- name: Start dfx
if: ${{ env.IS_FEATURE_BRANCH_PR == 'true' }}
working-directory: ${{ matrix.tests.path }}
run: dfx start --clean --background --host 127.0.0.1:8000 --artificial-delay 0
- name: Start dfx with artifcial delay
if: ${{ env.IS_RELEASE_BRANCH_PR == 'true' }}
working-directory: ${{ matrix.tests.path }}
run: dfx start --clean --background --host 127.0.0.1:8000
- name: Run test
run: |
IS_MERGE_TO_MAIN_FROM_RELEASE=${{ env.IS_MAIN_BRANCH == 'true' && contains(github.event.head_commit.message, 'Merge pull request') && contains(github.event.head_commit.message, 'demergent-labs/release--') }}
if $IS_MERGE_TO_MAIN_FROM_RELEASE; then
RUNS=100
elif ${{ env.IS_RELEASE_BRANCH_PR == 'true' && env.IS_MAIN_BRANCH == 'false' }}; then
RUNS=10
else
RUNS=5
fi
AZLE_PROPTEST_NUM_RUNS=$RUNS AZLE_PROPTEST_VERBOSE=true npm test
shell: bash -l {0}
working-directory: ${{ matrix.tests.path }}
# These final jobs are designed to ensure that all jobs spun up from the matrix in the run-test have succeeded
check-test-success:
name: Check Azle tests succeeded
needs: run-test
runs-on: ubuntu-latest
if: success()
steps:
- run: exit 0
check-test-failure:
name: Check Azle tests didn't fail
needs: run-test
runs-on: ubuntu-latest
if: failure()
steps:
- run: exit 1