Skip to content

Quick tests

Quick tests #4812

Workflow file for this run

# 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 azle-tests matrix spins up one job per combination of example directory and code source (repo or npm).
# The check-azle-tests-success job is designed to ensure that all jobs spun up from the matrix in the azle-tests have succeeded
name: Azle Tests
on:
push:
branches:
- main
pull_request: # Runs on pull requests to any branch
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
- id: get_all_tests
name: generateTests
run: echo "::set-output name=all_tests::$(./scripts/test.sh | base64 -d)"
determine-should-run-tests:
name: Determine Should Run Tests
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")
if [[ "${{ contains(github.head_ref, 'release--') }}" == "true" && "$COMMIT_MESSAGE" != "azle-bot automated release $RELEASE_VERSION" ]]
then
echo "::set-output name=should_run_tests::false"
else
echo "::set-output name=should_run_tests::true"
fi
release-candidate-deploy:
name: Deploy Release candidate for release branches
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 }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ contains(github.head_ref, 'release--') && 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 }}
- if: contains(github.head_ref, 'release--')
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--')
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: ${{ !needs.determine-should-run-tests.outputs.should_run_tests }}
run: ./publish-github-action.sh $RELEASE_VERSION ${{ toJSON(needs.generate-tests.outputs.all_tests) }}
azle-tests:
name: ${{matrix.tests.name}} / ${{matrix.tests.type}} / ${{matrix.tests.syntax}} / ${{matrix.tests.api}} / ${{matrix.azle_source}}
needs:
- determine-should-run-tests
- generate-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:
# 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-azle-tests-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: ${{ needs.determine-should-run-tests.outputs.should_run_tests }}
uses: actions/checkout@v4
- if: ${{ needs.determine-should-run-tests.outputs.should_run_tests }}
uses: actions/setup-node@v4
with:
node-version: 20
- if: ${{ needs.determine-should-run-tests.outputs.should_run_tests }}
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
- if: ${{ needs.determine-should-run-tests.outputs.should_run_tests && matrix.os == 'macos-latest' }}
shell: bash -l {0}
# The DNS server stuff is because of this: https://github.com/actions/runner-images/issues/6383
run: |
sudo networksetup -setdnsservers Ethernet 9.9.9.9
- if: ${{ needs.determine-should-run-tests.outputs.should_run_tests }}
shell: bash -l {0} # TODO figure out why this is here and comment about it
run: npm install
- if: ${{ needs.determine-should-run-tests.outputs.should_run_tests && matrix.azle_source == 'repo' }}
shell: bash -l {0}
run: npm link
- if: ${{ needs.determine-should-run-tests.outputs.should_run_tests }}
shell: bash -l {0}
run: npm run lint
- if: ${{ needs.determine-should-run-tests.outputs.should_run_tests }}
shell: bash -l {0}
working-directory: ${{ matrix.tests.path }}
run: npm install
- if: ${{ needs.determine-should-run-tests.outputs.should_run_tests && matrix.azle_source == 'repo' }}
shell: bash -l {0}
working-directory: ${{ matrix.tests.path }}
run: npm link azle
- if: ${{ needs.determine-should-run-tests.outputs.should_run_tests }}
working-directory: ${{ matrix.tests.path }}
run: npx azle install-dfx-extension
- if: ${{ needs.determine-should-run-tests.outputs.should_run_tests }}
working-directory: ${{ matrix.tests.path }}
run: dfx start --clean --background --host 127.0.0.1:8000
- if: ${{ needs.determine-should-run-tests.outputs.should_run_tests && !contains(github.head_ref, 'release--') && !(github.ref == 'refs/heads/main' && contains(github.event.head_commit.message, 'Merge pull request') && contains(github.event.head_commit.message, 'demergent-labs/release--')) }}
shell: bash -l {0}
working-directory: ${{ matrix.tests.path }}
run: AZLE_PROPTEST_NUM_RUNS=5 AZLE_PROPTEST_VERBOSE=true npm test
- if: ${{ needs.determine-should-run-tests.outputs.should_run_tests && contains(github.head_ref, 'release--') && !(github.ref == 'refs/heads/main' && contains(github.event.head_commit.message, 'Merge pull request') && contains(github.event.head_commit.message, 'demergent-labs/release--')) }}
shell: bash -l {0}
working-directory: ${{ matrix.tests.path }}
run: AZLE_PROPTEST_NUM_RUNS=10 AZLE_PROPTEST_VERBOSE=true npm test
- if: ${{ needs.determine-should-run-tests.outputs.should_run_tests && (github.ref == 'refs/heads/main' && contains(github.event.head_commit.message, 'Merge pull request') && contains(github.event.head_commit.message, 'demergent-labs/release--')) }}
shell: bash -l {0}
working-directory: ${{ matrix.tests.path }}
run: AZLE_PROPTEST_NUM_RUNS=100 AZLE_PROPTEST_VERBOSE=true npm test
check-azle-tests-success:
needs: azle-tests
runs-on: ubuntu-latest
if: success()
steps:
- run: exit 0
check-azle-tests-failure:
needs: azle-tests
runs-on: ubuntu-latest
if: failure()
steps:
- run: exit 1