Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit fb8663d

Browse files
authored
Add better logging for GitHub Actions (#410)
* Add better logging for GitHub Actions * Update UTs * Add GitHub Actions workflow * Typo * Logging * No name? * Fix tests for GHA * Fix tests * Fix tests again * Mistake * Add env vars * force * shellcheck * Update tests * Fix CircleCI * Fix CircleCI fo real * Not strict
1 parent 0f41bb7 commit fb8663d

File tree

8 files changed

+90
-37
lines changed

8 files changed

+90
-37
lines changed

.github/workflows/ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
on: [push, pull_request]
2+
3+
jobs:
4+
test:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v2
8+
- name: Set up Ruby
9+
uses: ruby/setup-ruby@v1
10+
with:
11+
ruby-version: 2.7
12+
- name: Extract shunit
13+
run: tar --strip-components=1 -zxvf tests/shunit2-2.1.8.tar.gz
14+
- name: Install Ruby dependencies
15+
run: |
16+
gem install bashcov
17+
gem install codecov
18+
- name: Run tests
19+
run: |
20+
env -i PATH="$PATH"
21+
bashcov tests/test
22+
shasum --algorithm 1 --check ./SHA1SUM
23+
shasum --algorithm 256 --check ./SHA256SUM
24+
shasum --algorithm 512 --check ./SHA512SUM
25+
- name: Upload Codecov
26+
run:
27+
bash ./codecov -Z

SHA1SUM

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ce0cfa65fe07b458037474f838759211bcfc17d1 codecov
1+
4dc681475a004f8cb8c1d8cf7c5aff3bd53d615b codecov

SHA256SUM

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0526a487e02b0eb5f314cd23a4d5b54c4e2a3e20b68ed5a1f2517b76d5ea73b8 codecov
1+
ae4058f2f1f0d3f62e6a95e288616c2a3e9c8a4929d8cefd69e6c36da81d0963 codecov

SHA512SUM

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b9820fd0c585f98028fdbccf40ff440c96270e8779925257c8fbfa476523b9690fb97b3e1fc52e8a9c3667916b2a6493c76f36dcf700da48a1bd7ff647131b54 codecov
1+
6d01cca237aaf0627165e71d384dfc4f63b538fe463138f078e9a54b434350cf008bcd7dbf489d80985156d53475f9c1bb41b425320372d5028942cde795b0a7 codecov

codecov

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,14 @@ then
841841
elif [ "$GITHUB_ACTIONS" != "" ];
842842
then
843843
say "$e==>$x GitHub Actions detected."
844+
say " Env vars used:"
845+
say " -> GITHUB_ACTIONS: ${GITHUB_ACTIONS}"
846+
say " -> GITHUB_HEAD_REF: ${GITHUB_HEAD_REF}"
847+
say " -> GITHUB_REF: ${GITHUB_REF}"
848+
say " -> GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}"
849+
say " -> GITHUB_RUN_ID: ${GITHUB_RUN_ID}"
850+
say " -> GITHUB_SHA: ${GITHUB_SHA}"
851+
say " -> GITHUB_WORKFLOW: ${GITHUB_WORKFLOW}"
844852

845853
# https://github.com/features/actions
846854
service="github-actions"
@@ -1819,7 +1827,7 @@ else
18191827

18201828
if [ "$s3" != "" ];
18211829
then
1822-
say " ${g}->${x} View reports at ${b}$(echo "$res" | sed -n 1p)${x}"
1830+
say " ${g}->${x} Reports have been successfully queued for processing at ${b}$(echo "$res" | sed -n 1p)${x}"
18231831
exit 0
18241832
else
18251833
say " ${r}X>${x} Failed to upload"
@@ -1851,7 +1859,7 @@ else
18511859
status=$(echo "$res" | head -1 | cut -d' ' -f2)
18521860
if [ "$status" = "" ] || [ "$status" = "200" ];
18531861
then
1854-
say " View reports at ${b}$(echo "$res" | head -2 | tail -1)${x}"
1862+
say " Reports have been successfully queued for processing at ${b}$(echo "$res" | head -2 | tail -1)${x}"
18551863
exit 0
18561864
else
18571865
say " ${g}${res}${x}"

env

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,12 @@ then
253253
elif [ "$GITHUB_ACTIONS" != '' ]
254254
then
255255
add "GITHUB_ACTIONS"
256+
add "GITHUB_HEAD_REF"
256257
add "GITHUB_REF"
257258
add "GITHUB_REPOSITORY"
258-
add "GITHUB_HEAD_REF"
259-
add "GITHUB_SHA"
260259
add "GITHUB_RUN_ID"
260+
add "GITHUB_SHA"
261+
add "GITHUB_WORKFLOW"
261262

262263
elif [ "$SYSTEM_TEAMFOUNDATIONSERVERURI" != "" ];
263264
then

tests/env

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,7 @@ export CI_PROJECT_DIR=""
4242
export CI_SERVER_NAME=""
4343
export CI_SERVER_NAME=""
4444
export CI=""
45-
export CIRCLE_BRANCH=""
4645
export CIRCLE_BUILD_NUM=""
47-
export CIRCLE_NODE_INDEX=""
48-
export CIRCLE_PR_NUMBER=""
49-
export CIRCLE_PROJECT_REPONAME=""
50-
export CIRCLE_PROJECT_USERNAME=""
51-
export CIRCLE_SHA1=""
5246
export CIRCLECI=""
5347
export CODECOV_ENV=""
5448
export CODECOV_SLUG=""
@@ -62,11 +56,6 @@ export ghprbPullId=""
6256
export ghprbSourceBranch=""
6357
export GIT_BRANCH=""
6458
export GIT_COMMIT=""
65-
export GITHUB_REF=""
66-
export GITHUB_HEAD_REF=""
67-
export GITHUB_REPOSITORY=""
68-
export GITHUB_RUN_ID=""
69-
export GITHUB_SHA=""
7059
export GITLAB_CI=""
7160
export JENKINS_URL=""
7261
export MAGNUM=""
@@ -125,6 +114,7 @@ export BITBUCKET_REPO_SLUG=""
125114
export BITBUCKET_PR_ID=""
126115
export BITBUCKET_COMMIT=""
127116
export GITHUB_ACTIONS=""
117+
export GITHUB_HEAD_REF=""
128118
export CODEBUILD_CI=""
129119
export CODEBUILD_WEBHOOK_HEAD_REF=""
130120
export CODEBUILD_RESOLVED_SOURCE_VERSION=""

tests/test

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ VERSION=$(grep "VERSION=" codecov | tr -d 'VERSION=' | tr -d '"')
99
_SHA=$(git rev-parse HEAD)
1010
_BRANCH=$(git rev-parse --abbrev-ref HEAD)
1111
_BRANCH=$(urlencode "$_BRANCH")
12+
_BUILD=$("${GITHUB_RUN_ID}" | ${CIRCLE_BUILD_NUM} | '')
13+
_JOB=$(urlencode "${GITHUB_WORKFLOW}" | '')
1214
if [ "$_BRANCH" = "HEAD" ];
1315
then
1416
_BRANCH=""
1517
fi
1618

19+
_CIRCLECI=$CIRCLECI
20+
_GITHUB_ACTIONS=$GITHUB_ACTIONS
21+
_GITHUB_HEAD_REF=$GITHUB_HEAD_REF
22+
1723
export PATH=$PWD:$PATH
1824

1925
function reset () {
@@ -64,21 +70,21 @@ function test_fixes () {
6470
function test_url_opt () {
6571
reset
6672
res=$(./codecov -d -u http://example.com | grep "http://example.com/")
67-
diff <(echo "http://example.com/upload/v4?package=bash-$VERSION&token=&branch=$_BRANCH&commit=$_SHA&build=&build_url=&name=&tag=&slug=codecov%2Fcodecov-bash&service=&flags=&pr=&job=&cmd_args=d,u") <(echo "$res")
73+
diff <(echo "http://example.com/upload/v4?package=bash-$VERSION&token=&branch=$_BRANCH&commit=$_SHA&build=$_BUILD&build_url=&name=&tag=&slug=codecov%2Fcodecov-bash&service=&flags=&pr=&job=$_JOB&cmd_args=d,u") <(echo "$res")
6874
assertTrue 'Expected output differs.' $?
6975
}
7076

7177
function test_url_env () {
7278
reset
7379
res=$(CODECOV_URL="http://other.com" ./codecov -d | grep "http://other.com/")
74-
diff <(echo "http://other.com/upload/v4?package=bash-$VERSION&token=&branch=$_BRANCH&commit=$_SHA&build=&build_url=&name=&tag=&slug=codecov%2Fcodecov-bash&service=&flags=&pr=&job=&cmd_args=d") <(echo "$res")
80+
diff <(echo "http://other.com/upload/v4?package=bash-$VERSION&token=&branch=$_BRANCH&commit=$_SHA&build=$_BUILD&build_url=&name=&tag=&slug=codecov%2Fcodecov-bash&service=&flags=&pr=&job=$_JOB&cmd_args=d") <(echo "$res")
7581
assertTrue 'Expected output differs.' $?
7682
}
7783

7884
function test_flags_opt () {
7985
reset
8086
res=$(./codecov -d -F f1 -F f2 | grep "https://codecov.io/")
81-
diff <(echo "https://codecov.io/upload/v4?package=bash-$VERSION&token=&branch=$_BRANCH&commit=$_SHA&build=&build_url=&name=&tag=&slug=codecov%2Fcodecov-bash&service=&flags=f1,f2&pr=&job=&cmd_args=d,F,F") <(echo "$res")
87+
diff <(echo "https://codecov.io/upload/v4?package=bash-$VERSION&token=&branch=$_BRANCH&commit=$_SHA&build=$_BUILD&build_url=&name=&tag=&slug=codecov%2Fcodecov-bash&service=&flags=f1,f2&pr=&job=$_JOB&cmd_args=d,F,F") <(echo "$res")
8288
assertTrue 'Expected output differs.' $?
8389
}
8490

@@ -90,7 +96,7 @@ function test_flags_opt () {
9096
# slug: owner/repo
9197
# ' > codecov.yml
9298
# res=$(./codecov -d | grep "http://other.com/")
93-
# diff <(echo "http://other.com/upload/v4?package=bash-$VERSION&token=abc123&branch=$_BRANCH&commit=$_SHA&build=&build_url=&tag=&slug=owner/repo&yaml=codecov.yml&service=&flags=&pr=&job=") <(echo "$res")
99+
# diff <(echo "http://other.com/upload/v4?package=bash-$VERSION&token=abc123&branch=$_BRANCH&commit=$_SHA&build=$_BUILD&build_url=&tag=&slug=owner/repo&yaml=codecov.yml&service=&flags=&pr=&job=$_JOB") <(echo "$res")
94100
# assertTrue 'Expected output differs.' $?
95101
# }
96102
#
@@ -100,22 +106,22 @@ function test_flags_opt () {
100106
# token: uuid
101107
# ' > tests/.codecov.yml
102108
# res=$(./codecov -d | grep "https://codecov.io/")
103-
# diff <(echo "https://codecov.io/upload/v4?package=bash-$VERSION&token=uuid&branch=$_BRANCH&commit=$_SHA&build=&build_url=&tag=&slug=codecov%2Fcodecov-bash&yaml=tests%2F.codecov.yml&service=&flags=&pr=&job=") <(echo "$res")
109+
# diff <(echo "https://codecov.io/upload/v4?package=bash-$VERSION&token=uuid&branch=$_BRANCH&commit=$_SHA&build=$_BUILD&build_url=&tag=&slug=codecov%2Fcodecov-bash&yaml=tests%2F.codecov.yml&service=&flags=&pr=&job=$_JOB") <(echo "$res")
104110
# assertTrue 'Expected output differs.' $?
105111
# }
106112

107113
function test_build_arg () {
108114
reset
109115
res=$(./codecov -d -b 1.6 | grep "https://codecov.io/")
110-
diff <(echo "https://codecov.io/upload/v4?package=bash-$VERSION&token=&branch=$_BRANCH&commit=$_SHA&build=1.6&build_url=&name=&tag=&slug=codecov%2Fcodecov-bash&service=&flags=&pr=&job=&cmd_args=d,b") <(echo "$res")
116+
diff <(echo "https://codecov.io/upload/v4?package=bash-$VERSION&token=&branch=$_BRANCH&commit=$_SHA&build=1.6&build_url=&name=&tag=&slug=codecov%2Fcodecov-bash&service=&flags=&pr=&job=$_JOB&cmd_args=d,b") <(echo "$res")
111117
assertTrue 'Expected output differs.' $?
112118
}
113119

114120
# function test_changes_merge_commit () {
115121
# reset
116122
# git commit --amend -m 'Merge 5d4123bcb99dd1bc9b5ae8b4271b39dbe4c3928b into 2f85ca252d69d6c52484f0c4b2e8500498228398'
117123
# res=$(./codecov -d -b 1.6 | grep "https://codecov.io/")
118-
# diff <(echo "https://codecov.io/upload/v4?package=bash-$VERSION&token=&branch=$_BRANCH&commit=5d4123bcb99dd1bc9b5ae8b4271b39dbe4c3928b&build=&build_url=&tag=&slug=codecov%2Fcodecov-bash&service=&flags=&pr=&job=") <(echo "$res")
124+
# diff <(echo "https://codecov.io/upload/v4?package=bash-$VERSION&token=&branch=$_BRANCH&commit=5d4123bcb99dd1bc9b5ae8b4271b39dbe4c3928b&build=$_BUILD&build_url=&tag=&slug=codecov%2Fcodecov-bash&service=&flags=&pr=&job=$_JOB") <(echo "$res")
119125
# assertTrue 'Expected output differs.' $?
120126
# }
121127

@@ -176,14 +182,14 @@ function test_env_env () {
176182
function test_slug_opt () {
177183
reset
178184
res=$(./codecov -dr myowner/myrepo | grep "https://codecov.io/")
179-
diff <(echo "https://codecov.io/upload/v4?package=bash-$VERSION&token=&branch=$_BRANCH&commit=$_SHA&build=&build_url=&name=&tag=&slug=myowner%2Fmyrepo&service=&flags=&pr=&job=&cmd_args=d,r") <(echo "$res")
185+
diff <(echo "https://codecov.io/upload/v4?package=bash-$VERSION&token=&branch=$_BRANCH&commit=$_SHA&build=$_BUILD&build_url=&name=&tag=&slug=myowner%2Fmyrepo&service=&flags=&pr=&job=$_JOB&cmd_args=d,r") <(echo "$res")
180186
assertTrue 'Expected output differs.' $?
181187
}
182188

183189
function test_slug_env () {
184190
reset
185191
export CODECOV_SLUG="myowner/myrepo"
186-
assertURL "https://codecov.io/upload/v4?package=bash-$VERSION&token=&branch=$_BRANCH&commit=$TEST_DATA_GIT_COMMIT&build=&build_url=&name=&tag=&slug=myowner%2Fmyrepo&service=&flags=&pr=&job=&cmd_args=d,C"
192+
assertURL "https://codecov.io/upload/v4?package=bash-$VERSION&token=&branch=$_BRANCH&commit=$TEST_DATA_GIT_COMMIT&build=$_BUILD&build_url=&name=&tag=&slug=myowner%2Fmyrepo&service=&flags=&pr=&job=$_JOB&cmd_args=d,C"
187193
}
188194

189195
function test_gcov () {
@@ -201,37 +207,56 @@ function test_token_opt () {
201207
reset
202208
token="38cd42da-4df4-4760-a998-4ebeca536904"
203209
res=$(./codecov -d -t "$token" | grep "https://codecov.io/")
204-
diff <(echo "https://codecov.io/upload/v4?package=bash-$VERSION&token=$token&branch=$_BRANCH&commit=$_SHA&build=&build_url=&name=&tag=&slug=codecov%2Fcodecov-bash&service=&flags=&pr=&job=&cmd_args=d,t") <(echo "$res")
210+
diff <(echo "https://codecov.io/upload/v4?package=bash-$VERSION&token=$token&branch=$_BRANCH&commit=$_SHA&build=$_BUILD&build_url=&name=&tag=&slug=codecov%2Fcodecov-bash&service=&flags=&pr=&job=$_JOB&cmd_args=d,t") <(echo "$res")
205211
assertTrue 'Expected output differs.' $?
206212
}
207213

208214
function test_token_env () {
209215
reset
210216
res=$(CODECOV_TOKEN="38cd42da-4df4-4760-a998-4ebeca536904" ./codecov -d | grep "https://codecov.io/")
211-
diff <(echo "https://codecov.io/upload/v4?package=bash-$VERSION&token=$token&branch=$_BRANCH&commit=$_SHA&build=&build_url=&name=&tag=&slug=codecov%2Fcodecov-bash&service=&flags=&pr=&job=&cmd_args=d") <(echo "$res")
217+
diff <(echo "https://codecov.io/upload/v4?package=bash-$VERSION&token=$token&branch=$_BRANCH&commit=$_SHA&build=$_BUILD&build_url=&name=&tag=&slug=codecov%2Fcodecov-bash&service=&flags=&pr=&job=$_JOB&cmd_args=d") <(echo "$res")
212218
assertTrue 'Expected output differs.' $?
213219
}
214220

215221
function test_upload () {
216222
reset
217223
export CI="true"
218-
export CIRCLECI="true"
224+
225+
if [ "$_CIRCLECI" != "" ];
226+
then
227+
export CIRCLECI=$_CIRCLECI
228+
export CIRCLE_BUILD_NUM="${CIRCLE_BUILD_URL##*/}"
229+
elif [ "$_GITHUB_ACTIONS" != "" ];
230+
then
231+
export GITHUB_ACTIONS=$_GITHUB_ACTIONS
232+
export GITHUB_HEAD_REF=$_GITHUB_HEAD_REF
233+
fi
234+
219235
export VERSION=$VERSION
220-
export CIRCLE_BUILD_NUM="${CIRCLE_BUILD_URL##*/}"
221236
printenv
222237
res=$(./codecov -F test)
223-
assertContains "$res" "View reports at"
238+
echo "$res"
239+
assertContains "$res" "Reports have been successfully queued for processing at"
224240
assertContains "$res" "https://codecov.io/github/codecov/codecov-bash/commit/"
225241
}
226242

227243
function test_direct_upload () {
228244
reset
229245
export CI="true"
230-
export CIRCLECI="true"
246+
if [ "$_CIRCLECI" != "" ];
247+
then
248+
export CIRCLECI=$_CIRCLECI
249+
export CIRCLE_BUILD_NUM="${CIRCLE_BUILD_URL##*/}"
250+
elif [ "$_GITHUB_ACTIONS" != "" ];
251+
then
252+
export GITHUB_ACTIONS=$_GITHUB_ACTIONS
253+
export GITHUB_HEAD_REF=$_GITHUB_HEAD_REF
254+
fi
255+
231256
export VERSION=$VERSION
232-
export CIRCLE_BUILD_NUM="${CIRCLE_BUILD_URL##*/}"
233257
res=$(./codecov -z "tests/reports/direct_report.json" -F test)
234-
assertContains "$res" "View reports at"
258+
echo "$res"
259+
assertContains "$res" "Reports have been successfully queued for processing at"
235260
assertContains "$res" "https://codecov.io/github/codecov/codecov-bash/commit/"
236261
}
237262

@@ -376,8 +401,9 @@ function test_github_action () {
376401
export GITHUB_REPOSITORY="codecov/ci-repo"
377402
export GITHUB_RUN_ID="32402849"
378403
export GITHUB_SHA="$TEST_DATA_GIT_COMMIT"
404+
export GITHUB_WORKFLOW="test"
379405

380-
assertURL "https://codecov.io/upload/v4?package=bash-$VERSION&token=&branch=master&commit=$TEST_DATA_GIT_COMMIT&build=32402849&build_url=http%3A%2F%2Fgithub.com%2Fcodecov%2Fci-repo%2Factions%2Fruns%2F32402849&name=&tag=&slug=codecov%2Fci-repo&service=github-actions&flags=&pr=&job=&cmd_args=d,C"
406+
assertURL "https://codecov.io/upload/v4?package=bash-$VERSION&token=&branch=master&commit=$TEST_DATA_GIT_COMMIT&build=32402849&build_url=http%3A%2F%2Fgithub.com%2Fcodecov%2Fci-repo%2Factions%2Fruns%2F32402849&name=&tag=&slug=codecov%2Fci-repo&service=github-actions&flags=&pr=&job=test&cmd_args=d,C"
381407
}
382408

383409
function test_github_action_pr () {
@@ -389,8 +415,9 @@ function test_github_action_pr () {
389415
export GITHUB_REPOSITORY="codecov/ci-repo"
390416
export GITHUB_RUN_ID="32402849"
391417
export GITHUB_SHA="$TEST_DATA_GIT_COMMIT"
418+
export GITHUB_WORKFLOW="test"
392419

393-
assertURL "https://codecov.io/upload/v4?package=bash-$VERSION&token=&branch=patch-2&commit=$TEST_DATA_GIT_COMMIT&build=32402849&build_url=http%3A%2F%2Fgithub.com%2Fcodecov%2Fci-repo%2Factions%2Fruns%2F32402849&name=&tag=&slug=codecov%2Fci-repo&service=github-actions&flags=&pr=7&job=&cmd_args=d,C"
420+
assertURL "https://codecov.io/upload/v4?package=bash-$VERSION&token=&branch=patch-2&commit=$TEST_DATA_GIT_COMMIT&build=32402849&build_url=http%3A%2F%2Fgithub.com%2Fcodecov%2Fci-repo%2Factions%2Fruns%2F32402849&name=&tag=&slug=codecov%2Fci-repo&service=github-actions&flags=&pr=7&job=test&cmd_args=d,C"
394421
}
395422

396423
function test_github_action_emoji () {

0 commit comments

Comments
 (0)