Skip to content

Commit

Permalink
tests: udpate the github workflow to run tests suggested by spread-fi…
Browse files Browse the repository at this point in the history
…lter tool

Through this change we will run the tests suggested by the spread-filter
tool following the rules located in tests/lib/spread/rules which defined
for each system.

For nested tests, this ruleset will make sure that:
. Always that the nested.sh lib or the assertions dir are updated, all
the nested test are executed
 . When an specific nested test is updated, then this is executed
. If the "Run Nested" label is added to the PR, all the nested tests
will be executed as well.
 . In master branch, all nested test are executed
 . In other scenarios, nested tests are not executed.

Also, in master branch, all the tests are executed (the tests defined in
the matrix for each system).
  • Loading branch information
sergiocazzolato committed Nov 13, 2024
1 parent 9a71592 commit ddffbe7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
5 changes: 0 additions & 5 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
# - https://github.com/actions/labeler/issues/112
# - https://github.com/actions/labeler/issues/104

# Add 'Run nested -auto-' label to either any change on nested lib or nested test
Run nested -auto-:
- tests/lib/nested.sh
- tests/nested/**/*

# Add 'Needs Documentation -auto-' label to indicate a change needs changes in the docs
Needs Documentation -auto-:
- cmd/snap/**/*"
Expand Down
29 changes: 17 additions & 12 deletions .github/workflows/spread-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ jobs:
# Make sure the test results dirs are created
# This step has to be after the cache is restored
mkdir -p "$TEST_RESULTS_DIR"
mkdir -p "$TEST_RESULTS_DIR"
- name: Prepare nested env vars
if: contains(github.event.pull_request.labels.*.name, 'Run nested') && startsWith(matrix.group, 'nested-')
run: |
echo "RUN_NESTED=true" >> "$GITHUB_ENV"
- name: Get changed files
id: changed-files
Expand Down Expand Up @@ -103,19 +108,19 @@ jobs:
RUN_TESTS="$FAILED_TESTS"
else
for SYSTEM in ${{ inputs.systems }}; do
for TESTS in ${{ inputs.tasks }}; do
RUN_TESTS="$RUN_TESTS ${{ inputs.backend }}:$SYSTEM:$TESTS"
done
CHANGES_PARAM=""
for CHANGE in $CHANGED_FILES; do
CHANGES_PARAM="$CHANGES_PARAM -c $CHANGE"
done
SUGGESTED_TESTS="$SUGGESTED_TESTS $(./tests/lib/external/snapd-testing-tools/utils/spread-filter -r ./tests/lib/spread/rules/${{ inputs.rules }}.yaml -p "${{ inputs.backend }}:$SYSTEM" $CHANGES_PARAM)"
# Configure parameters to run tests based on current changes
# The tests are just filtered when the change is a PR
# When 'Run Nested' label is added in a PR, all the nested tests have to be executed
if [ -z "${{ github.event.number }}" ] || [ "$RUN_NESTED" = 'true' ]; then
for TESTS in ${{ matrix.tests }}; do
RUN_TESTS="$RUN_TESTS ${{ matrix.backend }}:$SYSTEM:$TESTS"
done
else
RUN_TESTS="$RUN_TESTS $(./tests/lib/external/snapd-testing-tools/utils/spread-filter -r ./tests/lib/spread/rules/${{ matrix.rules }}.yaml -p "${{ matrix.backend }}:$SYSTEM" $CHANGES_PARAM)"
fi
done
fi
echo RUN_TESTS="$RUN_TESTS" >> $GITHUB_ENV
echo "Suggested tests by spread-filter tool"
echo "$SUGGESTED_TESTS"
- name: Setup grafana parameters
if: "!contains(github.event.pull_request.labels.*.name, 'Skip spread')"
Expand Down Expand Up @@ -159,7 +164,7 @@ jobs:
done
- name: Run spread tests
if: "!contains(github.event.pull_request.labels.*.name, 'Skip spread') && ( !startsWith(inputs.group, 'nested-') || contains(github.event.pull_request.labels.*.name, 'Run nested') )"
if: "!contains(github.event.pull_request.labels.*.name, 'Skip spread')"
env:
SPREAD_GOOGLE_KEY: ${{ secrets.SPREAD_GOOGLE_KEY }}
run: |
Expand Down
10 changes: 8 additions & 2 deletions tests/lib/spread/rules/nested.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ rules:
- tests/nested/.*
to: [$SELF]

rest:
from: [.*]
nestedlib:
from:
- tests/lib/nested.sh
to: [tests/nested/]

assertions:
from:
- tests/lib/assertions/.*
to: [tests/nested/]

0 comments on commit ddffbe7

Please sign in to comment.