2
2
3
3
set -e -o pipefail
4
4
5
- type gh > /dev/null 2>&1 || { echo >&2 ' ERROR: Script requires "gh" (see https://cli.github.com)' ; exit 1; }
6
- type go-coverage-report > /dev/null 2>&1 || { echo >&2 ' ERROR: Script requires "go-coverage-report" binary in PATH' ; exit 1; }
5
+ type gh > /dev/null 2>&1 || {
6
+ echo >&2 ' ERROR: Script requires "gh" (see https://cli.github.com)'
7
+ exit 1
8
+ }
9
+ type go-coverage-report > /dev/null 2>&1 || {
10
+ echo >&2 ' ERROR: Script requires "go-coverage-report" binary in PATH'
11
+ exit 1
12
+ }
7
13
8
14
USAGE=" $0 : Execute go-coverage-report as GitHub action.
9
15
@@ -56,40 +62,46 @@ CHANGED_FILES_PATH=${CHANGED_FILES_PATH:-.github/outputs/all_modified_files.json
56
62
SKIP_COMMENT=${SKIP_COMMENT:- false}
57
63
58
64
if [[ -z ${GITHUB_REPOSITORY+x} ]]; then
59
- echo " Missing github_repository argument"
60
- exit 1
65
+ echo " Missing github_repository argument"
66
+ exit 1
61
67
fi
62
68
63
69
if [[ -z ${GITHUB_PULL_REQUEST_NUMBER+x} ]]; then
64
- echo " Missing github_pull_request_number argument"
65
- exit 1
70
+ echo " Missing github_pull_request_number argument"
71
+ exit 1
66
72
fi
67
73
68
74
if [[ -z ${GITHUB_RUN_ID+x} ]]; then
69
- echo " Missing github_run_id argument"
70
- exit 1
75
+ echo " Missing github_run_id argument"
76
+ exit 1
71
77
fi
72
78
73
79
if [[ -z ${GITHUB_OUTPUT+x} ]]; then
74
- echo " Missing GITHUB_OUTPUT environment variable"
75
- exit 1
80
+ echo " Missing GITHUB_OUTPUT environment variable"
81
+ exit 1
76
82
fi
77
83
78
84
# If GITHUB_BASELINE_WORKFLOW_REF is defined, extract the workflow file path from it and use it instead of GITHUB_BASELINE_WORKFLOW
79
85
if [[ -n ${GITHUB_BASELINE_WORKFLOW_REF+x} ]]; then
80
- GITHUB_BASELINE_WORKFLOW=$( basename " ${GITHUB_BASELINE_WORKFLOW_REF%%@* } " )
86
+ GITHUB_BASELINE_WORKFLOW=$( basename " ${GITHUB_BASELINE_WORKFLOW_REF%%@* } " )
81
87
fi
82
88
83
89
export GH_REPO=" $GITHUB_REPOSITORY "
84
90
85
- start_group (){
86
- echo " ::group::$* "
87
- { set -x; return ; } 2> /dev/null
91
+ start_group () {
92
+ echo " ::group::$* "
93
+ {
94
+ set -x
95
+ return
96
+ } 2> /dev/null
88
97
}
89
98
90
- end_group (){
91
- { set +x; return ; } 2> /dev/null
92
- echo " ::endgroup::"
99
+ end_group () {
100
+ {
101
+ set +x
102
+ return
103
+ } 2> /dev/null
104
+ echo " ::endgroup::"
93
105
}
94
106
95
107
start_group " Download code coverage results from current run"
@@ -112,12 +124,12 @@ end_group
112
124
113
125
start_group " Compare code coverage results"
114
126
go-coverage-report \
115
- -root=" $ROOT_PACKAGE " \
116
- -trim=" $TRIM_PACKAGE " \
117
- " $OLD_COVERAGE_PATH " \
118
- " $NEW_COVERAGE_PATH " \
119
- " $CHANGED_FILES_PATH " \
120
- > $COVERAGE_COMMENT_PATH
127
+ -root=" $ROOT_PACKAGE " \
128
+ -trim=" $TRIM_PACKAGE " \
129
+ " $OLD_COVERAGE_PATH " \
130
+ " $NEW_COVERAGE_PATH " \
131
+ " $CHANGED_FILES_PATH " \
132
+ > $COVERAGE_COMMENT_PATH
121
133
end_group
122
134
123
135
if [ ! -s $COVERAGE_COMMENT_PATH ]; then
@@ -131,7 +143,7 @@ echo "Writing GitHub output parameter to \"$GITHUB_OUTPUT\""
131
143
echo " coverage_report<<END_OF_COVERAGE_REPORT"
132
144
cat " $COVERAGE_COMMENT_PATH "
133
145
echo " END_OF_COVERAGE_REPORT"
134
- } >> " $GITHUB_OUTPUT "
146
+ } >> " $GITHUB_OUTPUT "
135
147
136
148
if [ " $SKIP_COMMENT " = " true" ]; then
137
149
echo " Skipping pull request comment (\$ SKIP_COMMENT=true))"
@@ -142,10 +154,9 @@ start_group "Comment on pull request"
142
154
COMMENT_ID=$( gh api " repos/${GITHUB_REPOSITORY} /issues/${GITHUB_PULL_REQUEST_NUMBER} /comments" -q ' .[] | select(.user.login=="github-actions[bot]" and (.body | test("Coverage Δ")) ) | .id' | head -n 1)
143
155
if [ -z " $COMMENT_ID " ]; then
144
156
echo " Creating new coverage report comment"
157
+ gh pr comment " $GITHUB_PULL_REQUEST_NUMBER " --body-file=" $COVERAGE_COMMENT_PATH "
145
158
else
146
- echo " Replacing old coverage report comment"
147
- gh api -X DELETE " repos/${GITHUB_REPOSITORY} /issues/comments/${COMMENT_ID} "
159
+ echo " Updating old coverage report comment"
160
+ gh api -X PATCH " repos/${GITHUB_REPOSITORY} /issues/comments/${COMMENT_ID} " -f body= " $( cat " $COVERAGE_COMMENT_PATH " ) "
148
161
fi
149
-
150
- gh pr comment " $GITHUB_PULL_REQUEST_NUMBER " --body-file=$COVERAGE_COMMENT_PATH
151
162
end_group
0 commit comments