File tree 1 file changed +58
-0
lines changed
1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change
1
+ name : Go Test
2
+
3
+ on :
4
+ push :
5
+ branches : [main]
6
+ pull_request :
7
+ branches : [main]
8
+
9
+ jobs :
10
+ diff :
11
+ runs-on : ubuntu-latest
12
+ outputs :
13
+ matrix : ${{ steps.set-matrix.outputs.matrix }}
14
+ steps :
15
+ - uses : actions/checkout@v2
16
+ with :
17
+ fetch-depth : 0
18
+ ref : ${{ github.head_ref }}
19
+ - id : set-matrix
20
+ run : |
21
+ changed_dirs=$(git diff --name-only origin/${{ github.base_ref }} | grep '.go$' | xargs -I {} dirname {} | uniq | awk '{print "\"" $0 "\""}' | jq -R -s -c 'split("\n")[:-1]')
22
+ echo "Changed directories: $changed_dirs"
23
+ echo "matrix=$changed_dirs" >> $GITHUB_OUTPUT
24
+
25
+ test :
26
+ needs : diff
27
+ runs-on : ubuntu-latest
28
+ if : needs.diff.outputs.matrix != '[]'
29
+ strategy :
30
+ fail-fast : false
31
+ matrix :
32
+ dir : ${{fromJson(needs.diff.outputs.matrix)}}
33
+ steps :
34
+ - uses : actions/checkout@v2
35
+ - uses : actions/setup-go@v2
36
+ with :
37
+ go-version : " ^1.12.1"
38
+ - name : Run tests in changed directories
39
+ run : |
40
+ for dir in "${{ matrix.dir }}"; do
41
+ if [ -d "$dir" ]; then
42
+ echo "Running tests in $dir"
43
+ (cd "$dir" && go test ./...)
44
+ else
45
+ echo "No Go files in $dir"
46
+ fi
47
+ done
48
+
49
+ test-main :
50
+ if : github.ref == 'refs/heads/main' && github.event_name == 'push'
51
+ runs-on : ubuntu-latest
52
+ steps :
53
+ - uses : actions/checkout@v2
54
+ - uses : actions/setup-go@v2
55
+ with :
56
+ go-version : " ^1.12.1"
57
+ - name : Run tests
58
+ run : go test ./...
You can’t perform that action at this time.
0 commit comments