-
Notifications
You must be signed in to change notification settings - Fork 292
267 lines (256 loc) · 9.05 KB
/
zips.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
name: Plugin Zip Files
on:
push:
branches:
- develop
- main
- 'feature/**'
- 'release/**'
paths:
- '.github/workflows/zips.yml'
- 'bin/release'
- 'assets/**'
- '!assets/**/__tests__/**/*.js'
- '!assets/**/test/*.js'
- '!assets/**/*.test.js'
- 'includes/**'
- 'google-site-kit.php'
- 'scoper.inc.php'
- 'uninstall.php'
- 'composer.json'
- 'composer.lock'
- 'php-scoper/composer.lock'
- 'package.json'
- 'package-lock.json'
- 'postcss.config.js'
- 'webpack.config.js'
- 'feature-flags.json'
tags: ['**']
pull_request:
branches:
- develop
- main
- 'feature/**'
paths:
- '.github/workflows/zips.yml'
- 'bin/release'
- 'assets/**'
- '!assets/**/__tests__/**/*.js'
- '!assets/**/test/*.js'
- '!assets/**/*.test.js'
- 'includes/**'
- 'google-site-kit.php'
- 'scoper.inc.php'
- 'uninstall.php'
- 'composer.json'
- 'composer.lock'
- 'php-scoper/composer.lock'
- 'package.json'
- 'package-lock.json'
- 'postcss.config.js'
- 'webpack.config.js'
- 'feature-flags.json'
types:
- opened
- closed
- reopened
- synchronize
- ready_for_review
workflow_dispatch:
inputs:
release_version:
type: string
description: Release version
required: false
default: ''
concurrency:
group: zips-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true
env:
GCS_BUCKET: site-kit-github-artifacts
GCS_ROOT_PATH: builds
jobs:
build-zips:
name: Build Zips
runs-on: ubuntu-latest
timeout-minutes: 20
if: false == ( ( github.event_name == 'pull_request' && ( github.event.action == 'closed' || github.event.pull_request.draft == true || contains( github.head_ref, 'dependabot/' ) ) ) || github.event.pull_request.head.repo.fork )
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: composer:2.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get Composer Cache Directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"
- uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Composer Install
run: composer install --no-interaction --no-progress --no-dev
- name: Setup Node.js (.nvmrc)
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: npm install
run: |
npm ci
- name: Create destination directory and update file permissions
run: |
mkdir -p "${{ github.ref }}"
sudo chown -R "$(id -u):$(id -g)" .
- name: Build develop version
run: |
npm run dev-zip
mv ./*.zip "${{ github.ref }}/google-site-kit-dev.zip"
- name: Build release version
run: |
npm run release-zip
mv ./*.zip "${{ github.ref }}/google-site-kit.zip"
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: zip-files
path: ${{ github.ref }}
upload-to-cloud-storage:
name: Upload to GCS
runs-on: ubuntu-latest
if: github.event_name != 'workflow_dispatch'
needs: build-zips
steps:
- uses: actions/download-artifact@v4
with:
name: zip-files
path: ${{ github.ref }}
- uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_CREDENTIALS }}
- name: Upload PR files
uses: google-github-actions/upload-cloud-storage@v2
with:
path: ${{ github.ref }}
destination: ${{ env.GCS_BUCKET }}/${{ env.GCS_ROOT_PATH }}/${{ github.ref }}
parent: false
process_gcloudignore: false
add-comment-to-pr:
name: Add comment to PR
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
needs: upload-to-cloud-storage
steps:
- name: Check the comment exists
id: find-comment
uses: peter-evans/find-comment@v3
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: github-actions[bot]
body-includes: Build files for
- name: Get comment body
id: get-comment-body
# Setting a multi-line output requires escaping line-feeds. See <https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings>.
run: |
body="Build files for ${{ github.event.pull_request.head.sha }} are ready:
- Download [development build](https://storage.googleapis.com/${{ env.GCS_BUCKET }}/${{ env.GCS_ROOT_PATH }}/${{ github.ref }}/google-site-kit-dev.zip?${{ github.sha }})
- Download [production build](https://storage.googleapis.com/${{ env.GCS_BUCKET }}/${{ env.GCS_ROOT_PATH }}/${{ github.ref }}/google-site-kit.zip?${{ github.sha }})"
delimiter="${body//$'\n'/'%0A'}"
echo "body<<${delimiter}" >> "$GITHUB_OUTPUT"
echo "$body" >> "$GITHUB_OUTPUT"
echo "${delimiter}" >> "$GITHUB_OUTPUT"
- name: Create comment on PR with links to build files
if: ${{ steps.find-comment.outputs.comment-id == '' }}
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
body: ${{ steps.get-comment-body.outputs.body }}
- name: Update comment on PR with links to build files
if: ${{ steps.find-comment.outputs.comment-id != '' }}
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body: ${{ steps.get-comment-body.outputs.body }}
remove-zips:
name: Remove Zips
runs-on: ubuntu-latest
timeout-minutes: 20
if: ( github.event_name == 'pull_request' && github.event.action == 'closed' && contains( github.head_ref, 'dependabot/' ) == false ) && github.event.pull_request.head.repo.fork == false
steps:
- uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_CREDENTIALS }}
- uses: google-github-actions/setup-gcloud@v1
- name: Prune PR files
run: gcloud storage rm gs://${{ env.GCS_BUCKET }}/${{ env.GCS_ROOT_PATH }}/refs/pull/${{ github.event.pull_request.number }}/**
update-after-removal:
name: Update comment after removal
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
needs: remove-zips
steps:
- name: Check the comment exists
id: find-comment
uses: peter-evans/find-comment@v3
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: github-actions[bot]
body-includes: Build files for
- name: Update comment on PR with links to plugin builds
if: ${{ steps.find-comment.outputs.comment-id != '' }}
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body: Build files for ${{ github.event.pull_request.head.sha }} have been deleted.
dryrun-publish-to-wporg:
name: '[DRY RUN] Publish to WordPress.org'
runs-on: ubuntu-latest
# environment: do not define to omit SVN credentials + deployment protection rules for this dry-run.
if: github.event_name == 'workflow_dispatch' && ( github.ref_type == 'tag' || inputs.release_version != '' )
needs: build-zips
timeout-minutes: 20
steps:
- uses: actions/download-artifact@v4
with:
name: zip-files
path: /tmp
- name: Extract
run: |
unzip /tmp/google-site-kit.zip
- uses: 10up/[email protected]
with:
dry-run: true
env:
BUILD_DIR: ./google-site-kit
SLUG: google-site-kit
SVN_PASSWORD: no-op-password
SVN_USERNAME: no-op-username
VERSION: ${{ inputs.release_version }}
publish-to-wporg:
name: Publish to WordPress.org
runs-on: ubuntu-latest
environment: wordpress-plugin-svn
if: github.event_name == 'workflow_dispatch' && ( github.ref_type == 'tag' || inputs.release_version != '' )
needs: build-zips
timeout-minutes: 20
steps:
- uses: actions/download-artifact@v4
with:
name: zip-files
path: /tmp
- name: Extract
run: |
unzip /tmp/google-site-kit.zip
- uses: 10up/[email protected]
env:
BUILD_DIR: ./google-site-kit
SLUG: google-site-kit
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
VERSION: ${{ inputs.release_version }}