forked from rossjrw/pr-preview-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
188 lines (162 loc) · 6.07 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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
name: Deploy PR Preview
author: Ross Williams
description: >
Deploy a pull request preview to GitHub Pages, similar to Vercel and
Netlify.
branding:
icon: git-pull-request
color: yellow
inputs:
token:
description: >
The token to use for the deployment.
Default is GITHUB_TOKEN in the current repository.
If you need more permissions for things such as deploying to another
repository, you can add a Personal Access Token (PAT).
required: false
default: ${{ github.token }}
preview-branch:
description: Branch on which the previews will be deployed.
required: false
default: gh-pages
umbrella-dir:
description: Name of the directory containing all previews.
required: false
default: pr-preview
source-dir:
description: Directory containing files to deploy.
required: false
default: .
deploy-repository:
description: >
The GitHub repository to deploy the preview to.
This should be formatted like `<org name>/<repo name>`, e.g.
`rossjrw/pr-preview-action`.
Defaults to the current repository.
You will need to add a Personal Access Token (PAT) in the `token` input
in order to allow the action running in one repository to make changes
to another repository.
required: false
default: ${{ github.repository }}
custom-url:
description: Custom pages URL
required: false
default: ""
action:
description: >
Determines what this action will do when it is executed. Supported
values: `deploy`, `remove`, `auto` (default).
If set to `deploy`, will attempt to deploy the preview and overwrite
any existing preview in that location.
If set to `remove`, will attempt to remove the preview in that
location.
If set to `auto`, the action will try to determine whether to deploy
or remove the preview. It will deploy the preview on
`pull_request.types.synchronize` and `.opened` events, and remove it
on `pull_request.types.closed` events. It will not do anything for
all other events. `auto` is the default value.
required: false
default: auto
outputs:
deployment-url:
description: The URL at which the preview has been deployed
value: ${{ steps.url.outputs.url }}
runs:
using: composite
steps:
- name: Store environment variables
env:
action: ${{ inputs.action }}
umbrella: ${{ inputs.umbrella-dir }}
pr: ${{ github.event.number }}
actionref: ${{ github.action_ref }}
actionrepo: ${{ github.action_repository }}
customurl: ${{ inputs.custom-url }}
deployrepo: ${{ inputs.deploy-repository }}
token: ${{ inputs.token }}
run: |
echo "action=$action" >> $GITHUB_ENV
echo "targetdir=$umbrella/pr-$pr" >> $GITHUB_ENV
echo "pr=$pr" >> $GITHUB_ENV
org=$(echo "$deployrepo" | cut -d "/" -f 1)
thirdleveldomain=$(echo "$deployrepo" | cut -d "/" -f 2)
if [ ! -z "$customurl" ]; then
pagesurl="$customurl"
elif [ "${org}.github.io" == "$thirdleveldomain" ]; then
pagesurl="${org}.github.io"
else
pagesurl=$(echo "$deployrepo" | sed 's/\//.github.io\//')
fi
echo "pagesurl=$pagesurl" >> $GITHUB_ENV
echo "emptydir=$(mktemp -d)" >> $GITHUB_ENV
echo "datetime=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV
echo "actionref=$actionref" >> $GITHUB_ENV
echo "actionrepo=$actionrepo" >> $GITHUB_ENV
echo "deployrepo=$deployrepo" >> $GITHUB_ENV
echo "token=$token" >> $GITHUB_ENV
shell: bash
- name: Determine action version
run: |
action_version=$("$GITHUB_ACTION_PATH/lib/find-current-git-tag.sh" -p $actionrepo -f $actionref)
echo "action_version=$action_version" >> "$GITHUB_ENV"
shell: bash
- name: Determine auto action
if: env.action == 'auto'
run: $GITHUB_ACTION_PATH/lib/determine-auto-action.sh
shell: bash
- name: Deploy preview directory
if: env.action == 'deploy'
uses: JamesIves/github-pages-deploy-action@v4
with:
token: ${{ env.token }}
repository-name: ${{ env.deployrepo }}
branch: ${{ inputs.preview-branch }}
folder: ${{ inputs.source-dir }}
target-folder: ${{ env.targetdir }}
commit-message: Deploy preview for PR ${{ env.pr }} 🛫
force: false
- name: Expose deployment URL
id: url
run: echo "url=https://${{ env.pagesurl }}/${{ env.targetdir }}/" >> $GITHUB_OUTPUT
shell: bash
- name: Leave a comment after deployment
if: env.action == 'deploy' && env.deployment_status == 'success'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-preview
message: "\
[PR Preview Action]\
(${{ github.server_url }}/${{ env.actionrepo }})
${{ env.action_version }}
:---:
:rocket: Deployed preview to
https://${{ env.pagesurl }}/${{ env.targetdir }}/
on branch [`${{ inputs.preview-branch }}`](\
${{ github.server_url }}/${{ env.deployrepo }}\
/tree/${{ inputs.preview-branch }})
at ${{ env.datetime }}
"
- name: Remove preview directory
if: env.action == 'remove'
uses: JamesIves/github-pages-deploy-action@v4
with:
token: ${{ env.token }}
repository-name: ${{ env.deployrepo }}
branch: ${{ inputs.preview-branch }}
folder: ${{ env.emptydir }}
target-folder: ${{ env.targetdir }}
commit-message: Remove preview for PR ${{ env.pr }} 🛬
force: false
- name: Leave a comment after removal
if: env.action == 'remove' && env.deployment_status == 'success'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-preview
message: "\
[PR Preview Action]\
(${{ github.server_url }}/${{ env.actionrepo }})
${{ env.action_version }}
:---:
Preview removed because the pull request was closed.
${{ env.datetime }}
"