-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathaction.yml
More file actions
177 lines (170 loc) · 6.61 KB
/
action.yml
File metadata and controls
177 lines (170 loc) · 6.61 KB
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
name: "Preview Environments for GitHub"
description: "Ephemeral preview deployments of your app for every pull request. Just using Docker Compose."
author: "Cyril Rohr"
branding:
icon: anchor
color: purple
inputs:
app_path:
description: "The path to your application containing a docker-compose file"
default: "."
required: false
dns:
description: "Which DNS suffix to use"
default: "my.preview.run"
max_domain_length:
description: "Maximum length of fully qualified domain name. Note that it cannot be greater than 62 characters due to LetsEncrypt restrictions."
default: "62"
label:
description: "Label to use for triggering preview deployments"
default: "pullpreview"
github_token:
description: "The GitHub access token used to perform GitHub API operations (labels, comments, collaborator/keys lookup)."
default: "${{ github.token }}"
admins:
description: "Logins of GitHub users that will have their SSH key installed on the instance, comma-separated"
required: false
default: "@collaborators/push"
ports:
description: "Ports to open for external access on the preview server (port 22 is always open), comma-separated"
required: false
default: "80/tcp,443/tcp"
cidrs:
description: "The IP address, or range of IP addresses in CIDR notation, that are allowed to connect to the instance"
required: false
default: "0.0.0.0/0"
default_port:
description: "The port to use when building the preview URL"
required: false
default: "80"
compose_files:
description: "Compose files to use when running docker-compose up, comma-separated"
required: false
default: "docker-compose.yml"
compose_options:
description: "Additional options to pass to docker-compose up, comma-separated"
required: false
default: "--build"
license:
description: "PullPreview license"
required: false
default: ""
instance_type:
description: "Instance type to use"
required: false
default: "small"
region:
description: "Provider region (AWS region or Hetzner location), overrides provider defaults"
required: false
default: ""
deployment_variant:
description: "Deployment variant, which allows launching multiple deployments per PR (4 chars max)"
required: false
default: ""
image:
description: "Instance image (Hetzner only; ignored by AWS)"
required: false
default: "ubuntu-24.04"
provider:
description: "Cloud provider to use: lightsail, hetzner"
required: false
default: "lightsail"
registries:
description: "Names of private registries to authenticate against. E.g. docker://username:password@ghcr.io"
required: false
default: ""
proxy_tls:
description: "Enable automatic HTTPS forwarding with Let's Encrypt (format: service:port, e.g. web:80)"
required: false
default: ""
pre_script:
description: "Path to a local bash script (relative to app_path) executed inline over SSH on the instance before docker compose"
required: false
default: ""
ttl:
description: "Maximum time to live for deployments (e.g. 10h, 5d, infinite)"
required: false
default: "infinite"
outputs:
live:
description: "Whether this run produced a live preview deployment"
value: "${{ steps.pullpreview.outputs.live }}"
url:
description: "The URL of the application on the preview server"
value: "${{ steps.pullpreview.outputs.url }}"
host:
description: "The hostname or IP address of the preview server"
value: "${{ steps.pullpreview.outputs.host }}"
username:
description: "The username that can be used to SSH into the preview server"
value: "${{ steps.pullpreview.outputs.username }}"
runs:
using: "composite"
steps:
- name: Restore SSH key cache
uses: actions/cache@v4
with:
path: ${{ runner.temp }}/pullpreview-ssh-keys
key: pullpreview-ssh-keys-v1-${{ github.repository_id }}-${{ github.run_id }}
restore-keys: |
pullpreview-ssh-keys-v1-${{ github.repository_id }}-
- id: pullpreview
shell: bash
env:
GITHUB_TOKEN: "${{ inputs.github_token }}"
PULLPREVIEW_LICENSE: "${{ inputs.license }}"
PULLPREVIEW_PROVIDER: "${{ inputs.provider }}"
PULLPREVIEW_MAX_DOMAIN_LENGTH: "${{ inputs.max_domain_length }}"
PULLPREVIEW_SSH_KEYS_CACHE_DIR: "${{ runner.temp }}/pullpreview-ssh-keys"
PULLPREVIEW_GITHUB_JOB_ID: "${{ job.check_run_id }}"
run: |
set -euo pipefail
mkdir -p "${PULLPREVIEW_SSH_KEYS_CACHE_DIR}"
os="$(echo "${RUNNER_OS}" | tr '[:upper:]' '[:lower:]')"
arch="$(echo "${RUNNER_ARCH}" | tr '[:upper:]' '[:lower:]')"
if [ "${os}" != "linux" ]; then
echo "::error::Unsupported RUNNER_OS=${RUNNER_OS}. Only Linux amd64 is supported."
exit 1
fi
case "${arch}" in
x64) arch="amd64" ;;
amd64) arch="amd64" ;;
*)
echo "::error::Unsupported RUNNER_ARCH=${RUNNER_ARCH}. Only amd64 is supported."
exit 1
;;
esac
binary="${GITHUB_ACTION_PATH}/dist/pullpreview-${os}-${arch}"
if [ ! -f "${binary}" ]; then
echo "::error::Bundled binary not found at ${binary}. Run 'make dist' and commit dist artifacts."
ls -la "${GITHUB_ACTION_PATH}/dist" || true
exit 1
fi
chmod +x "${binary}"
app_path="${{ inputs.app_path }}"
# Backward compatibility for Docker-era defaults; composite actions run in $GITHUB_WORKSPACE.
if [ -z "${app_path}" ] || [ "${app_path}" = "/github/workspace" ]; then
app_path="${GITHUB_WORKSPACE}"
fi
"${binary}" github-sync "${app_path}" \
--admins "${{ inputs.admins }}" \
--cidrs "${{ inputs.cidrs }}" \
--compose-files "${{ inputs.compose_files }}" \
--compose-options "${{ inputs.compose_options }}" \
--dns "${{ inputs.dns }}" \
--label "${{ inputs.label }}" \
--ports "${{ inputs.ports }}" \
--default-port "${{ inputs.default_port }}" \
--instance-type "${{ inputs.instance_type }}" \
--region "${{ inputs.region }}" \
--image "${{ inputs.image }}" \
--deployment-variant "${{ inputs.deployment_variant }}" \
--registries "${{ inputs.registries }}" \
--proxy-tls "${{ inputs.proxy_tls }}" \
--pre-script "${{ inputs.pre_script }}" \
--ttl "${{ inputs.ttl }}"
if grep -q '^url=' "${GITHUB_OUTPUT}"; then
echo "live=true" >> "${GITHUB_OUTPUT}"
else
echo "live=false" >> "${GITHUB_OUTPUT}"
fi