Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use reusable workflows to break up tests #2152

Merged
merged 30 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c882082
use reusable workflows for running tests
bdemann Oct 4, 2024
ee4fc08
try splitting it up into two things
bdemann Oct 4, 2024
45542b5
this would be crazy
bdemann Oct 4, 2024
86ffe52
move run conditions into action
bdemann Oct 8, 2024
abbb9df
move node version inside get test infos action
bdemann Oct 8, 2024
eb31aec
remove name to prefer just id
bdemann Oct 8, 2024
5afdaab
try using variables instead of jq
bdemann Oct 8, 2024
bcedb3b
fold into one action
bdemann Oct 8, 2024
6f135d8
move get and run tests to a workflow
bdemann Oct 8, 2024
9001e67
update names
bdemann Oct 8, 2024
36df50f
improve readability
bdemann Oct 8, 2024
3495704
move os and include npm into the run tests workflow
bdemann Oct 8, 2024
65250e6
bring back comments
bdemann Oct 8, 2024
7e1fa2b
bring back dfx without artificial delay and comments
bdemann Oct 8, 2024
e0cf9b1
check conditions
bdemann Oct 8, 2024
85bd45d
restore lower case
bdemann Oct 8, 2024
8c31c99
set env variables to be '' by default
bdemann Oct 9, 2024
9d08830
fix spacing
bdemann Oct 9, 2024
8ba60a1
use underscore instead of dash
bdemann Oct 9, 2024
6c793ef
pr fixes
bdemann Oct 18, 2024
9ea228c
fixup
bdemann Oct 18, 2024
3cb7eb7
remove intermediary step
bdemann Oct 21, 2024
d3b22a8
revert
bdemann Oct 21, 2024
2d5c855
move include npm into get_and_run_tests
bdemann Oct 21, 2024
d2768e4
make value boolean
bdemann Oct 22, 2024
293baa1
rename is_main_branch_push_from_release_merge
bdemann Oct 22, 2024
0254818
update variable names for maximum verbosity
bdemann Oct 22, 2024
591c831
fixup
bdemann Oct 22, 2024
53ecbf6
fixup
bdemann Oct 22, 2024
8021478
fixup
bdemann Oct 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
lastmjs marked this conversation as resolved.
Show resolved Hide resolved
lastmjs marked this conversation as resolved.
Show resolved Hide resolved
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_merge_from_release_push:
description: 'True if this is a push to the main branch from a release branch merge'
value: ${{ steps.set-conditions.outputs.is_main_branch_merge_from_release_push }}
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
IS_MAIN_PUSH=${{ github.ref == 'refs/heads/main' && !contains(github.event.head_commit.message, 'demergent-labs/release--') }}
IS_MAIN_MERGE_RELEASE=${{ github.ref == 'refs/heads/main' && contains(github.event.head_commit.message, 'demergent-labs/release--') }}
IS_RELEASE_PR=${{ startsWith(github.head_ref, 'release--') }}
IS_FEATURE_PR=${{ !startsWith(github.head_ref, 'release--') && github.ref != 'refs/heads/main' && github.event.pull_request.draft == false }}
lastmjs marked this conversation as resolved.
Show resolved Hide resolved
IS_DRAFT_PR=${{ !startsWith(github.head_ref, 'release--') && github.ref != 'refs/heads/main' && github.event.pull_request.draft == true }}
lastmjs marked this conversation as resolved.
Show resolved Hide resolved

# Set individual outputs
echo "is_main_branch_push=$IS_MAIN_PUSH" >> $GITHUB_OUTPUT
echo "is_main_branch_merge_from_release_push=$IS_MAIN_MERGE_RELEASE" >> $GITHUB_OUTPUT
echo "is_release_branch_pr=$IS_RELEASE_PR" >> $GITHUB_OUTPUT
echo "is_feature_branch_pr=$IS_FEATURE_PR" >> $GITHUB_OUTPUT
echo "is_feature_branch_draft_pr=$IS_DRAFT_PR" >> $GITHUB_OUTPUT
shell: bash
33 changes: 33 additions & 0 deletions .github/workflows/get_and_run_tests.yml
lastmjs marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Get and Run Tests

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

jobs:
get-test-infos:
name: 'Get test infos'
runs-on: ubuntu-latest
outputs:
test-infos: ${{ steps.get-test-infos.outputs.test-infos }}
steps:
- uses: actions/checkout@v4
- id: get-test-infos
uses: ./.github/actions/get_test_infos
with:
directories: ${{ inputs.directories }}
exclude-dirs: ${{ inputs.exclude-dirs }}

run-tests:
name: 'Run'
needs: get-test-infos
uses: ./.github/workflows/run_test.yml
with:
test_infos: ${{ needs.get-test-infos.outputs.test-infos }}
149 changes: 149 additions & 0 deletions .github/workflows/run_test.yml
lastmjs marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
name: Run Test

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

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_MERGE_FROM_RELEASE_PUSH: ''
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]
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--') }}
lastmjs marked this conversation as resolved.
Show resolved Hide resolved
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(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_MERGE_FROM_RELEASE_PUSH=${{ steps.set-conditions.outputs.is_main_branch_merge_from_release_push }}" >> $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
lastmjs marked this conversation as resolved.
Show resolved Hide resolved
run: |
echo "AZLE_IS_MAIN_BRANCH_PUSH: $AZLE_IS_MAIN_BRANCH_PUSH"
echo "AZLE_IS_MAIN_BRANCH_MERGE_FROM_RELEASE_PUSH: $AZLE_IS_MAIN_BRANCH_MERGE_FROM_RELEASE_PUSH"
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
lastmjs marked this conversation as resolved.
Show resolved Hide resolved
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_merge_from_release_push == '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_merge_from_release_push }}" == "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