@@ -117,13 +117,11 @@ jobs:
117
117
- module : v2
118
118
path : v2
119
119
120
- defaults :
121
- run :
122
- working-directory : ${{ matrix.path }}
123
-
124
120
steps :
125
121
- name : Checkout code
126
122
uses : actions/checkout@v4
123
+ with :
124
+ ref : ${{ github.head_ref }}
127
125
128
126
- name : Set up Go
129
127
uses : actions/setup-go@v4
@@ -141,12 +139,15 @@ jobs:
141
139
ubuntu-latest-go-1.24-
142
140
143
141
- name : Download dependencies
142
+ working-directory : ${{ matrix.path }}
144
143
run : go mod download
145
144
146
145
- name : Run tests with coverage
146
+ working-directory : ${{ matrix.path }}
147
147
run : go test -coverprofile=coverage.out ./...
148
148
149
149
- name : Calculate coverage
150
+ working-directory : ${{ matrix.path }}
150
151
run : |
151
152
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}')
152
153
echo "Coverage: $COVERAGE%"
@@ -163,17 +164,41 @@ jobs:
163
164
fi
164
165
165
166
- name : Generate coverage report
167
+ working-directory : ${{ matrix.path }}
166
168
run : go tool cover -html=coverage.out -o coverage.html
167
169
168
170
- name : Upload coverage report
169
171
uses : actions/upload-artifact@v4
170
172
with :
171
- name : coverage-report
173
+ name : coverage-report-${{ matrix.module }}
172
174
path : |
173
- coverage.out
174
- coverage.html
175
+ ${{ matrix.path }}/coverage.out
176
+ ${{ matrix.path }}/coverage.html
177
+
178
+ - name : Go Coverage Badge # Pass the `coverage.out` output to this action
179
+ if : matrix.module == 'v2'
180
+ uses : tj-actions/coverage-badge-go@v2
181
+ with :
182
+ value : $COVERAGE
183
+
184
+ - name : Verify Changed files
185
+ if : matrix.module == 'v2'
186
+ uses : tj-actions/verify-changed-files@v16
187
+ id : verify-changed-files
188
+ with :
189
+ files : README.md
190
+
191
+ - name : Commit and push changes
192
+ if : matrix.module == 'v2' && steps.verify-changed-files.outputs.files_changed == 'true'
193
+ run : |
194
+ git config --local user.email "action@github.com"
195
+ git config --local user.name "GitHub Action"
196
+ git add README.md
197
+ git commit -m "chore: Updated coverage badge."
198
+ git push
175
199
176
200
- name : Add coverage to PR comment
201
+ working-directory : ${{ matrix.path }}
177
202
if : github.event_name == 'pull_request'
178
203
run : |
179
204
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}')
0 commit comments