forked from rossjrw/pr-preview-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
153 lines (128 loc) · 4.73 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
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:
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: .
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 }}
run: |
echo "action=$action" >> $GITHUB_ENV
echo "targetdir=$umbrella/pr-$pr" >> $GITHUB_ENV
echo "pr=$pr" >> $GITHUB_ENV
org=$(echo "$GITHUB_REPOSITORY" | cut -d "/" -f 1)
thirdleveldomain=$(echo "$GITHUB_REPOSITORY" | cut -d "/" -f 2 | cut -d "." -f 1)
if [ "$org" == "$thirdleveldomain" ]; then
pagesurl="${org}.github.io"
else
pagesurl=$(echo "$GITHUB_REPOSITORY" | 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
shell: bash
- name: Determine action version
run: >-
${{ github.action_path }}/lib/find-current-git-tag.sh
-p $actionrepo -f $actionref
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:
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 "::set-output name=url::https://${{ env.pagesurl }}/${{ env.targetdir }}/"
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 }}/${{ github.repository }}\
/tree/${{ inputs.preview-branch }})
at ${{ env.datetime }}
"
- name: Remove preview directory
if: env.action == 'remove'
uses: JamesIves/github-pages-deploy-action@v4
with:
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 }}
"