-
Notifications
You must be signed in to change notification settings - Fork 0
204 lines (182 loc) · 7.29 KB
/
deploy-wpengine.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
name: Deploy to WP Engine
on:
workflow_call:
inputs:
install_name:
description: 'The name of the install on WP Engine we are deploying to'
required: true
type: string
site_url:
description: 'The site url we are deploying to (full url)'
required: true
type: string
environment:
description: 'The environment we are deploying to (production, staging, dev)'
required: false
default: 'staging'
type: string
branch:
description: 'The branch we are deploying to'
required: false
default: 'staging'
type: string
deployment:
description: 'The deployment ID from previous jobs'
required: true
type: string
deployment_path:
description: 'Provide if the deployment path is non standard'
required: false
default: '_wpeprivate/releases'
type: string
workflow_run_id:
description: 'Workflow Run ID to get artifacts from'
required: true
type: string
remote_plugin_install:
description: 'Remotely install plugins instead of using composer'
required: false
default: false
type: boolean
secrets:
deployment_ssh_key:
description: 'WP Engine SSH Key needed for deployment'
required: true
gh_bot_token:
description: 'Bot Access to Private repo'
required: true
jobs:
deploy:
name: To WP Engine
runs-on: ubuntu-latest
environment:
name: ${{ inputs.environment }}
url: ${{ inputs.site_url }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Get Current Version
id: version
run: echo "current=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Get branch name
id: branch
uses: tj-actions/branch-names@v7
- name: Deployment In Progress
id: in_progress_deployment
uses: octokit/[email protected]
with:
route: POST /repos/{repo}/deployments/{deployment}/statuses
repo: ${{ github.repository }}
deployment: ${{ inputs.deployment }}
environment: ${{ inputs.environment }}
environment_url: ${{ inputs.site_url }}
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: in_progress
mediaType: '{"previews": ["flash", "ant-man"]}'
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: Download All Artifacts
uses: actions/[email protected]
id: download
with:
name: 'release'
path: ./
- name: Generate release zip
id: folder
run: |
echo "folder=$(date +'%s')" >> $GITHUB_OUTPUT
- name: Configure SSH Connection with WP Engine
uses: linchpin/actions-wpengine-ssh@main
with:
ssh_user: ${{ inputs.install_name }}
ssh_key: ${{ secrets.deployment_ssh_key }}
ssh_host: "${{ inputs.install_name }}.ssh.wpengine.net"
- name: Upload Assets
id: upload_assets
run: |
mv ./release.zip ./${{ steps.folder.outputs.folder }}.zip
ssh wpengine "mkdir -p ~/sites/${{ inputs.install_name }}/${{ inputs.deployment_path }}/"
rsync -e "ssh -p 22" -W --progress "${{ steps.folder.outputs.folder }}.zip" wpengine:~/sites/"${{ inputs.install_name }}"/"${{ inputs.deployment_path }}"
- name: Execute Commands On Server
id: execute_bash
run: |
ssh wpengine "cd ~/sites/${{ inputs.install_name }}/${{ inputs.deployment_path }}/ && wget -O ./entrypoint.sh https://raw.githubusercontent.com/linchpin/actions/v2/.deployment/wpengine-entrypoint.sh && chmod +x ./entrypoint.sh && bash ./entrypoint.sh ${{ steps.folder.outputs.folder }}"
# Loop through all themes passed from inputs.themes
plugin_install:
name: WordPress Plugin Install(s)
runs-on: ubuntu-latest
needs: deploy
steps:
# When installing the plugins we only need the lock file
- name: Checkout code
uses: actions/checkout@v3
with:
path: 'build'
sparse-checkout: |
composer.lock
sparse-checkout-cone-mode: false
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
- name: Configure SSH Connection with WP Engine
uses: linchpin/actions-wpengine-ssh@main
with:
ssh_user: ${{ inputs.install_name }}
ssh_key: ${{ secrets.deployment_ssh_key }}
ssh_host: "${{ inputs.install_name }}.ssh.wpengine.net"
- name: Remote Plugin Install
if: ${{ inputs.remote_plugin_install != false }}
id: parse_composer_lock
shell: bash
run: |
wget -O remote-plugin-install.sh https://raw.githubusercontent.com/linchpin/actions/v2/.deployment/remote-plugin-install.sh
chmod +x ./remote-plugin-install.sh
bash ./remote-plugin-install.sh ${{ inputs.install_name }} ${{ secrets.SATISPRESS_USER }} ${{ secrets.SATISPRESS_PASSWORD }}
status:
name: Deploy Status
runs-on: ubuntu-latest
needs: [deploy, plugin_install]
steps:
- name: Configure SSH Connection with WP Engine
uses: linchpin/actions-wpengine-ssh@main
with:
ssh_user: ${{ inputs.install_name }}
ssh_key: ${{ secrets.deployment_ssh_key }}
ssh_host: "${{ inputs.install_name }}.ssh.wpengine.net"
- name: Cleanup Maintenance
id: cleanup_maintenance
run: |
ssh wpengine "cd ~/sites/${{ inputs.install_name }}/${{ inputs.deployment_path }}/release/.deployment/ && wget -O endpoint.sh https://raw.githubusercontent.com/linchpin/actions/v2/.deployment/wpengine-endpoint.sh && chmod +x ./endpoint.sh && bash ./endpoint.sh"
# - name: Clear Page and Object Cache
# if: ${{ always() && 'production' == inputs.environment }}
# run: |
# ssh wpengine "cd ~/sites/${{ inputs.install_name }} && wp cache flush && wp page-cache flush"
- name: Set Deployment Status as Successful
if: ${{ success() }}
uses: octokit/[email protected]
with:
route: POST /repos/{repo}/deployments/{deployment}/statuses
repo: ${{ github.repository }}
deployment: ${{ inputs.deployment }}
environment: ${{ inputs.environment }}
environment_url: ${{ inputs.site_url }}
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: success
mediaType: '{"previews": ["flash", "ant-man"]}'
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: Set Deployment Status as Failboat
if: ${{ failure() }}
uses: octokit/[email protected]
with:
route: POST /repos/{repo}/deployments/{deployment}/statuses
repo: ${{ github.repository }}
deployment: ${{ inputs.deployment }}
environment: ${{ inputs.environment }}
environment_url: ${{ inputs.site_url }}
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: failure
mediaType: '{"previews": ["flash", "ant-man"]}'
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"