@@ -13,15 +13,25 @@ runs:
13
13
shell : bash
14
14
env :
15
15
GH_TOKEN : ${{ github.token }}
16
+ GITHUB_RUN_ID : ${{ github.run_id }}
17
+ GITHUB_REPOSITORY : ${{ github.repository }}
18
+ GITHUB_WORKFLOW_REF : ${{ github.workflow_ref }}
19
+ GITHUB_SERVER_URL : ${{ github.server_url }}
20
+ GITHUB_REF_NAME : ${{ github.ref_name }}
21
+ GITHUB_EVENT_SENDER_LOGIN : ${{ github.event.sender.login }}
22
+ GITHUB_EVENT_SENDER_HTML_URL : ${{ github.event.sender.html_url }}
23
+ GITHUB_EVENT_PULL_REQUEST_HTML_URL : ${{ github.event.pull_request.html_url }}
24
+ GITHUB_EVENT_PULL_REQUEST_NUMBER : ${{ github.event.pull_request.number }}
25
+ GITHUB_EVENT_HEAD_COMMIT_URL : ${{ github.event.head_commit.url }}
16
26
run : |
17
27
# Pull additional details from GitHub API
18
- json=$(gh run view ${{ github.run_id }} -R ${{ github.repository }} --json name,number,displayTitle,url,headSha,jobs)
28
+ json=$(gh run view "$GITHUB_RUN_ID" -R "$GITHUB_REPOSITORY" --json name,number,displayTitle,url,headSha,jobs)
19
29
# Get sanitized display title (usually a commit message or PR title) from GitHub API
20
30
displayTitle=$(echo $json | jq -r .displayTitle | sed 's/"/\\"/g')
21
31
# Parse workflow yaml file name from full ref name
22
- workflow=$(echo ${{ github.workflow_ref }} | awk -F'/|@' '{ print $5 }')
32
+ workflow=$(echo "$GITHUB_WORKFLOW_REF" | awk -F'/|@' '{ print $5 }')
23
33
# Build workflow URL with branch name
24
- workflowUrl="${{ github.server_url }} /${{ github.repository }} /actions/workflows/${workflow}?query=branch%3A${{ github.ref_name } }"
34
+ workflowUrl="${GITHUB_SERVER_URL} /${GITHUB_REPOSITORY} /actions/workflows/${workflow}?query=branch%3A${GITHUB_REF_NAME }"
25
35
# Get workflow name from GitHub API (also available as "github.workflow")
26
36
workflowName=$(echo $json | jq -r .name | sed 's/"/\\"/g')
27
37
# Get workflow run URL from GitHub API
@@ -36,15 +46,15 @@ runs:
36
46
# Workflow info with link to all workflow runs for this branch
37
47
workflowInfo="<${workflowUrl}|${workflowName}> #${runNumber}"
38
48
# Determine run info, with either pull request, commit or manual run info
39
- if [ ! -z "${{ github.event.sender.login } }" ] ; then
40
- author="${{ github.event.sender.login } }"
41
- authorUrl="${{ github.event.sender.html_url } }"
42
- if [ ! -z "${{ github.event.pull_request.html_url } }" ] ; then
43
- prNumber="${{ github.event.pull_request.number } }"
44
- prUrl="${{ github.event.pull_request.html_url } }"
49
+ if [ ! -z "${GITHUB_EVENT_SENDER_LOGIN }" ] ; then
50
+ author="${GITHUB_EVENT_SENDER_LOGIN }"
51
+ authorUrl="${GITHUB_EVENT_SENDER_HTML_URL }"
52
+ if [ ! -z "${GITHUB_EVENT_PULL_REQUEST_HTML_URL }" ] ; then
53
+ prNumber="${GITHUB_EVENT_PULL_REQUEST_NUMBER }"
54
+ prUrl="${GITHUB_EVENT_PULL_REQUEST_HTML_URL }"
45
55
runInfo="Pull request #<${prUrl}|${prNumber}> opened by <${authorUrl}|${author}>"
46
- elif [ ! -z "${{ github.event.head_commit.url } }" ] ; then
47
- commitUrl="${{ github.event.head_commit.url } }"
56
+ elif [ ! -z "${GITHUB_EVENT_HEAD_COMMIT_URL }" ] ; then
57
+ commitUrl="${GITHUB_EVENT_HEAD_COMMIT_URL }"
48
58
shaId=$(echo $json | jq -r .headSha | awk '{ print substr($0, 0, 7) }')
49
59
runInfo="Commit <${commitUrl}|${shaId}> pushed by <${authorUrl}|${author}>"
50
60
else
65
75
- shell : bash
66
76
if : ${{ contains(fromJSON('["failed", "cancelled", "unsuccessful"]'), steps.run-info.outputs.result) }}
67
77
run : |
68
- curl -X POST '${{ inputs.webhook-url }}' -H 'Content-Type: application/json' -d '{ "text": "${{ env.WORKFLOW_STATUS }}\n${{ env.WORKFLOW_INFO }}: ${{ env.RUN_INFO }}\n\n${{ env.JOB_INFO }}" }' || true
78
+ curl -X POST "$WEBHOOK_URL" -H 'Content-Type: application/json' -d "{ \"text\": \"${WORKFLOW_STATUS}\n${WORKFLOW_INFO}: ${RUN_INFO}\n\n${JOB_INFO}\" }" || true
79
+ env :
80
+ WEBHOOK_URL : ${{ inputs.webhook-url }}
0 commit comments