forked from MercymeIlya/last-workflow-status
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
47 lines (47 loc) · 2.04 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
name: 'Get status of last workflow'
description: 'Get conclusion of last workflow run on current branch.'
branding:
icon: 'arrow-left'
color: 'yellow'
inputs:
github_token:
description: Secret GitHub API token to use for making API requests.
default: ${{ github.token }}
required: true
outputs:
last_status:
description: "Conclusion of last workflow run on current branch"
value: ${{ steps.last_status.outputs.last_status }}
runs:
using: "composite"
steps:
- name: Get branch name
shell: bash
run: |
if [[ ${GITHUB_EVENT_NAME} == "pull_request" ]]
then
echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF})" >> $GITHUB_ENV
echo "Branch name: ${GITHUB_HEAD_REF}"
else
echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
echo "Branch name: ${GITHUB_REF#refs/heads/}"
fi
- name: Get workflow id
shell: bash
run: |
WORKFLOW_ID=$(curl --header 'authorization: Bearer ${{ inputs.github_token }}' \
--header 'content-type: application/json' \
${{ github.api_url }}/repos/${{ github.repository }}/actions/runs/${{ github.run_id }} |
sed -E -ne 's/.*"workflow_id":\s*([0-9]+).*/\1/p') # jq -r .workflow_id
echo "WORKFLOW_ID=$WORKFLOW_ID" >> $GITHUB_ENV
echo "Workflow id: ${WORKFLOW_ID}"
- name: Get previous build status
shell: bash
id: last_status
run: |
last_status=$(curl --silent --header 'authorization: Bearer ${{ inputs.github_token }}' \
--header 'content-type: application/json' \
"${{ github.api_url }}/repos/${{ github.repository }}/actions/workflows/${{ env.WORKFLOW_ID }}/runs?per_page=1&status=completed&branch=${{ env.BRANCH_NAME }}" |
sed -E -ne '/"workflow_runs":/,/"conclusion":/ {s/.*"conclusion":\s*"([^"]*)".*/\1/p}') # jq -r .workflow_runs[0].conclusion
echo "last_status=$last_status" >> $GITHUB_OUTPUT
echo "Status of the previous build: $last_status"