-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaction.yaml
92 lines (89 loc) · 3.8 KB
/
action.yaml
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# !!!!!!!!!!!!!! This repository is public !!!!!!!!!!!!!!!!!!!!!!!!
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# repo is public until Github Action supports cloning private repos
# https://github.com/github/roadmap/issues/74
name: 'Get Git SHA for PR or Branch Build'
description: 'Get Git SHA for PR or Branch Build'
inputs:
github_sha:
description: 'should be github.sha'
required: true
github_event_pull_request_head_sha:
description: 'should be github.event.pull_request.head.sha'
required: true
github_event_number:
description: 'should be github.event.number'
required: true
github_event_pull_request_base_ref:
description: 'should be github.event.pull_request.base.ref'
required: true
github_event_ref:
description: 'should be github.event.ref'
required: true
github_head_ref:
description: 'should be github.head_ref'
required: true
github_ref:
description: 'should be github.ref'
required: true
outputs:
sha:
description: "if pull request : 'github.event.pull_request.head.sha' else : 'github.sha'"
value: ${{ steps.do.outputs.sha }}
isPullRequest:
description: "'true' or 'false'"
value: ${{ steps.do.outputs.isPullRequest }}
uniqueName:
description: "if pull request: 'inputs.github_event_number' else : short 'github.sha' "
value: ${{ steps.do.outputs.uniqueName }}
baseBranch:
description: "if pull request: 'github.event.pull_request.base.ref' else : short 'github.event.ref' stripped out of 'refs/heads/' "
value: ${{ steps.do.outputs.baseBranch }}
currentBranch:
description: "if pull request: 'github.event.pull_request.base.ref' else : short 'github.event.ref' stripped out of 'refs/heads/' "
value: ${{ steps.do.outputs.currentBranch }}
runs:
using: "composite"
steps:
- shell: bash
id: do
run: |
if [[ "${{ inputs.github_event_pull_request_head_sha }}" != "" ]]; then
sha=${{ inputs.github_event_pull_request_head_sha }}
isPullRequest="true"
uniqueName="${{ inputs.github_event_number }}"
baseBranch=${{ inputs.github_event_pull_request_base_ref }}
currentBranch=${{ inputs.github_head_ref }}
currentBranch=${currentBranch:0:10}
# replace "/" with "-", to avoid errors from validators
currentBranch=${currentBranch//\//-}
# replace "_" with "-", to avoid errors from validators
currentBranch=${currentBranch//_/-}
# replace "." with "-", to avoid errors from validators
currentBranch=${currentBranch//\./-}
else
sha=${{ inputs.github_sha }}
isPullRequest="false"
uniqueName=${sha:0:8}
baseBranch=${{ inputs.github_event_ref }}
baseBranch=${baseBranch#refs/heads/}
currentBranch=${{ inputs.github_ref }}
currentBranch=${currentBranch#refs/heads/}
# replace "/" with "-", to avoid errors from validators
currentBranch=${currentBranch//\//-}
# replace "_" with "-", to avoid errors from validators
currentBranch=${currentBranch//_/-}
# replace "." with "-", to avoid errors from validators
currentBranch=${currentBranch//\./-}
fi
currentBranch=$(echo ${currentBranch} | tr "[:upper:]" "[:lower:]")
echo "sha : ${sha}"
echo "uniqueName : ${uniqueName}"
echo "isPullRequest : ${isPullRequest}"
echo "currentBranch : ${currentBranch}"
echo "sha=${sha}" >> $GITHUB_OUTPUT
echo "isPullRequest=${isPullRequest}" >> $GITHUB_OUTPUT
echo "uniqueName=${uniqueName}" >> $GITHUB_OUTPUT
echo "baseBranch=${baseBranch}" >> $GITHUB_OUTPUT
echo "currentBranch=${currentBranch}" >> $GITHUB_OUTPUT