2021-01-13 21:53:19 +03:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# [description]
|
|
|
|
# Set a status with a given name to the specified commit.
|
|
|
|
#
|
|
|
|
# [usage]
|
2024-07-31 16:36:20 +03:00
|
|
|
# set-commit-status.sh <NAME> <STATUS> <SHA>
|
2021-01-13 21:53:19 +03:00
|
|
|
#
|
|
|
|
# NAME: Name of status.
|
|
|
|
# Status with existing name overwrites a previous one.
|
|
|
|
#
|
|
|
|
# STATUS: Status to be set.
|
|
|
|
# Can be "error", "failure", "pending" or "success".
|
|
|
|
#
|
|
|
|
# SHA: SHA of a commit to set a status on.
|
|
|
|
|
2024-04-23 03:28:51 +03:00
|
|
|
set -e -E -u -o pipefail
|
2021-01-13 21:53:19 +03:00
|
|
|
|
|
|
|
if [ -z "$GITHUB_ACTIONS" ]; then
|
|
|
|
echo "Must be run inside GitHub Actions CI"
|
2024-02-10 07:42:00 +03:00
|
|
|
exit 1
|
2021-01-13 21:53:19 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $# -ne 3 ]; then
|
|
|
|
echo "Usage: $0 <NAME> <STATUS> <SHA>"
|
2024-02-10 07:42:00 +03:00
|
|
|
exit 1
|
2021-01-13 21:53:19 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
name=$1
|
|
|
|
|
|
|
|
status=$2
|
|
|
|
status=${status/error/failure}
|
|
|
|
status=${status/cancelled/failure}
|
|
|
|
status=${status/timed_out/failure}
|
|
|
|
status=${status/in_progress/pending}
|
|
|
|
status=${status/queued/pending}
|
|
|
|
|
|
|
|
sha=$3
|
|
|
|
|
|
|
|
data=$(
|
|
|
|
jq -n \
|
2024-09-03 05:03:20 +03:00
|
|
|
--arg state "${status}" \
|
2021-01-13 21:53:19 +03:00
|
|
|
--arg url "${GITHUB_SERVER_URL}/microsoft/LightGBM/actions/runs/${GITHUB_RUN_ID}" \
|
2024-09-03 05:03:20 +03:00
|
|
|
--arg name "${name}" \
|
2021-01-13 21:53:19 +03:00
|
|
|
'{"state":$state,"target_url":$url,"context":$name}'
|
|
|
|
)
|
|
|
|
|
|
|
|
curl -sL \
|
|
|
|
-X POST \
|
|
|
|
-H "Accept: application/vnd.github.v3+json" \
|
|
|
|
-H "Authorization: token $SECRETS_WORKFLOW" \
|
|
|
|
-d "$data" \
|
|
|
|
"${GITHUB_API_URL}/repos/microsoft/LightGBM/statuses/$sha"
|