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

Commit

Permalink
Add better logging for GitHub Actions (#410)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
thomasrockhu authored Feb 25, 2021
1 parent 0f41bb7 commit fb8663d
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 37 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
- name: Extract shunit
run: tar --strip-components=1 -zxvf tests/shunit2-2.1.8.tar.gz
- name: Install Ruby dependencies
run: |
gem install bashcov
gem install codecov
- name: Run tests
run: |
env -i PATH="$PATH"
bashcov tests/test
shasum --algorithm 1 --check ./SHA1SUM
shasum --algorithm 256 --check ./SHA256SUM
shasum --algorithm 512 --check ./SHA512SUM
- name: Upload Codecov
run:
bash ./codecov -Z
2 changes: 1 addition & 1 deletion SHA1SUM
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ce0cfa65fe07b458037474f838759211bcfc17d1 codecov
4dc681475a004f8cb8c1d8cf7c5aff3bd53d615b codecov
2 changes: 1 addition & 1 deletion SHA256SUM
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0526a487e02b0eb5f314cd23a4d5b54c4e2a3e20b68ed5a1f2517b76d5ea73b8 codecov
ae4058f2f1f0d3f62e6a95e288616c2a3e9c8a4929d8cefd69e6c36da81d0963 codecov
2 changes: 1 addition & 1 deletion SHA512SUM
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b9820fd0c585f98028fdbccf40ff440c96270e8779925257c8fbfa476523b9690fb97b3e1fc52e8a9c3667916b2a6493c76f36dcf700da48a1bd7ff647131b54 codecov
6d01cca237aaf0627165e71d384dfc4f63b538fe463138f078e9a54b434350cf008bcd7dbf489d80985156d53475f9c1bb41b425320372d5028942cde795b0a7 codecov
12 changes: 10 additions & 2 deletions codecov
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,14 @@ then
elif [ "$GITHUB_ACTIONS" != "" ];
then
say "$e==>$x GitHub Actions detected."
say " Env vars used:"
say " -> GITHUB_ACTIONS: ${GITHUB_ACTIONS}"
say " -> GITHUB_HEAD_REF: ${GITHUB_HEAD_REF}"
say " -> GITHUB_REF: ${GITHUB_REF}"
say " -> GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}"
say " -> GITHUB_RUN_ID: ${GITHUB_RUN_ID}"
say " -> GITHUB_SHA: ${GITHUB_SHA}"
say " -> GITHUB_WORKFLOW: ${GITHUB_WORKFLOW}"

# https://github.com/features/actions
service="github-actions"
Expand Down Expand Up @@ -1819,7 +1827,7 @@ else

if [ "$s3" != "" ];
then
say " ${g}->${x} View reports at ${b}$(echo "$res" | sed -n 1p)${x}"
say " ${g}->${x} Reports have been successfully queued for processing at ${b}$(echo "$res" | sed -n 1p)${x}"
exit 0
else
say " ${r}X>${x} Failed to upload"
Expand Down Expand Up @@ -1851,7 +1859,7 @@ else
status=$(echo "$res" | head -1 | cut -d' ' -f2)
if [ "$status" = "" ] || [ "$status" = "200" ];
then
say " View reports at ${b}$(echo "$res" | head -2 | tail -1)${x}"
say " Reports have been successfully queued for processing at ${b}$(echo "$res" | head -2 | tail -1)${x}"
exit 0
else
say " ${g}${res}${x}"
Expand Down
5 changes: 3 additions & 2 deletions env
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,12 @@ then
elif [ "$GITHUB_ACTIONS" != '' ]
then
add "GITHUB_ACTIONS"
add "GITHUB_HEAD_REF"
add "GITHUB_REF"
add "GITHUB_REPOSITORY"
add "GITHUB_HEAD_REF"
add "GITHUB_SHA"
add "GITHUB_RUN_ID"
add "GITHUB_SHA"
add "GITHUB_WORKFLOW"

elif [ "$SYSTEM_TEAMFOUNDATIONSERVERURI" != "" ];
then
Expand Down
12 changes: 1 addition & 11 deletions tests/env
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,7 @@ export CI_PROJECT_DIR=""
export CI_SERVER_NAME=""
export CI_SERVER_NAME=""
export CI=""
export CIRCLE_BRANCH=""
export CIRCLE_BUILD_NUM=""
export CIRCLE_NODE_INDEX=""
export CIRCLE_PR_NUMBER=""
export CIRCLE_PROJECT_REPONAME=""
export CIRCLE_PROJECT_USERNAME=""
export CIRCLE_SHA1=""
export CIRCLECI=""
export CODECOV_ENV=""
export CODECOV_SLUG=""
Expand All @@ -62,11 +56,6 @@ export ghprbPullId=""
export ghprbSourceBranch=""
export GIT_BRANCH=""
export GIT_COMMIT=""
export GITHUB_REF=""
export GITHUB_HEAD_REF=""
export GITHUB_REPOSITORY=""
export GITHUB_RUN_ID=""
export GITHUB_SHA=""
export GITLAB_CI=""
export JENKINS_URL=""
export MAGNUM=""
Expand Down Expand Up @@ -125,6 +114,7 @@ export BITBUCKET_REPO_SLUG=""
export BITBUCKET_PR_ID=""
export BITBUCKET_COMMIT=""
export GITHUB_ACTIONS=""
export GITHUB_HEAD_REF=""
export CODEBUILD_CI=""
export CODEBUILD_WEBHOOK_HEAD_REF=""
export CODEBUILD_RESOLVED_SOURCE_VERSION=""
Expand Down
65 changes: 46 additions & 19 deletions tests/test
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ VERSION=$(grep "VERSION=" codecov | tr -d 'VERSION=' | tr -d '"')
_SHA=$(git rev-parse HEAD)
_BRANCH=$(git rev-parse --abbrev-ref HEAD)
_BRANCH=$(urlencode "$_BRANCH")
_BUILD=$("${GITHUB_RUN_ID}" | ${CIRCLE_BUILD_NUM} | '')
_JOB=$(urlencode "${GITHUB_WORKFLOW}" | '')
if [ "$_BRANCH" = "HEAD" ];
then
_BRANCH=""
fi

_CIRCLECI=$CIRCLECI
_GITHUB_ACTIONS=$GITHUB_ACTIONS
_GITHUB_HEAD_REF=$GITHUB_HEAD_REF

export PATH=$PWD:$PATH

function reset () {
Expand Down Expand Up @@ -64,21 +70,21 @@ function test_fixes () {
function test_url_opt () {
reset
res=$(./codecov -d -u http://example.com | grep "http://example.com/")
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")
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")
assertTrue 'Expected output differs.' $?
}

function test_url_env () {
reset
res=$(CODECOV_URL="http://other.com" ./codecov -d | grep "http://other.com/")
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")
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")
assertTrue 'Expected output differs.' $?
}

function test_flags_opt () {
reset
res=$(./codecov -d -F f1 -F f2 | grep "https://codecov.io/")
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")
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")
assertTrue 'Expected output differs.' $?
}

Expand All @@ -90,7 +96,7 @@ function test_flags_opt () {
# slug: owner/repo
# ' > codecov.yml
# res=$(./codecov -d | grep "http://other.com/")
# 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")
# 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")
# assertTrue 'Expected output differs.' $?
# }
#
Expand All @@ -100,22 +106,22 @@ function test_flags_opt () {
# token: uuid
# ' > tests/.codecov.yml
# res=$(./codecov -d | grep "https://codecov.io/")
# 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")
# 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")
# assertTrue 'Expected output differs.' $?
# }

function test_build_arg () {
reset
res=$(./codecov -d -b 1.6 | grep "https://codecov.io/")
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")
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")
assertTrue 'Expected output differs.' $?
}

# function test_changes_merge_commit () {
# reset
# git commit --amend -m 'Merge 5d4123bcb99dd1bc9b5ae8b4271b39dbe4c3928b into 2f85ca252d69d6c52484f0c4b2e8500498228398'
# res=$(./codecov -d -b 1.6 | grep "https://codecov.io/")
# 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")
# 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")
# assertTrue 'Expected output differs.' $?
# }

Expand Down Expand Up @@ -176,14 +182,14 @@ function test_env_env () {
function test_slug_opt () {
reset
res=$(./codecov -dr myowner/myrepo | grep "https://codecov.io/")
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")
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")
assertTrue 'Expected output differs.' $?
}

function test_slug_env () {
reset
export CODECOV_SLUG="myowner/myrepo"
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"
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"
}

function test_gcov () {
Expand All @@ -201,37 +207,56 @@ function test_token_opt () {
reset
token="38cd42da-4df4-4760-a998-4ebeca536904"
res=$(./codecov -d -t "$token" | grep "https://codecov.io/")
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")
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")
assertTrue 'Expected output differs.' $?
}

function test_token_env () {
reset
res=$(CODECOV_TOKEN="38cd42da-4df4-4760-a998-4ebeca536904" ./codecov -d | grep "https://codecov.io/")
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")
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")
assertTrue 'Expected output differs.' $?
}

function test_upload () {
reset
export CI="true"
export CIRCLECI="true"

if [ "$_CIRCLECI" != "" ];
then
export CIRCLECI=$_CIRCLECI
export CIRCLE_BUILD_NUM="${CIRCLE_BUILD_URL##*/}"
elif [ "$_GITHUB_ACTIONS" != "" ];
then
export GITHUB_ACTIONS=$_GITHUB_ACTIONS
export GITHUB_HEAD_REF=$_GITHUB_HEAD_REF
fi

export VERSION=$VERSION
export CIRCLE_BUILD_NUM="${CIRCLE_BUILD_URL##*/}"
printenv
res=$(./codecov -F test)
assertContains "$res" "View reports at"
echo "$res"
assertContains "$res" "Reports have been successfully queued for processing at"
assertContains "$res" "https://codecov.io/github/codecov/codecov-bash/commit/"
}

function test_direct_upload () {
reset
export CI="true"
export CIRCLECI="true"
if [ "$_CIRCLECI" != "" ];
then
export CIRCLECI=$_CIRCLECI
export CIRCLE_BUILD_NUM="${CIRCLE_BUILD_URL##*/}"
elif [ "$_GITHUB_ACTIONS" != "" ];
then
export GITHUB_ACTIONS=$_GITHUB_ACTIONS
export GITHUB_HEAD_REF=$_GITHUB_HEAD_REF
fi

export VERSION=$VERSION
export CIRCLE_BUILD_NUM="${CIRCLE_BUILD_URL##*/}"
res=$(./codecov -z "tests/reports/direct_report.json" -F test)
assertContains "$res" "View reports at"
echo "$res"
assertContains "$res" "Reports have been successfully queued for processing at"
assertContains "$res" "https://codecov.io/github/codecov/codecov-bash/commit/"
}

Expand Down Expand Up @@ -376,8 +401,9 @@ function test_github_action () {
export GITHUB_REPOSITORY="codecov/ci-repo"
export GITHUB_RUN_ID="32402849"
export GITHUB_SHA="$TEST_DATA_GIT_COMMIT"
export GITHUB_WORKFLOW="test"

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"
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"
}

function test_github_action_pr () {
Expand All @@ -389,8 +415,9 @@ function test_github_action_pr () {
export GITHUB_REPOSITORY="codecov/ci-repo"
export GITHUB_RUN_ID="32402849"
export GITHUB_SHA="$TEST_DATA_GIT_COMMIT"
export GITHUB_WORKFLOW="test"

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"
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"
}

function test_github_action_emoji () {
Expand Down

0 comments on commit fb8663d

Please sign in to comment.