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

tests: udpate the github workflow to run tests suggested by spread-filter tool #14519

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
38 changes: 26 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 @@ -102,20 +107,29 @@ jobs:
if [ -n "$FAILED_TESTS" ]; then
RUN_TESTS="$FAILED_TESTS"
else
CHANGES_PARAM=""
for CHANGE in $CHANGED_FILES; do
CHANGES_PARAM="$CHANGES_PARAM -c $CHANGE"
done
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 ${{ inputs.tasks }}; do
RUN_TESTS="$RUN_TESTS ${{ inputs.backend }}:$SYSTEM:$TESTS"
done
else
NEW_TESTS="$(./tests/lib/external/snapd-testing-tools/utils/spread-filter -r ./tests/lib/spread/rules/${{ inputs.rules }}.yaml -p "${{ inputs.backend }}:$SYSTEM" $CHANGES_PARAM)"
if [ -z "$RUN_TESTS" ]; then
RUN_TESTS="$NEW_TESTS"
else
RUN_TESTS="$RUN_TESTS $NEW_TESTS"
fi
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 +173,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/]
Loading