-
Notifications
You must be signed in to change notification settings - Fork 37
176 lines (153 loc) · 7.53 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
# 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: ${{ startsWith(github.head_ref, 'release--') }}
IS_FEATURE_BRANCH_PR: ${{ !startsWith(github.head_ref, 'release--') }}
jobs:
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
- id: determine-should-run-tests
uses: ./.github/actions/should_release
get-test-infos:
name: Get test infos
needs: determine-should-run-tests
if: ${{ needs.determine-should-run-tests.outputs.should-run-tests == 'true' }}
runs-on: ubuntu-latest
outputs:
test-infos: ${{ steps.get-test-infos.outputs.test-infos }}
steps:
- uses: actions/checkout@v4
- name: Get test infos
id: get-test-infos
uses: ./.github/actions/get_test_infos
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
') || '' }}
run-test:
name: '${{matrix.tests.name}} | ${{matrix.tests.displayPath}} | ${{matrix.azle_source}}'
needs:
- determine-should-run-tests
- get-test-infos
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: ${{ startsWith(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-test-infos.outputs.test-infos) }}
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 without artificial delay
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
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--') }}
IS_RELEASE_BRANCH_PR_BEFORE_MERGE_TO_MAIN=${{ env.IS_RELEASE_BRANCH_PR == 'true' && env.IS_MAIN_BRANCH == 'false' }}
RUNS=5
if $IS_MERGE_TO_MAIN_FROM_RELEASE; then
RUNS=100
fi
if $IS_RELEASE_BRANCH_PR_BEFORE_MERGE_TO_MAIN; then
RUNS=10
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