Skip to content

Run integration tests only on what changes #1433

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
53 changes: 46 additions & 7 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@
push:
branches: ["main"]
paths:
- 'charts/**'
- '!charts/k8s-monitoring-v1/**'
# - '.github/workflows/integration-test.yml'

Check warning on line 8 in .github/workflows/integration-test.yml

View workflow job for this annotation

GitHub Actions / YAML

8:1 [comments-indentation] comment not indented like content
- 'charts/k8s-monitoring/**'
- '!charts/k8s-monitoring/Makefile' # Skip chart README file
- '!charts/k8s-monitoring/README.md*' # Skip chart README file
- '!charts/k8s-monitoring/docs/**' # Skip documentation files
- '!charts/k8s-monitoring/tests/*.yaml' # Skip unit test files
- 'charts/k8s-monitoring-test/**'
pull_request:
paths:
- 'charts/**'
- '!charts/k8s-monitoring-v1/**'
# - '.github/workflows/integration-test.yml'

Check warning on line 17 in .github/workflows/integration-test.yml

View workflow job for this annotation

GitHub Actions / YAML

17:1 [comments-indentation] comment not indented like content
- 'charts/k8s-monitoring/**'
- '!charts/k8s-monitoring/Makefile' # Skip chart README file
- '!charts/k8s-monitoring/README.md*' # Skip chart README file
- '!charts/k8s-monitoring/docs/**' # Skip documentation files
- '!charts/k8s-monitoring/tests/*.yaml' # Skip unit test files
- 'charts/k8s-monitoring-test/**'

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -29,17 +39,46 @@
id: list_tests
working-directory: charts/k8s-monitoring/tests/integration
run: |
# if "integration-test-skip" is set, return an empty list
# If "integration-test-skip" is set, return an empty list
# All labels on this PR
labels='${{ toJson(github.event.pull_request.labels.*.name) }}'
if echo "${labels}" | jq --exit-status '. | any(. == "integration-test-skip")' > /dev/null; then
echo "\"integration-test-skip\" label is set, skipping integration tests."
echo "tests=[]" >> "${GITHUB_OUTPUT}"
exit 0
fi

Check failure on line 50 in .github/workflows/integration-test.yml

View workflow job for this annotation

GitHub Actions / YAML

50:1 [trailing-spaces] trailing spaces
all_tests=$(find . -name values.yaml -exec dirname {} \; | sort)

# Default: run all tests
tests="${all_tests}"

Check failure on line 55 in .github/workflows/integration-test.yml

View workflow job for this annotation

GitHub Actions / YAML

55:1 [trailing-spaces] trailing spaces
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "Manual triggered - running all tests."

elif [ "${{ github.event_name }}" = "push" ]; then
echo "Push to main - running all tests."

elif [ "${{ github.event_name }}" == "pull_request" ]; then
# Fetch base branch so we can diff against it
git fetch origin ${{ github.base_ref }}

Check failure on line 65 in .github/workflows/integration-test.yml

View workflow job for this annotation

GitHub Actions / YAML

65:1 [trailing-spaces] trailing spaces
changed_files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD)

# Check if any changed files are outside of the integration test directory
if echo "$changed_files" | grep -qv '^charts/k8s-monitoring/tests/integration/'; then
echo "PR contains changes outside of integration test directory - running all tests."
else
echo "PR only contains changes inside integration test directory - running only changed tests."
# Extract test dirs from changed values.yaml
tests=$(echo "$changed_files" \
| grep '^charts/k8s-monitoring/tests/integration/' \
| sed 's|^charts/k8s-monitoring/tests/integration/||' \
| awk -F/ '{print $1}' \
| sort -u)
fi
fi

tests=$(find . -name values.yaml -exec dirname {} \;)
echo "Tests: ${tests}"
echo "tests=$(echo "${tests}" | jq --raw-input --slurp --compact-output 'split("\n") | map(select(. != ""))')" >> "${GITHUB_OUTPUT}"

run-tests:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ spec:
k8s.grafana.com/scrape: "true"
k8s.grafana.com/job: "integrations/cert-manager"
k8s.grafana.com/metrics.portNumber: "9402"
another-annotation: yep
Loading