-
Notifications
You must be signed in to change notification settings - Fork 2
216 lines (189 loc) · 6.43 KB
/
build-and-deploy.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
name: Build plugin
on:
push:
# Don't run for irrelevant changes.
paths-ignore:
- 'docs/**'
- '!.github/workflows/**'
- '!.github/workflows/build-and-deploy.yml'
- '.storybook/**'
- '.wordpress-org/**'
- '__mocks__/**'
- '__static__/**'
- 'bin/**'
- 'tests/**'
branches:
- main
- release/*
pull_request:
# Don't run for irrelevant changes.
paths-ignore:
- 'docs/**'
- '!.github/workflows/**'
- '!.github/workflows/build-and-deploy.yml'
- '.storybook/**'
- '.wordpress-org/**'
- '__mocks__/**'
- '__static__/**'
- 'bin/**'
- 'tests/**'
# Cancels all previous workflow runs for pull requests that have not completed.
concurrency:
# The concurrency group contains the workflow name and the branch name for pull requests
# or the commit hash for any other events.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true
jobs:
bundle-size:
name: Bundle size check
runs-on: ubuntu-latest
timeout-minutes: 60
# The action cannot annotate the PR when run from a PR fork or authored by Dependabot.
if: >
github.event_name == 'pull_request' &&
github.event.pull_request.draft == false &&
github.event.pull_request.head.repo.fork == false &&
github.event.pull_request.user.login != 'dependabot[bot]'
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Read .nvmrc
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
id: nvm
- name: Setup Node
uses: actions/[email protected]
with:
node-version: ${{ steps.nvm.outputs.NVMRC }}
cache: npm
- name: Bundle size check
uses: preactjs/compressed-size-action@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
pattern: '{assets/js/*.js,assets/css/*.css}'
build-script: 'build:js'
minimum-change-threshold: 100
# Ignore webpack content hash in bundle filenames.
strip-hash: '.*-(\w{20})\.js$'
build:
name: Package ZIP files
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Read .nvmrc
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
id: nvm
- name: Setup Node
uses: actions/[email protected]
with:
node-version: ${{ steps.nvm.outputs.NVMRC }}
cache: npm
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
coverage: none
tools: composer
- name: Get Composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Setup Composer cache
uses: pat-s/[email protected]
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
${{ runner.os }}-
- name: Install dependencies
run: |
npm ci
composer install --prefer-dist --no-progress --no-interaction
env:
CI: true
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
- name: Build plugin
run: |
npm run build:js
npm run workflow:version -- --nightly
mkdir -p build/web-stories-regular build/web-stories-dev
- name: Bundle regular version
run: |
npm run workflow:build-plugin
mv build/web-stories build/web-stories-regular/
- name: Bundle development version
run: |
rm -rf assets/css/* assets/js/*
NODE_ENV=development npx webpack --config webpack.config.cjs
npm run workflow:build-plugin
mv build/web-stories build/web-stories-dev/
- name: Upload regular bundle
uses: actions/upload-artifact@v4
with:
name: web-stories
path: build/web-stories-regular
- name: Upload development bundle
uses: actions/upload-artifact@v4
with:
name: web-stories-dev
path: build/web-stories-dev
upload-to-wiki:
name: Upload ZIP files to storage
runs-on: ubuntu-latest
timeout-minutes: 60
# Only run if the PR was not authored by Dependabot and it is not a draft or not from a fork.
if: >
github.event.pull_request.draft == false &&
github.event.pull_request.head.repo.fork == false &&
github.event.pull_request.user.login != 'dependabot[bot]'
needs: build
steps:
- name: Checkout
uses: actions/checkout@v2
with:
repository: ${{ github.repository }}.wiki
ref: master
token: ${{ secrets.GITHUB_TOKEN }}
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ${{ github.ref }}
- name: ZIP artifacts
run: |
rm -rf web-stories.zip web-stories-dev.zip
(cd web-stories && zip -mrT web-stories.zip web-stories && mv web-stories.zip ../ )
(cd web-stories-dev && zip -mrT web-stories-dev.zip web-stories && mv web-stories-dev.zip ../ )
working-directory: ${{ github.ref }}
- name: Commit updates
run: |
git add .
git status
git commit -m "Build and publish ${{ github.ref }}"
git pull --no-edit --quiet
git push origin master
env:
GIT_AUTHOR_EMAIL: ${{ github.actor }}@users.noreply.github.com
GIT_AUTHOR_NAME: ${{ github.actor }}
GIT_COMMITTER_EMAIL: ${{ github.actor }}@users.noreply.github.com
GIT_COMMITTER_NAME: ${{ github.actor }}
deploy-to-staging:
name: Deploy to staging environment
runs-on: ubuntu-latest
timeout-minutes: 60
needs: [build]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Download full bundle
uses: actions/download-artifact@v4
with:
name: web-stories
path: build
- name: Setup SSH Keys and known_hosts
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.PANTHEON_DEPLOY_KEY }}
- name: Run deployment
run: bash bin/deploy-to-test-environment.sh