-
Notifications
You must be signed in to change notification settings - Fork 0
223 lines (202 loc) · 7.76 KB
/
zip.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
name: Generate Zip
on:
workflow_call:
secrets:
COMPOSER_TOKEN:
description: 'Composer token'
required: false
NODE_AUTH_TOKEN:
description: 'Node auth token'
required: false
GH_BOT_TOKEN:
description: 'GitHub Bot Token'
required: true
JENKINS_SECRET:
description: 'Jenkins token for packaging requests'
required: true
S3_BUCKET:
description: 'S3 bucket to place packaged zips'
required: true
S3_ACCESS_KEY_ID:
description: 'S3 access key ID'
required: true
S3_SECRET_ACCESS_KEY:
description: 'S3 Secret Access Key'
required: true
S3_REGION:
description: 'S3 Region'
required: true
S3_ENDPOINT:
description: 'S3 Endpoint'
required: true
inputs:
ref:
description: 'Git Commit Ref (branch, tag, or hash)'
default: 'main'
required: true
type: string
production:
description: 'Is this a production build?'
default: 'no'
required: false
type: string
php_version:
description: 'PHP version to use'
default: '7.4'
required: false
type: string
i18n:
description: 'Perform pup i18n steps'
default: 'yes'
required: false
type: string
check:
description: 'Perform pup check steps'
default: 'yes'
required: false
type: string
additional_commands:
description: 'Execute additional commands'
default: ''
required: false
type: string
slack_channel:
description: 'Slack channel ID to post to'
required: false
type: string
slack_thread:
description: 'Slack thread to post to'
required: false
type: string
jobs:
generate-zip:
runs-on: ubuntu-latest
steps:
# ------------------------------------------------------------------------------
# Checkout the repo.
# ------------------------------------------------------------------------------
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
token: ${{ secrets.GH_BOT_TOKEN }}
submodules: recursive
# ------------------------------------------------------------------------------
# Setup Node.
# ------------------------------------------------------------------------------
- name: Check for .nvmrc file
id: check-nvmrc
run: |
if [ -f .nvmrc ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- uses: actions/setup-node@v3
if: steps.check-nvmrc.outputs.exists == 'true'
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Set up authentication for NODE_AUTH_TOKEN if present
if: secrets.NODE_AUTH_TOKEN
run: echo "//npm.pkg.github.com/:_authToken=\${{ secrets.NODE_AUTH_TOKEN }}" >> ~/.npmrc
# ------------------------------------------------------------------------------
# Setup bun.
# ------------------------------------------------------------------------------
- name: Setup bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
# ------------------------------------------------------------------------------
# Setup PHP.
# ------------------------------------------------------------------------------
- name: Configure PHP environment
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php_version }}
extensions: mbstring, intl
coverage: none
# ------------------------------------------------------------------------------
# Setup WordPress.
# ------------------------------------------------------------------------------
- name: Set up WP-CLI
run: |
wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
# ------------------------------------------------------------------------------
# Pup and filename setup.
# ------------------------------------------------------------------------------
- name: install pup
run: composer -- pup
- name: get version
if: ${{ inputs.production == 'yes' }}
run: echo "VERSION=$(composer -- pup get-version)" >> $GITHUB_ENV
- name: get dev version
if: ${{ inputs.production == 'no' }}
run: echo "VERSION=$(composer -- pup get-version --dev)" >> $GITHUB_ENV
- name: get zip name
run: echo "ZIP_NAME=$(composer -- pup zip-name ${{ env.VERSION }})" >> $GITHUB_ENV
# ------------------------------------------------------------------------------
# Try to find zip on s3 service.
# ------------------------------------------------------------------------------
- name: Check if zip already exists
uses: the-events-calendar/action-s3-utility@main
if: ${{ inputs.production == 'no' }}
id: s3_zip_exists
continue-on-error: true
env:
S3_BUCKET: ${{ secrets.S3_BUCKET }}
S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }}
S3_REGION: ${{ secrets.S3_REGION }}
S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }}
COMMAND: exists
FILE: "${{ env.ZIP_NAME }}.zip"
# ------------------------------------------------------------------------------
# Prepare our cache directories.
# ------------------------------------------------------------------------------
- name: Get Composer Cache Directory
if: steps.s3_zip_exists.outcome != 'success'
id: get_composer_cache_dir
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v2
if: steps.s3_zip_exists.outcome != 'success'
id: composer_cache
with:
path: ${{ steps.get_composer_cache_dir.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
# ------------------------------------------------------------------------------
# Build and zip.
# ------------------------------------------------------------------------------
- name: Determine if COMPOSER_TOKEN was provided
run: |
if [ -z "${{ secrets.COMPOSER_TOKEN }}" ]; then
echo "COMPOSER_TOKEN_AVAILABLE=false" >> $GITHUB_ENV
else
echo "COMPOSER_TOKEN_AVAILABLE=true" >> $GITHUB_ENV
fi
- name: pup build
if: steps.s3_zip_exists.outcome != 'success'
run: composer -- pup build
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
- name: pup build with composer auth
if: steps.s3_zip_exists.outcome != 'success' && env.COMPOSER_TOKEN_AVAILABLE == "true"
env:
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.COMPOSER_TOKEN }}"}}'
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
run: composer -- pup build
- name: pup check
if: steps.s3_zip_exists.outcome != 'success' && inputs.production == 'yes' && inputs.check == 'yes'
run: composer -- pup check
- name: Run additional_commands
if: steps.s3_zip_exists.outcome != 'success' && inputs.additional_commands != ''
run: ${{ inputs.additional_commands }}
- name: pup i18n
if: steps.s3_zip_exists.outcome != 'success' && inputs.i18n == 'yes'
run: composer -- pup i18n
- name: pup package
id