Skip to content

Commit

Permalink
Merge branch 'main' into responses_prop_test
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann authored Oct 22, 2024
2 parents b926b3c + 812223c commit 5d70454
Show file tree
Hide file tree
Showing 7 changed files with 322 additions and 157 deletions.
1 change: 0 additions & 1 deletion .github/actions/get_test_infos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ steps:
- id: get-test-infos
uses: ./.github/actions/get_test_infos
with:
node-version: '20.x'
directories: './tests ./examples'
exclude-dirs: 'tests/exclude_this_directory examples/exclude_this exclude_all_with_this_dir_in_path'

Expand Down
16 changes: 8 additions & 8 deletions .github/actions/get_test_infos/action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Get test infos
name: 'Get test infos'
description:
'Gets a list of test info objects for each npm project with an npm test script
The shape of the object is
Expand All @@ -9,26 +9,26 @@ description:
displayPath: string // An abbreviated version of the path for display purposes only
}'
inputs:
node-version:
description: The version of Node.js to use
required: true
directories:
description: List of directories to search for npm projects with an npm test script
description: 'List of directories to search for npm projects with an npm test script'
required: true
exclude-dirs:
description: List of directories to exclude from the search
description: 'List of directories to exclude from the search'
required: false
default: ''
outputs:
test-infos:
description: All of the test info objects found by this action
description: 'All of the test info objects found by this action'
value: ${{ steps.get-test-infos.outputs.test-infos }}
runs:
using: composite
steps:
- id: get-node-version
uses: ./.github/actions/get_node_version

- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
node-version: ${{ steps.get-node-version.outputs.node-version }}

- name: Get test infos
id: get-test-infos
Expand Down
30 changes: 30 additions & 0 deletions .github/actions/set_run_conditions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Prerequisite

This action assumes that the repository has already been checked out before
calling the action, typically using `actions/checkout@v4`. If you have not
checked out the code in a previous step, make sure to do so to avoid errors.

This action does **not** perform a checkout action itself because it would be
redundant. This action is part of the repository's codebase, so if the code
hasn't already been checked out, the action itself wouldn't even be available to
call. Additionally, rerunning a checkout at this stage could potentially
overwrite any earlier `actions/checkout` step with different parameters, such as
checking out a specific branch.

## Example Usage

```yaml
steps:
- uses: actions/checkout@v4

- id: set-run-conditions
uses: ./.github/actions/set_run_conditions

- name: Use run conditions
run: |
echo "Is main branch push: ${{ steps.set-run-conditions.outputs.is_main_branch_push }}"
echo "Is main branch merge from release: ${{ steps.set-run-conditions.outputs.is_main_branch_merge_from_release_push }}"
echo "Is release branch PR: ${{ steps.set-run-conditions.outputs.is_release_branch_pr }}"
echo "Is feature branch PR: ${{ steps.set-run-conditions.outputs.is_feature_branch_pr }}"
echo "Is feature branch draft PR: ${{ steps.set-run-conditions.outputs.is_feature_branch_draft_pr }}"
```
37 changes: 37 additions & 0 deletions .github/actions/set_run_conditions/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: 'Set run conditions'
description: 'Sets the run conditions based on the current GitHub context'
outputs:
is_main_branch_push:
description: 'True if this is a push to the main branch (excluding merges from release branches)'
value: ${{ steps.set-conditions.outputs.is_main_branch_push }}
is_main_branch_push_from_release_merge:
description: 'True if this is a push to the main branch from a release branch merge'
value: ${{ steps.set-conditions.outputs.is_main_branch_push_from_release_merge }}
is_release_branch_pr:
description: 'True if this is a pull request from a release branch'
value: ${{ steps.set-conditions.outputs.is_release_branch_pr }}
is_feature_branch_pr:
description: 'True if this is a pull request from a feature branch (non-draft)'
value: ${{ steps.set-conditions.outputs.is_feature_branch_pr }}
is_feature_branch_draft_pr:
description: 'True if this is a draft pull request from a feature branch'
value: ${{ steps.set-conditions.outputs.is_feature_branch_draft_pr }}
runs:
using: 'composite'
steps:
- id: set-conditions
run: |
# Define conditions using shell variables
AZLE_IS_MAIN_BRANCH_PUSH=${{ github.ref == 'refs/heads/main' && !contains(github.event.head_commit.message, 'demergent-labs/release--') }}
AZLE_IS_MAIN_BRANCH_PUSH_FROM_RELEASE_MERGE=${{ github.ref == 'refs/heads/main' && contains(github.event.head_commit.message, 'demergent-labs/release--') }}
AZLE_IS_RELEASE_PR=${{ startsWith(github.head_ref, 'release--') }}
AZLE_IS_FEATURE_PR=${{ !startsWith(github.head_ref, 'release--') && github.ref != 'refs/heads/main' && github.event.pull_request.draft == false }}
AZLE_IS_DRAFT_PR=${{ !startsWith(github.head_ref, 'release--') && github.ref != 'refs/heads/main' && github.event.pull_request.draft == true }}
# Set individual outputs
echo "is_main_branch_push=$AZLE_IS_MAIN_BRANCH_PUSH" >> $GITHUB_OUTPUT
echo "is_main_branch_push_from_release_merge=$AZLE_IS_MAIN_BRANCH_PUSH_FROM_RELEASE_MERGE" >> $GITHUB_OUTPUT
echo "is_release_branch_pr=$AZLE_IS_RELEASE_BRANCH_PR" >> $GITHUB_OUTPUT
echo "is_feature_branch_pr=$AZLE_IS_FEATURE_BRANCH_PR" >> $GITHUB_OUTPUT
echo "is_feature_branch_draft_pr=$AZLE_IS_FEATURE_BRANCH_DRAFT_PR" >> $GITHUB_OUTPUT
shell: bash
46 changes: 46 additions & 0 deletions .github/workflows/get_and_run_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Prepare and Run Tests

on:
workflow_call:
inputs:
directories:
required: true
type: string
exclude-dirs:
required: false
type: string
default: ''

jobs:
prepare-test-environment:
name: 'Prepare Test Environment'
runs-on: ubuntu-latest
outputs:
test-infos: ${{ steps.get-test-infos.outputs.test-infos }}
include_npm: ${{ steps.set-include-npm.outputs.include_npm }}
steps:
- uses: actions/checkout@v4
- id: get-test-infos
uses: ./.github/actions/get_test_infos
with:
directories: ${{ inputs.directories }}
exclude-dirs: ${{ inputs.exclude-dirs }}
- uses: ./.github/actions/set_run_conditions
id: set-conditions
- id: set-include-npm
run: |
if [[ "${{ steps.set-conditions.outputs.is_main_branch_push }}" == "true" || \
"${{ steps.set-conditions.outputs.is_main_branch_push_from_release_merge }}" == "true" || \
"${{ steps.set-conditions.outputs.is_release_branch_pr }}" == "true" ]]; then
echo "include_npm=true" >> $GITHUB_OUTPUT
else
echo "include_npm=false" >> $GITHUB_OUTPUT
fi
run-tests:
name: 'Run'
needs: prepare-test-environment
uses: ./.github/workflows/run_test.yml
with:
test_infos: ${{ needs.prepare-test-environment.outputs.test-infos }}
include_npm: ${{ needs.prepare-test-environment.outputs.include_npm == 'true' }}
142 changes: 142 additions & 0 deletions .github/workflows/run_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
name: Run Test

on:
workflow_call:
inputs:
test_infos:
required: true
type: string
include_npm:
required: true
type: boolean

jobs:
run-test:
name: '${{matrix.tests.name}} | ${{matrix.tests.displayPath}} | ${{matrix.azle_source}}'
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_IS_MAIN_BRANCH_PUSH: ''
AZLE_IS_MAIN_BRANCH_PUSH_FROM_RELEASE_MERGE: ''
AZLE_IS_RELEASE_BRANCH_PR: ''
AZLE_IS_FEATURE_BRANCH_PR: ''
AZLE_IS_FEATURE_BRANCH_DRAFT_PR: ''

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, ubuntu-latest]
os: [ubuntu-latest]
azle_source:
- ${{ inputs.include_npm == 'true' && 'npm' || 'repo' }}
tests: ${{ fromJSON(inputs.test_infos) }}
steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/set_run_conditions
id: set-conditions

- name: Set condition environment variables
run: |
echo "AZLE_IS_MAIN_BRANCH_PUSH=${{ steps.set-conditions.outputs.is_main_branch_push }}" >> $GITHUB_ENV
echo "AZLE_IS_MAIN_BRANCH_PUSH_FROM_RELEASE_MERGE=${{ steps.set-conditions.outputs.is_main_branch_push_from_release_merge }}" >> $GITHUB_ENV
echo "AZLE_IS_RELEASE_BRANCH_PR=${{ steps.set-conditions.outputs.is_release_branch_pr }}" >> $GITHUB_ENV
echo "AZLE_IS_FEATURE_BRANCH_PR=${{ steps.set-conditions.outputs.is_feature_branch_pr }}" >> $GITHUB_ENV
echo "AZLE_IS_FEATURE_BRANCH_DRAFT_PR=${{ steps.set-conditions.outputs.is_feature_branch_draft_pr }}" >> $GITHUB_ENV
- id: check-conditions
run: |
echo "AZLE_IS_MAIN_BRANCH_PUSH: $AZLE_IS_MAIN_BRANCH_PUSH"
echo "AZLE_IS_MAIN_BRANCH_PUSH_FROM_RELEASE_MERGE: $AZLE_IS_MAIN_BRANCH_PUSH_FROM_RELEASE_MERGE"
echo "AZLE_IS_RELEASE_BRANCH_PR: $AZLE_IS_RELEASE_BRANCH_PR"
echo "AZLE_IS_FEATURE_BRANCH_PR: $AZLE_IS_FEATURE_BRANCH_PR"
echo "AZLE_IS_FEATURE_BRANCH_DRAFT_PR: $AZLE_IS_FEATURE_BRANCH_DRAFT_PR"
- 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}}

- id: get-node-version
uses: ./.github/actions/get_node_version

- uses: actions/setup-node@v4
with:
node-version: ${{ steps.get-node-version.outputs.node-version }}

- id: get-dfx-version
uses: ./.github/actions/get_dfx_version

- name: Run pre-test Azle setup
run: |
# Install dfx (Note: DFX must be installed before `npm install` because the azle installation process requires dfx)
src/build/stable/commands/install_global_dependencies/install_dfx.sh ${{ steps.get-dfx-version.outputs.dfx-version }}
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 with artificial delay 0
if: ${{ steps.set-conditions.outputs.is_feature_branch_pr == 'true' || steps.set-conditions.outputs.is_feature_branch_draft_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: ${{ steps.set-conditions.outputs.is_release_branch_pr == 'true' || steps.set-conditions.outputs.is_main_branch_push == 'true' || steps.set-conditions.outputs.is_main_branch_push_from_release_merge == 'true' }}
working-directory: ${{ matrix.tests.path }}
run: dfx start --clean --background --host 127.0.0.1:8000

- name: Run test
run: |
RUNS=1
if [[ "${{ steps.set-conditions.outputs.is_main_branch_push }}" == "true" ]]; then
RUNS=100
fi
if [[ "${{ steps.set-conditions.outputs.is_main_branch_push_from_release_merge }}" == "true" ]]; then
RUNS=100
fi
if [[ "${{ steps.set-conditions.outputs.is_release_branch_pr }}" == "true" ]]; then
RUNS=10
fi
if [[ "${{ steps.set-conditions.outputs.is_feature_branch_pr }}" == "true" ]]; then
RUNS=5
fi
if [[ "${{ steps.set-conditions.outputs.is_feature_branch_draft_pr }}" == "true" ]]; then
RUNS=1
fi
echo "Running tests $RUNS times"
AZLE_PROPTEST_NUM_RUNS=$RUNS AZLE_PROPTEST_VERBOSE=true npm test
shell: bash -l {0}
working-directory: ${{ matrix.tests.path }}
Loading

0 comments on commit 5d70454

Please sign in to comment.