-
Notifications
You must be signed in to change notification settings - Fork 7
/
cover.example.yml
106 lines (99 loc) · 3.77 KB
/
cover.example.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
name: Coverage report
concurrency:
cancel-in-progress: true
group: cover-${{ github.ref }}
on:
pull_request:
push:
branches:
- main
jobs:
main:
name: Coverage
if: github.actor != 'dependabot[bot]'
runs-on: ubuntu-latest
steps:
# required bootstrap steps (e.g. Docker package registry login, additional packages)
- name: Checkout source
if: github.event_name != 'pull_request'
uses: actions/checkout@v4
- name: Checkout pull request base
if: github.event_name == 'pull_request'
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.ref }}
- name: Setup Golang with cache
uses: flipgroup/action-golang-with-cache@main
with:
version-file: go.mod
- name: Generate Golang source hash base
id: hash-base
run: echo "value=${{ hashFiles('**/*.go','!vendor/**') }}" >>"$GITHUB_OUTPUT"
- name: Cache base cover profile
id: cache-base
uses: actions/cache@v4
with:
key: golang-cover-profile-${{ steps.hash-base.outputs.value }}
path: cover-${{ steps.hash-base.outputs.value }}.profile
- name: Generate base cover profile
if: steps.cache-base.outputs.cache-hit != 'true'
# generate base cover profile
# example:
# > env:
# > GOFLAGS: -coverprofile=cover-${{ steps.hash-base.outputs.value }}.profile
# > run: make test
- name: Checkout source
if: github.event_name == 'pull_request'
uses: actions/checkout@v4
with:
clean: false
- name: Generate Golang source hash head
if: github.event_name == 'pull_request'
id: hash-head
run: echo "value=${{ hashFiles('**/*.go','!vendor/**') }}" >>"$GITHUB_OUTPUT"
- name: Cache head cover profile
if: |
github.event_name == 'pull_request' &&
steps.hash-base.outputs.value != steps.hash-head.outputs.value
id: cache-head
uses: actions/cache@v4
with:
key: golang-cover-profile-${{ steps.hash-head.outputs.value }}
path: cover-${{ steps.hash-head.outputs.value }}.profile
- name: Generate head cover profile
if: |
github.event_name == 'pull_request' &&
steps.hash-base.outputs.value != steps.hash-head.outputs.value &&
steps.cache-head.outputs.cache-hit != 'true'
# generate head cover profile
# example:
# > env:
# > GOFLAGS: -coverprofile=cover-${{ steps.hash-head.outputs.value }}.profile
# > run: make test
- name: Fetch golang-cover-diff @main SHA-1
id: golang-cover-diff-main
run: |
sha1=$(curl \
--header "Accept: application/vnd.github+json" \
--silent \
https://api.github.com/repos/flipgroup/golang-cover-diff/branches/main | \
jq --raw-output ".commit.sha")
echo "sha1=$sha1" >>"$GITHUB_OUTPUT"
- name: Cache golang-cover-diff
id: cache-golang-cover-diff
uses: actions/cache@v4
with:
key: golang-cover-diff-${{ runner.os }}-sha1-${{ steps.golang-cover-diff-main.outputs.sha1 }}
path: ~/go/bin/golang-cover-diff
- name: Install golang-cover-diff
if: steps.cache-golang-cover-diff.outputs.cache-hit != 'true'
run: go install github.com/flipgroup/golang-cover-diff@main
- name: Run golang-cover-diff
if: github.event_name == 'pull_request'
env:
GITHUB_PULL_REQUEST_ID: ${{ github.event.number }}
GITHUB_TOKEN: ${{ github.token }}
run: |
golang-cover-diff \
cover-${{ steps.hash-base.outputs.value }}.profile \
cover-${{ steps.hash-head.outputs.value }}.profile