Skip to content

Commit 17038b8

Browse files
authored
fix: created integration-inputs to keep integration tests more focused (#3171)
1 parent 06393c3 commit 17038b8

2 files changed

Lines changed: 71 additions & 8 deletions

File tree

.github/workflows/lint.yml

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,45 @@ jobs:
2121
modules: ${{ steps.set-modules.outputs.modules }}
2222
steps:
2323
- uses: actions/checkout@v5
24+
with:
25+
# Full history so we can diff against the PR base to find changed modules.
26+
fetch-depth: 0
2427
- id: set-modules
25-
run: echo "modules=$(go list -m -json | jq -s '.' | jq -c '[.[].Dir]')" >> $GITHUB_OUTPUT
28+
env:
29+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
30+
run: |
31+
set -euo pipefail
32+
33+
all_modules=$(go list -m -json | jq -s -c '[.[].Dir]')
34+
35+
# Files changed by this PR (repo-relative paths), vs the base merge-base.
36+
changed=$(git diff --name-only "${BASE_SHA}...HEAD")
37+
38+
# Changes to workspace-wide inputs affect linting of every module,
39+
# so lint them all in that case.
40+
if printf '%s\n' "$changed" | grep -qE '^(go\.work|go\.work\.sum|\.golangci\.yml|\.tool-versions)$'; then
41+
echo "Workspace-wide change detected; linting all modules."
42+
echo "modules=${all_modules}" >> "$GITHUB_OUTPUT"
43+
exit 0
44+
fi
45+
46+
# Otherwise, select only the modules that contain a changed file.
47+
root="$(pwd)"
48+
selected=$(go list -m -json | jq -r '.Dir' | while read -r dir; do
49+
rel="${dir#"$root"/}"
50+
while IFS= read -r f; do
51+
if [[ "$f" == "$rel"/* ]]; then printf '%s\n' "$dir"; break; fi
52+
done <<< "$changed"
53+
done | jq -R . | jq -s -c 'map(select(length > 0)) | unique')
54+
55+
echo "Changed modules: ${selected}"
56+
echo "modules=${selected}" >> "$GITHUB_OUTPUT"
2657
2758
golangci-lint:
2859
needs: detect-modules
29-
if: ${{ inputs.run-lint == true }}
60+
# Skip cleanly when no Go modules changed. An empty matrix would otherwise
61+
# make this job's result 'failure' (not 'skipped') for the aggregate below.
62+
if: ${{ inputs.run-lint == true && needs.detect-modules.outputs.modules != '[]' }}
3063
runs-on: ubuntu-latest
3164
strategy:
3265
matrix:
@@ -51,6 +84,11 @@ jobs:
5184
version: "v${{ env.GOLANGCI_LINT }}"
5285
working-directory: ${{ matrix.modules }}
5386

87+
# Only report issues introduced by this PR (on changed lines), not
88+
# pre-existing issues in files the PR didn't touch. Uses the PR patch
89+
# from the GitHub API, so no extra git history is needed.
90+
only-new-issues: true
91+
5492
# disable, as it randomly fails with the following error:
5593
# The command is terminated due to an error: [../../.golangci.yml] validate: compile schema: failing loading "https://golangci-lint.run/jsonschema/golangci.v2.11.jsonschema.json": Get "https://golangci-lint.run/jsonschema/golangci.v2.11.jsonschema.json": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
5694
verify: 'false'
@@ -75,7 +113,8 @@ jobs:
75113
exit 1
76114
fi
77115
78-
if [[ "${{ needs.golangci-lint.result }}" != "success" ]]; then
116+
# "skipped" is expected when no Go modules changed (empty matrix).
117+
if [[ "${{ needs.golangci-lint.result }}" != "success" && "${{ needs.golangci-lint.result }}" != "skipped" ]]; then
79118
echo "golangci-lint result: ${{ needs.golangci-lint.result }}"
80119
exit 1
81120
fi

.github/workflows/pull-request.yml

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,32 @@ jobs:
3737
- 'go.work'
3838
- 'go.work.sum'
3939
- 'Makefile'
40-
- '.github/**'
4140
- '.tool-versions'
41+
# only the .github paths that affect the Go unit/arm64 test suites,
42+
# so unrelated CI edits (e.g. other workflows) don't trigger them
43+
- '.github/workflows/pr-tests.yml'
44+
- '.github/workflows/pr-tests-arm64.yml'
45+
- '.github/actions/go-setup-cache/**'
46+
# Like test-inputs, but scoped to only the .github paths that affect
47+
# the integration harness (its workflow + composite actions) instead
48+
# of all of .github/**. This keeps unrelated CI edits (e.g. other
49+
# workflows) from triggering the ~20-min integration suite.
50+
integration-inputs:
51+
- 'packages/**'
52+
- 'tests/**'
53+
- 'spec/**'
54+
- 'go.work'
55+
- 'go.work.sum'
56+
- 'Makefile'
57+
- '.tool-versions'
58+
# invoked by the start-services action to launch each service
59+
- 'scripts/start-service.sh'
60+
- '.github/workflows/integration_tests.yml'
61+
- '.github/actions/build-packages/**'
62+
- '.github/actions/build-sandbox-template/**'
63+
- '.github/actions/host-init/**'
64+
- '.github/actions/start-services/**'
65+
- '.github/actions/go-setup-cache/**'
4266
lint-inputs:
4367
- 'packages/**'
4468
- 'tests/**'
@@ -115,7 +139,7 @@ jobs:
115139
with:
116140
# Only publish the results for same-repo PRs
117141
publish: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
118-
run-tests: ${{ contains(fromJSON(needs.detect-changes.outputs.changed-scopes), 'test-inputs') }}
142+
run-tests: ${{ contains(fromJSON(needs.detect-changes.outputs.changed-scopes), 'integration-inputs') }}
119143
secrets:
120144
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
121145
publish-test-results:
@@ -133,11 +157,11 @@ jobs:
133157

134158
steps:
135159
- name: Skip publishing when tests did not run
136-
if: ${{ !contains(fromJSON(needs.detect-changes.outputs.changed-scopes), 'test-inputs') }}
160+
if: ${{ !contains(fromJSON(needs.detect-changes.outputs.changed-scopes), 'test-inputs') && !contains(fromJSON(needs.detect-changes.outputs.changed-scopes), 'integration-inputs') }}
137161
run: echo "test result publishing skipped because test inputs did not change"
138162

139163
- name: Download Artifacts
140-
if: ${{ contains(fromJSON(needs.detect-changes.outputs.changed-scopes), 'test-inputs') }}
164+
if: ${{ contains(fromJSON(needs.detect-changes.outputs.changed-scopes), 'test-inputs') || contains(fromJSON(needs.detect-changes.outputs.changed-scopes), 'integration-inputs') }}
141165
uses: actions/download-artifact@v7
142166
with:
143167
path: artifacts
@@ -146,7 +170,7 @@ jobs:
146170
pattern: "!*.dockerbuild"
147171

148172
- name: Publish Test Results
149-
if: ${{ contains(fromJSON(needs.detect-changes.outputs.changed-scopes), 'test-inputs') }}
173+
if: ${{ contains(fromJSON(needs.detect-changes.outputs.changed-scopes), 'test-inputs') || contains(fromJSON(needs.detect-changes.outputs.changed-scopes), 'integration-inputs') }}
150174
uses: EnricoMi/publish-unit-test-result-action@v2
151175
with:
152176
comment_mode: off

0 commit comments

Comments
 (0)