Update GitHub workflows #4900
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. | |
# TODO give every step a name | |
name: Tests | |
on: | |
push: | |
branches: | |
- main | |
pull_request: # Runs on pull requests to any branch | |
env: | |
IS_RELEASE_CANDIDATE: ${{ contains(github.head_ref, 'release--') }} | |
IS_FEATURE: ${{ !contains(github.head_ref, 'release--') }} | |
DFX_VERSION: 0.21.0 | |
NODE_VERSION: 20 | |
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 | |
uses: ./.github/actions/generate_tests | |
with: | |
directories: | | |
./examples | |
./tests | |
exclude_dirs: | | |
${{ env.IS_FEATURE == '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: | |
should_run_tests: ${{ steps.determine_should_run_tests.outputs.should_run_tests }} | |
steps: | |
- uses: actions/checkout@v4 | |
- id: determine_should_run_tests | |
# Determine if tests should run for this pr. If it's a manually submitted release candidate no tests will run. | |
run: | | |
BRANCH_NAME="${{ github.head_ref }}" | |
RELEASE_VERSION="${BRANCH_NAME:9}" | |
COMMIT_MESSAGE=$(git log -1 --pretty=format:"%s") | |
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 | |
run-test: | |
# 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. | |
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--') }} | |
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: ${{ needs.determine-should-run-tests.outputs.should_run_tests == 'true' && fromJSON(needs.generate-tests.outputs.all_tests) || fromJSON('["dummy"]') }} | |
steps: | |
- name: Report full path of test | |
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 Test Setup | |
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_RELEASE_CANDIDATE }} | |
working-directory: ${{ matrix.tests.path }} | |
run: dfx start --clean --background --host 127.0.0.1:8000 --artificial-delay 0 | |
- name: Start dfx with artifical delay | |
if: ${{ env.IS_RELEASE_CANDIDATE }} | |
working-directory: ${{ matrix.tests.path }} | |
run: dfx start --clean --background --host 127.0.0.1:8000 | |
- 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--' | |
IS_FEATURE_PR=true | |
IS_RELEASE_PR=false | |
IS_MERGE_TO_MAIN_FROM_RELEASE=false | |
# Check if it's a feature pull request | |
if [[ $BRANCH_NAME != *"$RELEASE_TAG"* && ${{ github.ref }} != "$MAIN_BRANCH" && !($COMMIT_MESSAGE == *"$RELEASE_PR_MERGE_MSG"* && $COMMIT_MESSAGE == *"$RELEASE_REPO_MSG"*) ]]; then | |
IS_FEATURE_PR=true | |
else | |
IS_FEATURE_PR=false | |
fi | |
# Check if it's a release candidate pull request | |
if [[ $BRANCH_NAME == *"$RELEASE_TAG"* && ${{ github.ref }} != "$MAIN_BRANCH" && !($COMMIT_MESSAGE == *"$RELEASE_PR_MERGE_MSG"* && $COMMIT_MESSAGE == *"$RELEASE_REPO_MSG"*) ]]; then | |
IS_RELEASE_PR=true | |
else | |
IS_RELEASE_PR=false | |
fi | |
# Check if it's a merge from a release candidate into main | |
if [[ ${{ github.ref }} == "$MAIN_BRANCH" && $COMMIT_MESSAGE == *"$RELEASE_PR_MERGE_MSG"* && $COMMIT_MESSAGE == *"$RELEASE_REPO_MSG"* ]]; then | |
IS_MERGE_TO_MAIN_FROM_RELEASE=true | |
else | |
IS_MERGE_TO_MAIN_FROM_RELEASE=false | |
fi | |
# Determine the number of runs based on the conditions | |
if [[ $IS_MERGE_TO_MAIN_FROM_RELEASE == true ]]; then | |
RUNS=100 | |
elif [[ $IS_RELEASE_PR == true ]]; 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-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 |