Skip to content

Commit 603b51d

Browse files
pjanotticodeboten
andauthored
[chore] Fix scoped tests (open-telemetry#38931)
Scoped tests were broken for some time since the action to grab the changed sources had to be removed. The runs were green but not actually testing anything. This change fixes that and also starts to run "make" instead of "make test" for the affected components. --------- Co-authored-by: Alex Boten <[email protected]>
1 parent a40d6b0 commit 603b51d

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44

55
go.sum linguist-generated=true
66

7+
# To avoid git status and other tools reporting files due to different line endings
8+
# normalize the line endings to LF
9+
* text=auto eol=lf

.github/workflows/scoped-test.yaml

+32-12
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,45 @@ jobs:
1212
changedfiles:
1313
runs-on: ubuntu-latest
1414
if: ${{ github.actor != 'dependabot[bot]' }}
15+
env:
16+
PR_HEAD: ${{ github.event.pull_request.head.sha }}
1517
outputs:
16-
go_sources: ${{ steps.changed-source.outputs.go_sources }}
17-
go_tests: ${{ steps.changed-test.outputs.go_tests }}
18+
go_sources: ${{ steps.changes.outputs.go_sources }}
19+
go_tests: ${{ steps.changes.outputs.go_tests }}
1820
steps:
1921
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
2022
with:
2123
fetch-depth: 0
22-
- name: Get changed files
23-
id: changed-source
24-
run: |
25-
files=$(git diff --name-only --diff-filter=ACMRTUXB $(git merge-base origin/main $PR_HEAD) $PR_HEAD | grep .go$ | xargs)
2624

27-
echo "go_sources=$files" >> $GITHUB_OUTPUT
28-
- name: Get changed files
29-
id: changed-test
25+
- name: Get changes
26+
shell: bash
27+
id: changes
3028
run: |
31-
files=$(git diff --name-only --diff-filter=ACMRTUXB $(git merge-base origin/main $PR_HEAD) $PR_HEAD | grep _test.go$ | xargs)
29+
changed_files=$(git diff --name-only --diff-filter=ACMRTUXB $(git merge-base origin/main $PR_HEAD) $PR_HEAD)
30+
echo changed_files
31+
echo $changed_files
32+
33+
go_sources=$(echo "$changed_files" | tr ' ' '\n' | grep -E '\.go$' | grep -v -E '.*_test\.go$' || true)
34+
echo go_sources
35+
echo $go_sources
36+
if [[ -n "$go_sources" ]]; then
37+
{
38+
echo 'go_sources<<EOF'
39+
echo $go_sources
40+
echo EOF
41+
} >> $GITHUB_OUTPUT
42+
fi
3243
33-
echo "go_tests=$files" >> $GITHUB_OUTPUT
44+
go_tests=$(echo "$changed_files" | tr ' ' '\n' | grep -E '.*_test\.go$' || true)
45+
echo go_tests
46+
echo $go_tests
47+
if [[ -n "$go_tests" ]]; then
48+
{
49+
echo 'go_tests<<EOF'
50+
echo $go_tests
51+
echo EOF
52+
} >> $GITHUB_OUTPUT
53+
fi
3454
3555
scoped-tests:
3656
needs: changedfiles
@@ -83,4 +103,4 @@ jobs:
83103
env:
84104
CHANGED_GOLANG_SOURCES: ${{ needs.changedfiles.outputs.go_sources }}
85105
run: |
86-
make for-affected-components CMD="make test"
106+
make for-affected-components CMD="make"

0 commit comments

Comments
 (0)