This repository has been archived by the owner on Nov 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yaml
162 lines (151 loc) · 6.91 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: set environment variables for gha-trigger
description: set environment variables for gha-trigger
inputs:
data:
description: gha-trigger's workflow dispatch input
required: true
runs:
using: composite
steps:
- shell: bash
run: |
event_path=$(mktemp)
echo "$INPUTS_EVENT" > "$event_path"
# GITHUB_ACTOR
# > The name of the person or app that initiated the workflow.
# > For example, octocat.
# GITHUB_SHA
# > The commit SHA that triggered the workflow.
# > The value of this commit SHA depends on the event that triggered the workflow.
# > For more information, see "Events that trigger workflows."
# > https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows
# > For example, ffac537e6cbbf934b08745a378932722df287a53.
cat << EOS >> "$GITHUB_ENV"
GHA_ACTOR=${{fromJSON(inputs.data).event.sender.login}}
GHA_EVENT_NAME=${{fromJSON(inputs.data).event_name}}
GHA_REPOSITORY=${{fromJSON(inputs.data).event.repository.full_name}}
GHA_REPOSITORY_OWNER=${{fromJSON(inputs.data).event.repository.owner.login}}
GHA_REPOSITORY_NAME=${{fromJSON(inputs.data).event.repository.name}}
GHA_SHA=${{fromJSON(inputs.data).event.sha}}
GHA_COMMIT_STATUS_SHA=${{fromJSON(inputs.data).event.sha}}
GHA_EVENT_PATH=$event_path
GHA_REF=refs/heads/${{fromJSON(inputs.data).event.repository.default_branch}}
GHA_REF_NAME=${{fromJSON(inputs.data).event.repository.default_branch}}
EOS
env:
INPUTS_EVENT: ${{toJSON(fromJSON(inputs.data).event)}}
- shell: bash
run: |
# GITHUB_BASE_REF
# > The name of the base ref or target branch of the pull request in a workflow run.
# > This is only set when the event that triggers a workflow run is either pull_request or pull_request_target.
# > For example, main.
# GITHUB_HEAD_REF
# > The head ref or source branch of the pull request in a workflow run.
# > This property is only set when the event that triggers a workflow run is either pull_request or pull_request_target.
# > For example, feature-branch-1.
# GITHUB_REF
# > For workflows triggered by pull_request, this is the pull request merge branch.
# GITHUB_SHA
# > Last merge commit on the GITHUB_REF branch
cat << EOS >> "$GITHUB_ENV"
GHA_BASE_REF=${{fromJSON(inputs.data).pull_request.base.ref}}
GHA_HEAD_SHA=${{fromJSON(inputs.data).pull_request.head.sha}}
GHA_COMMIT_STATUS_SHA=${{fromJSON(inputs.data).pull_request.head.sha}}
GHA_HEAD_REF=${{fromJSON(inputs.data).pull_request.head.ref}}
GHA_REF=refs/pull/${{fromJSON(inputs.data).event.number}}/merge
GHA_REF_NAME=${{fromJSON(inputs.data).event.number}}/merge
GHA_SHA=${{fromJSON(inputs.data).pull_request.merge_commit_sha}}
GHA_PULL_REQUEST_NUMBER=${{fromJSON(inputs.data).event.number}}
EOS
if: startsWith(env.GHA_EVENT_NAME, 'pull_request')
- shell: bash
# GITHUB_REF
# > For workflows triggered by release, this is the release tag created.
run: |
cat << EOS >> "$GITHUB_ENV"
GHA_REF=refs/tags/${{fromJSON(inputs.data).event.release.tag_name}}
GHA_REF_NAME=${{fromJSON(inputs.data).event.release.tag_name}}
EOS
if: env.GHA_EVENT_NAME == 'release'
- shell: bash
# GITHUB_REF
# > For workflows triggered by push, this is the branch or tag ref that was pushed.
run: |
# TODO
# When you delete a branch,
# the SHA in the workflow run (and its associated refs) reverts to the default branch of the repository.
cat << EOS >> "$GITHUB_ENV"
GHA_REF=$REF
GHA_SHA=${{fromJSON(inputs.data).event.head_commit.id}}
GHA_COMMIT_STATUS_SHA=${{fromJSON(inputs.data).event.head_commit.id}}
EOS
if: env.GHA_EVENT_NAME == 'push'
env:
REF: ${{fromJSON(inputs.data).event.ref}}
- shell: bash
run: |
cat << EOS >> "$GITHUB_ENV"
GHA_REF_NAME=${GHA_REF#refs/heads/}
EOS
if: "env.GHA_EVENT_NAME == 'push' && startsWith(env.GHA_REF, 'refs/heads/')"
- shell: bash
run: |
cat << EOS >> "$GITHUB_ENV"
GHA_REF_NAME=${GHA_REF#refs/tags/}
EOS
if: "env.GHA_EVENT_NAME == 'push' && startsWith(env.GHA_REF, 'refs/tags/')"
- shell: bash
run: |
cat << EOS >> "$GITHUB_ENV"
GHA_REF_NAME=${{fromJSON(inputs.data).event.ref}}
EOS
if: contains(fromJSON('["create", "delete"]'), env.GHA_EVENT_NAME)
- shell: bash
run: |
cat << EOS >> "$GITHUB_ENV"
GHA_REF=refs/heads/${{fromJSON(inputs.data).event.ref}}
EOS
if: |
contains(fromJSON('["create", "delete"]'), env.GHA_EVENT_NAME) && fromJSON(inputs.data).event.ref_type == 'branch'
- shell: bash
run: |
cat << EOS >> "$GITHUB_ENV"
GHA_REF=refs/tags/${{fromJSON(inputs.data).event.ref}}
EOS
if: |
contains(fromJSON('["create", "delete"]'), env.GHA_EVENT_NAME) && fromJSON(inputs.data).event.ref_type == 'tag'
- shell: bash
run: |
# TODO GITHUB_REF: Branch or tag to be deployed (empty if created with a commit SHA)
cat << EOS >> "$GITHUB_ENV"
GHA_SHA=${{fromJSON(inputs.data).event.deployment.sha}}
GHA_COMMIT_STATUS_SHA=${{fromJSON(inputs.data).event.deployment.sha}}
GHA_REF=refs/heads/${{fromJSON(inputs.data).event.deployment.ref}}
GHA_REF_NAME=${{fromJSON(inputs.data).event.deployment.ref}}
EOS
if: env.GHA_EVENT_NAME == 'deployment' || env.GHA_EVENT_NAME == 'deployment_status'
# TODO GITHUB_REF
# > The branch or tag ref that triggered the workflow run.
# > For other triggers, this is the branch or tag ref that triggered the workflow run.
# > This is only set if a branch or tag is available for the event type.
# > The ref given is fully-formed, meaning that for branches the format is refs/heads/<branch_name>, for pull requests it is refs/pull/<pr_number>/merge, and for tags it is refs/tags/<tag_name>.
# > For example, refs/heads/feature-branch-1.
# TODO GITHUB_REF_NAME
# > The branch or tag name that triggered the workflow run. For example, feature-branch-1.
- shell: bash
run: |
env_path=$(mktemp)
cat << EOS >> "$env_path"
export GITHUB_ACTOR=$GHA_ACTOR
export GITHUB_BASE_REF=$GHA_BASE_REF
export GITHUB_EVENT_NAME=$GHA_EVENT_NAME
export GITHUB_HEAD_REF=$GHA_HEAD_REF
export GITHUB_REF=$GHA_REF
export GITHUB_REF_NAME=$GHA_REF_NAME
export GITHUB_REPOSITORY=$GHA_REPOSITORY
export GITHUB_REPOSITORY_OWNER=$GHA_REPOSITORY_OWNER
export GITHUB_SHA=$GHA_SHA
export GITHUB_EVENT_PATH=$GHA_EVENT_PATH
EOS
echo "GHA_ENV=$env_path" >> "$GITHUB_ENV"