@@ -117,13 +117,11 @@ jobs:
117117 - module : v2
118118 path : v2
119119
120- defaults :
121- run :
122- working-directory : ${{ matrix.path }}
123-
124120 steps :
125121 - name : Checkout code
126122 uses : actions/checkout@v4
123+ with :
124+ ref : ${{ github.head_ref }}
127125
128126 - name : Set up Go
129127 uses : actions/setup-go@v4
@@ -141,12 +139,15 @@ jobs:
141139 ubuntu-latest-go-1.24-
142140
143141 - name : Download dependencies
142+ working-directory : ${{ matrix.path }}
144143 run : go mod download
145144
146145 - name : Run tests with coverage
146+ working-directory : ${{ matrix.path }}
147147 run : go test -coverprofile=coverage.out ./...
148148
149149 - name : Calculate coverage
150+ working-directory : ${{ matrix.path }}
150151 run : |
151152 COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}')
152153 echo "Coverage: $COVERAGE%"
@@ -163,17 +164,41 @@ jobs:
163164 fi
164165
165166 - name : Generate coverage report
167+ working-directory : ${{ matrix.path }}
166168 run : go tool cover -html=coverage.out -o coverage.html
167169
168170 - name : Upload coverage report
169171 uses : actions/upload-artifact@v4
170172 with :
171- name : coverage-report
173+ name : coverage-report-${{ matrix.module }}
172174 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
175199
176200 - name : Add coverage to PR comment
201+ working-directory : ${{ matrix.path }}
177202 if : github.event_name == 'pull_request'
178203 run : |
179204 COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}')
0 commit comments