Skip to content

Commit 35e09c9

Browse files
committed
end-notification uses env:
1 parent 64402c8 commit 35e09c9

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

.github/actions/send-notification/action.yml

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,25 @@ runs:
1313
shell: bash
1414
env:
1515
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 }}
1626
run: |
1727
# 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)
1929
# Get sanitized display title (usually a commit message or PR title) from GitHub API
2030
displayTitle=$(echo $json | jq -r .displayTitle | sed 's/"/\\"/g')
2131
# 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 }')
2333
# 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}"
2535
# Get workflow name from GitHub API (also available as "github.workflow")
2636
workflowName=$(echo $json | jq -r .name | sed 's/"/\\"/g')
2737
# Get workflow run URL from GitHub API
@@ -36,15 +46,15 @@ runs:
3646
# Workflow info with link to all workflow runs for this branch
3747
workflowInfo="<${workflowUrl}|${workflowName}> #${runNumber}"
3848
# 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}"
4555
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}"
4858
shaId=$(echo $json | jq -r .headSha | awk '{ print substr($0, 0, 7) }')
4959
runInfo="Commit <${commitUrl}|${shaId}> pushed by <${authorUrl}|${author}>"
5060
else
@@ -65,4 +75,6 @@ runs:
6575
- shell: bash
6676
if: ${{ contains(fromJSON('["failed", "cancelled", "unsuccessful"]'), steps.run-info.outputs.result) }}
6777
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

Comments
 (0)