You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@yetus.apache.org by aw...@apache.org on 2020/09/23 14:19:09 UTC
[yetus] branch main updated: YETUS-994. Add GitHub Status as a
report type (#128)
This is an automated email from the ASF dual-hosted git repository.
aw pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/yetus.git
The following commit(s) were added to refs/heads/main by this push:
new ea9a42d YETUS-994. Add GitHub Status as a report type (#128)
ea9a42d is described below
commit ea9a42d1d57b2b49abd459d937e436eb9cb5ab71
Author: Allen Wittenauer <aw...@apache.org>
AuthorDate: Wed Sep 23 07:18:49 2020 -0700
YETUS-994. Add GitHub Status as a report type (#128)
---
.github/workflows/yetus.yml | 2 +
precommit/src/main/shell/robots.d/circleci.sh | 12 +-
precommit/src/main/shell/robots.d/cirrusci.sh | 12 +-
precommit/src/main/shell/robots.d/githubactions.sh | 28 +-
precommit/src/main/shell/robots.d/jenkins.sh | 7 +
precommit/src/main/shell/robots.d/travisci.sh | 4 +
precommit/src/main/shell/test-patch.d/github.sh | 381 +++++++++++++++------
7 files changed, 327 insertions(+), 119 deletions(-)
diff --git a/.github/workflows/yetus.yml b/.github/workflows/yetus.yml
index 1b76f06..7948808 100644
--- a/.github/workflows/yetus.yml
+++ b/.github/workflows/yetus.yml
@@ -44,10 +44,12 @@ jobs:
--junit-report-xml="${GITHUB_WORKSPACE}/out/junit-report.xml"
--linecomments=''
--proclimit=2000
+ --bugcomments=console,briefreport,github,htmlout,junit
--archive-list="checkstyle-errors.xml,spotbugsXml.xml"
--plugins=all
--tests-filter=checkstyle,javadoc,rubocop,test4tests
--docker-cache-from=apache/yetus-base:main
+ --github-token="${{ secrets.GITHUB_TOKEN }}"
- name: Artifact output
if: ${{ always() }}
uses: actions/upload-artifact@v2
diff --git a/precommit/src/main/shell/robots.d/circleci.sh b/precommit/src/main/shell/robots.d/circleci.sh
index 3e74d34..b5b6153 100755
--- a/precommit/src/main/shell/robots.d/circleci.sh
+++ b/precommit/src/main/shell/robots.d/circleci.sh
@@ -49,15 +49,19 @@ if [[ "${CIRCLECI}" = true ]] &&
fi
add_docker_env \
- CIRCLECI \
CIRCLE_BRANCH \
CIRCLE_BUILD_NUM \
+ CIRCLE_PROJECT_REPONAME \
+ CIRCLE_PROJECT_USERNAME \
CIRCLE_PULL_REQUEST \
CIRCLE_PULL_REQUESTS \
- CIRCLE_PROJECT_USERNAME \
- CIRCLE_PROJECT_REPONAME \
CIRCLE_REPOSITORY_URL \
- CIRCLE_TOKEN
+ CIRCLE_SHA1 \
+ CIRCLE_TOKEN \
+ CIRCLECI
+
+ # shellcheck disable=SC2034
+ GITHUB_SHA=${CIRCLE_SHA1}
yetus_add_array_element EXEC_MODES Circle_CI
fi
diff --git a/precommit/src/main/shell/robots.d/cirrusci.sh b/precommit/src/main/shell/robots.d/cirrusci.sh
index e1421d2..a5e6aab 100755
--- a/precommit/src/main/shell/robots.d/cirrusci.sh
+++ b/precommit/src/main/shell/robots.d/cirrusci.sh
@@ -48,14 +48,18 @@ if [[ "${CIRRUS_CI}" == true ]] &&
add_docker_env \
CI \
+ CIRRUS_BASE_SHA \
+ CIRRUS_BRANCH \
+ CIRRUS_BUILD_ID
+ CIRRUS_BUILD_ID \
CIRRUS_CI \
CIRRUS_DEFAULT_BRANCH \
- CIRRUS_BUILD_ID \
CIRRUS_PR \
- CIRRUS_BRANCH \
CIRRUS_REPO_FULL_NAME \
- CIRRUS_TASK_ID \
- CIRRUS_BUILD_ID
+ CIRRUS_TASK_ID
+
+ # shellcheck disable=SC2034
+ GITHUB_SHA=${CIRRUS_BASE_SHA}
# shellcheck disable=SC2034
BUILD_URL="https://cirrus-ci.com/task/${CIRRUS_TASK_ID}"
diff --git a/precommit/src/main/shell/robots.d/githubactions.sh b/precommit/src/main/shell/robots.d/githubactions.sh
index f59eb85..f8ef479 100755
--- a/precommit/src/main/shell/robots.d/githubactions.sh
+++ b/precommit/src/main/shell/robots.d/githubactions.sh
@@ -32,6 +32,15 @@ if [[ "${GITHUB_ACTIONS}" == true ]] &&
ROBOTTYPE=githubactions
# shellcheck disable=SC2034
+ BUILD_URL="https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
+
+ # shellcheck disable=SC2034
+ BUILD_URL_CONSOLE=/
+
+ # shellcheck disable=SC2034
+ CONSOLE_USE_BUILD_URL=true
+
+ # shellcheck disable=SC2034
GITHUB_REPO="${GITHUB_REPOSITORY}"
if [[ "${GITHUB_EVENT_NAME}" == push ]]; then
@@ -51,20 +60,15 @@ if [[ "${GITHUB_ACTIONS}" == true ]] &&
fi
add_docker_env \
- GITHUB_WORKSPACE \
- GITHUB_SHA \
- GITHUB_REPOSITORY \
- GITHUB_RUN_NUMBER \
- GITHUB_REF \
GITHUB_ACTIONS \
+ GITHUB_BASE_REF \
GITHUB_EVENT_NAME \
- GITHUB_BASE_REF
-
- # shellcheck disable=SC2034
- BUILD_URL_CONSOLE=console
-
- # shellcheck disable=SC2034
- CONSOLE_USE_BUILD_URL=true
+ GITHUB_REF \
+ GITHUB_REPOSITORY \
+ GITHUB_RUN_NUMBER \
+ GITHUB_SHA \
+ GITHUB_TOKEN \
+ GITHUB_WORKSPACE
if [[ -d ${BASEDIR}/.git ]]; then
echo "Updating the local git repo to include all branches/tags:"
diff --git a/precommit/src/main/shell/robots.d/jenkins.sh b/precommit/src/main/shell/robots.d/jenkins.sh
index 2d52945..813655c 100755
--- a/precommit/src/main/shell/robots.d/jenkins.sh
+++ b/precommit/src/main/shell/robots.d/jenkins.sh
@@ -99,9 +99,16 @@ if [[ -n "${JENKINS_URL}" && -n "${EXECUTOR_NUMBER}" ]] &&
EXECUTOR_NUMBER \
ghprbPullId \
ghprbPullLink \
+ GIT_COMMIT \
GIT_URL \
JENKINS_URL
+ # Enable writes to GitHub Statuses
+ if [[ -z "${GITHUB_SHA}" ]]; then
+ # shellcheck disable=SC2034
+ GITHUB_SHA=${GIT_COMMIT}
+ fi
+
yetus_add_array_element EXEC_MODES Jenkins
fi
diff --git a/precommit/src/main/shell/robots.d/travisci.sh b/precommit/src/main/shell/robots.d/travisci.sh
index 7b230b0..7f306fd 100755
--- a/precommit/src/main/shell/robots.d/travisci.sh
+++ b/precommit/src/main/shell/robots.d/travisci.sh
@@ -46,12 +46,16 @@ if [[ "${TRAVIS}" == true ]] &&
# shellcheck disable=SC2034
GITHUB_REPO=${TRAVIS_REPO_SLUG}
+ # shellcheck disable=SC2034
+ GITHUB_SHA=${TRAVIS_PULL_REQUEST_SHA}
+
add_docker_env \
TRAVIS \
TRAVIS_BRANCH \
TRAVIS_BUILD_ID \
TRAVIS_BUILD_WEB_URL \
TRAVIS_PULL_REQUEST \
+ TRAVIS_PULL_REQUEST_SHA \
TRAVIS_REPO_SLUG
# shellcheck disable=SC2034
diff --git a/precommit/src/main/shell/test-patch.d/github.sh b/precommit/src/main/shell/test-patch.d/github.sh
index 95c0ef3..b7a3308 100755
--- a/precommit/src/main/shell/test-patch.d/github.sh
+++ b/precommit/src/main/shell/test-patch.d/github.sh
@@ -594,6 +594,177 @@ function github_write_comment
return ${retval}
}
+# @description Print out the finished details to the Github PR
+# @audience private
+# @stability evolving
+# @replaceable no
+# @param runresult
+# function github_finalreport
+# {
+# declare result=$1
+# declare i
+# declare commentfile=${PATCH_DIR}/gitcommentfile.$$
+# declare comment
+# declare url
+# declare ela
+# declare subs
+# declare logfile
+# declare calctime
+# declare vote
+# declare emoji
+
+# rm "${commentfile}" 2>/dev/null
+
+# if [[ ${ROBOT} = "false"
+# || -z ${GITHUB_ISSUE} ]] ; then
+# return 0
+# fi
+
+# url=$(get_artifact_url)
+
+# big_console_header "Adding comment to Github"
+
+# if [[ ${result} == 0 ]]; then
+# echo ":confetti_ball: **+1 overall**" >> "${commentfile}"
+# else
+# echo ":broken_heart: **-1 overall**" >> "${commentfile}"
+# fi
+# printf '\n\n\n\n' >> "${commentfile}"
+
+# i=0
+# until [[ ${i} -ge ${#TP_HEADER[@]} ]]; do
+# printf '%s\n\n' "${TP_HEADER[${i}]}" >> "${commentfile}"
+# ((i=i+1))
+# done
+
+# {
+# printf '\n\n'
+# echo "| Vote | Subsystem | Runtime | Logfile | Comment |"
+# echo "|:----:|----------:|--------:|:--------:|:-------:|"
+# } >> "${commentfile}"
+
+# i=0
+# until [[ ${i} -ge ${#TP_VOTE_TABLE[@]} ]]; do
+# ourstring=$(echo "${TP_VOTE_TABLE[${i}]}" | tr -s ' ')
+# vote=$(echo "${ourstring}" | cut -f2 -d\| | tr -d ' ')
+# subs=$(echo "${ourstring}" | cut -f3 -d\|)
+# ela=$(echo "${ourstring}" | cut -f4 -d\|)
+# calctime=$(clock_display "${ela}")
+# logfile=$(echo "${ourstring}" | cut -f5 -d\| | tr -d ' ')
+# comment=$(echo "${ourstring}" | cut -f6 -d\|)
+
+# if [[ "${vote}" = "H" ]]; then
+# echo "|||| _${comment}_ |" >> "${commentfile}"
+# ((i=i+1))
+# continue
+# fi
+
+# if [[ ${GITHUB_USE_EMOJI_VOTE} == true ]]; then
+# emoji=""
+# case ${vote} in
+# 1|"+1")
+# emoji="+1 :green_heart:"
+# ;;
+# -1)
+# emoji="-1 :x:"
+# ;;
+# 0)
+# emoji="+0 :ok:"
+# ;;
+# -0)
+# emoji="-0 :warning:"
+# ;;
+# H)
+# # this never gets called (see above) but this is here so others know the color is taken
+# emoji=""
+# ;;
+# *)
+# # usually this should not happen but let's keep the old vote result if it happens
+# emoji=${vote}
+# ;;
+# esac
+# else
+# emoji="${vote}"
+# fi
+
+# if [[ -n "${logfile}" ]]; then
+# t1=${logfile/@@BASE@@/}
+# t2=$(echo "${logfile}" | "${SED}" -e "s,@@BASE@@,${url},g")
+# t2="[${t1}](${t2})"
+# else
+# t2=""
+# fi
+
+# printf '| %s | %s | %s | %s | %s |\n' \
+# "${emoji}" \
+# "${subs}" \
+# "${calctime}" \
+# "${t2}" \
+# "${comment}" \
+# >> "${commentfile}"
+
+# ((i=i+1))
+# done
+
+# if [[ ${#TP_TEST_TABLE[@]} -gt 0 ]]; then
+# {
+# printf '\n\n'
+# echo "| Reason | Tests |"
+# echo "|-------:|:------|"
+# } >> "${commentfile}"
+# i=0
+# until [[ ${i} -ge ${#TP_TEST_TABLE[@]} ]]; do
+# echo "${TP_TEST_TABLE[${i}]}" >> "${commentfile}"
+# ((i=i+1))
+# done
+# fi
+
+# {
+# printf '\n\n'
+# echo "| Subsystem | Report/Notes |"
+# echo "|----------:|:-------------|"
+# } >> "${commentfile}"
+
+# i=0
+# until [[ $i -ge ${#TP_FOOTER_TABLE[@]} ]]; do
+# comment=$(echo "${TP_FOOTER_TABLE[${i}]}" | "${SED}" -e "s,@@BASE@@,${url},g")
+# printf '%s\n' "${comment}" >> "${commentfile}"
+# ((i=i+1))
+# done
+# printf '\n\nThis message was automatically generated.\n\n' >> "${commentfile}"
+
+# github_write_comment "${commentfile}"
+# }
+
+## @description Write a github status
+## @audience private
+## @stability evolving
+## @replaceable no
+## @param runresult
+function github_status_write()
+{
+ declare filename=$1
+ declare -a githubauth
+
+ if [[ -n "${GITHUB_TOKEN}" ]]; then
+ githubauth=(-H "Authorization: token ${GITHUB_TOKEN}")
+ elif [[ -n "${GITHUB_USER}"
+ && -n "${GITHUB_PASSWD}" ]]; then
+ githubauth=(-u "${GITHUB_USER}:${GITHUB_PASSWD}")
+ else
+ echo "githubstatus-report: no credentials provided to write statuses."
+ return 0
+ fi
+
+ "${CURL}" --silent --fail -X POST \
+ -H "Accept: application/vnd.github.v3.full+json" \
+ -H "Content-Type: application/json" \
+ "${githubauth[@]}" \
+ -d @"${filename}" \
+ --location \
+ "${GITHUB_API_URL}/repos/${GITHUB_REPO}/statuses/${GITHUB_SHA}"
+}
+
## @description Print out the finished details to the Github PR
## @audience private
## @stability evolving
@@ -602,136 +773,148 @@ function github_write_comment
function github_finalreport
{
declare result=$1
- declare i
- declare commentfile=${PATCH_DIR}/gitcommentfile.$$
+ declare tempfile="${PATCH_DIR}/ghstatus.$$.${RANDOM}"
+ declare warnings=false
+ declare foundlogs=false
+ declare url
+ declare logurl
declare comment
declare url
- declare ela
declare subs
declare logfile
- declare calctime
declare vote
- declare emoji
+ declare ourstring
+ declare -a githubauth
+ declare -i i=0
+ declare header
+
+ big_console_header "Adding GitHub Statuses"
- rm "${commentfile}" 2>/dev/null
+ if [[ -n "${GITHUB_TOKEN}" ]]; then
+ githubauth=(-H "Authorization: token ${GITHUB_TOKEN}")
+ elif [[ -n "${GITHUB_USER}"
+ && -n "${GITHUB_PASSWD}" ]]; then
+ githubauth=(-u "${GITHUB_USER}:${GITHUB_PASSWD}")
+ else
+ echo "githubstatus-report: no credentials provided to write statuses."
+ return 0
+ fi
- if [[ ${ROBOT} = "false"
- || -z ${GITHUB_ISSUE} ]] ; then
+ if [[ -z "${GITHUB_SHA}" ]]; then
+ echo "Unknown GITHUB_SHA defined. Skipping."
return 0
fi
url=$(get_artifact_url)
- big_console_header "Adding comment to Github"
-
- if [[ ${result} == 0 ]]; then
- echo ":confetti_ball: **+1 overall**" >> "${commentfile}"
+ if [[ "${ROBOTTYPE}" ]]; then
+ header="Apache Yetus(${ROBOTTYPE})"
else
- echo ":broken_heart: **-1 overall**" >> "${commentfile}"
+ header="Apache Yetus"
fi
- printf '\n\n\n\n' >> "${commentfile}"
- i=0
- until [[ ${i} -ge ${#TP_HEADER[@]} ]]; do
- printf '%s\n\n' "${TP_HEADER[${i}]}" >> "${commentfile}"
- ((i=i+1))
- done
+ # Customize the message based upon type of passing:
+ # - if there were no warnings, then just put a single message
+ # - if there were warningss, but no logs, then just mention warnings
+ # - if there were warnings and logs, handle in the next section
+ if [[ "${result}" == 0 ]]; then
+ i=0
+ until [[ ${i} -eq ${#TP_VOTE_TABLE[@]} ]]; do
+ ourstring=$(echo "${TP_VOTE_TABLE[${i}]}" | tr -s ' ')
+ vote=$(echo "${ourstring}" | cut -f2 -d\| | tr -d ' ')
+
+ if [[ "${vote}" == "-0" ]]; then
+ warnings=true
+ logfile=$(echo "${ourstring}" | cut -f5 -d\| | tr -d ' ')
+
+ if [[ -n "${logfile}" ]]; then
+ foundlogs=true
+ break
+ fi
+ fi
+ ((i=i+1))
+ done
- {
- printf '\n\n'
- echo "| Vote | Subsystem | Runtime | Logfile | Comment |"
- echo "|:----:|----------:|--------:|:--------:|:-------:|"
- } >> "${commentfile}"
+ # did not find any logs, so just give a simple success status
+ if [[ ${foundlogs} == false ]]; then
+ if [[ ${warnings} == false ]]; then
+ # build our REST post
+ {
+ echo "{\"state\": \"success\", "
+ echo "\"target_url\": \"${BUILD_URL}${BUILD_URL_CONSOLE}\","
+ echo "\"description\": \"passed\","
+ echo "\"context\":\"${header}\"}"
+ } > "${tempfile}"
+ elif [[ ${warnings} == true ]]; then
+ # build our REST post
+ {
+ echo "{\"state\": \"success\", "
+ echo "\"target_url\": \"${BUILD_URL}${BUILD_URL_CONSOLE}\","
+ echo "\"description\": \"passed with warnings\","
+ echo "\"context\":\"${header}\"}"
+ } > "${tempfile}"
+ fi
+ github_status_write "${tempfile}"
+ rm "${tempfile}"
+ return 0
+ fi
+ fi
+
+ # from here on, success w/logs or failure.
+ # give a separate status for each:
+ # - failure
+ # - failure w/log
+ # - successs w/warning log
i=0
- until [[ ${i} -ge ${#TP_VOTE_TABLE[@]} ]]; do
+ until [[ ${i} -eq ${#TP_VOTE_TABLE[@]} ]]; do
ourstring=$(echo "${TP_VOTE_TABLE[${i}]}" | tr -s ' ')
vote=$(echo "${ourstring}" | cut -f2 -d\| | tr -d ' ')
subs=$(echo "${ourstring}" | cut -f3 -d\|)
- ela=$(echo "${ourstring}" | cut -f4 -d\|)
- calctime=$(clock_display "${ela}")
logfile=$(echo "${ourstring}" | cut -f5 -d\| | tr -d ' ')
comment=$(echo "${ourstring}" | cut -f6 -d\|)
if [[ "${vote}" = "H" ]]; then
- echo "|||| _${comment}_ |" >> "${commentfile}"
((i=i+1))
continue
fi
- if [[ ${GITHUB_USE_EMOJI_VOTE} == true ]]; then
- emoji=""
- case ${vote} in
- 1|"+1")
- emoji="+1 :green_heart:"
- ;;
- -1)
- emoji="-1 :x:"
- ;;
- 0)
- emoji="+0 :ok:"
- ;;
- -0)
- emoji="-0 :warning:"
- ;;
- H)
- # this never gets called (see above) but this is here so others know the color is taken
- emoji=""
- ;;
- *)
- # usually this should not happen but let's keep the old vote result if it happens
- emoji=${vote}
- ;;
- esac
- else
- emoji="${vote}"
- fi
+ # GitHub needs more statuses to cover everything yetus does :(
+ case ${vote} in
+ -1)
+ status="error"
+ ;;
+ *)
+ status="success"
+ ;;
+ esac
- if [[ -n "${logfile}" ]]; then
- t1=${logfile/@@BASE@@/}
- t2=$(echo "${logfile}" | "${SED}" -e "s,@@BASE@@,${url},g")
- t2="[${t1}](${t2})"
- else
- t2=""
+ logurl=${BUILD_URL}${BUILD_URL_CONSOLE}
+ if [[ "${url}" =~ ^http ]]; then
+ if [[ -n "${logfile}" ]]; then
+ logurl=$(echo "${logfile}" | "${SED}" -e "s,@@BASE@@,${url},g")
+ fi
fi
- printf '| %s | %s | %s | %s | %s |\n' \
- "${emoji}" \
- "${subs}" \
- "${calctime}" \
- "${t2}" \
- "${comment}" \
- >> "${commentfile}"
-
- ((i=i+1))
- done
-
- if [[ ${#TP_TEST_TABLE[@]} -gt 0 ]]; then
- {
- printf '\n\n'
- echo "| Reason | Tests |"
- echo "|-------:|:------|"
- } >> "${commentfile}"
- i=0
- until [[ ${i} -ge ${#TP_TEST_TABLE[@]} ]]; do
- echo "${TP_TEST_TABLE[${i}]}" >> "${commentfile}"
- ((i=i+1))
- done
- fi
-
- {
- printf '\n\n'
- echo "| Subsystem | Report/Notes |"
- echo "|----------:|:-------------|"
- } >> "${commentfile}"
-
- i=0
- until [[ $i -ge ${#TP_FOOTER_TABLE[@]} ]]; do
- comment=$(echo "${TP_FOOTER_TABLE[${i}]}" | "${SED}" -e "s,@@BASE@@,${url},g")
- printf '%s\n' "${comment}" >> "${commentfile}"
+ if [[ ${status} == "success" && -n "${logfile}" ]]; then
+ {
+ echo "{\"state\": \"${status}\", "
+ echo "\"target_url\": \"${logurl}\","
+ echo "\"description\": \"${comment}\","
+ echo "\"context\":\"${header} warning: ${subs}\"}"
+ } > "${tempfile}"
+ github_status_write "${tempfile}"
+ rm "${tempfile}"
+ elif [[ ${status} == "error" ]]; then
+ {
+ echo "{\"state\": \"${status}\", "
+ echo "\"target_url\": \"${logurl}\","
+ echo "\"description\": \"${comment}\","
+ echo "\"context\":\"${header} error: ${subs}\"}"
+ } > "${tempfile}"
+ github_status_write "${tempfile}"
+ rm "${tempfile}"
+ fi
((i=i+1))
done
- printf '\n\nThis message was automatically generated.\n\n' >> "${commentfile}"
-
- github_write_comment "${commentfile}"
-}
+}
\ No newline at end of file