Skip to content

Commit fc593fd

Browse files
authored
Update deploy.yml
1 parent b1f5536 commit fc593fd

File tree

1 file changed

+92
-81
lines changed

1 file changed

+92
-81
lines changed

.github/workflows/deploy.yml

Lines changed: 92 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
name: Deploy
2+
name: Deployment
33
on:
44
workflow_dispatch:
55
inputs:
@@ -22,37 +22,25 @@ jobs:
2222
deploy_prod: ${{ contains(github.event.inputs.env, 'prod') }}
2323
deploy_dev: ${{ contains(github.event.inputs.env, 'dev') }}
2424
clean_cache: ${{ contains(github.event.inputs.clean, 'yes') }}
25-
branch_short_ref: ${{ steps.extract_branch.outputs.branch }}
25+
path_prefix: ${{ steps.get_path_prefix.outputs.path_prefix }}
26+
branch_short_ref: ${{ steps.get_branch.outputs.branch }}
2627
exclude_subfolder: ${{ github.event.inputs.excludeSubfolder }}
27-
path_prefix: ${{ steps.extract_pathPrefix.outputs.path_prefix }}
2828
steps:
2929
- name: Checkout
3030
uses: actions/checkout@v3
31-
- name: Extract path prefix
31+
32+
- name: Get pathPrefix
3233
uses: actions/github-script@v6
33-
id: extract_pathPrefix
34+
id: get_path_prefix
3435
with:
3536
script: |
36-
const { GITHUB_WORKSPACE } = process.env;
37-
const { pathPrefix } = await require(`${GITHUB_WORKSPACE}/gatsby-config.js`);
38-
39-
try {
40-
core.setOutput('path_prefix', pathPrefix);
41-
core.notice(`path_prefix in now set to: ${pathPrefix}`);
42-
} catch (err) {
43-
if (!pathPrefix) {
44-
core.setFailed('Missing path prefix');
45-
} else if (pathPrefix === '/') {
46-
core.setFailed('Path prefix "/" is not allowed');
47-
} else if (!pathPrefix.startsWith('/') || !pathPrefix.endsWith('/')) {
48-
core.setFailed('Path prefix should start and end with "/"');
49-
}
50-
}
37+
const script = require('./.github/scripts/get-path-prefix.js');
38+
script({ core });
5139
result-encoding: string
52-
- name: Extract branch name
40+
- name: Get branch name
5341
shell: bash
54-
run: echo "##[set-output name=branch;](${GITHUB_REF#refs/heads/})"
55-
id: extract_branch
42+
run: echo "##[set-output name=branch;]${GITHUB_REF#refs/heads/}"
43+
id: get_branch
5644

5745
echo-state:
5846
needs: [set-state]
@@ -63,13 +51,9 @@ jobs:
6351
- run: echo "Clean cache - ${{ needs.set-state.outputs.clean_cache }}"
6452
- run: echo "Repository org - ${{ github.event.repository.owner.login }}"
6553
- run: echo "Repository name - ${{ github.event.repository.name }}"
66-
- run:
67-
echo "Repository branch - ${{
68-
needs.set-state.outputs.branch_short_ref}}"
54+
- run: echo "Repository branch - ${{ needs.set-state.outputs.branch_short_ref }}"
6955
- run: echo "Path prefix - ${{ needs.set-state.outputs.path_prefix }}"
70-
- run:
71-
echo "Exclude subfolder - ${{
72-
needs.set-state.outputs.exclude_subfolder }}"
56+
- run: echo "Exclude subfolder - ${{ needs.set-state.outputs.exclude_subfolder }}"
7357

7458
pre-build-dev:
7559
needs: [set-state]
@@ -79,13 +63,10 @@ jobs:
7963
- name: check dev azure connection string
8064
if: env.AIO_AZURE_DEV_CONNECTION_STRING == null
8165
run: |
82-
echo "::error::Please set the Azure Blob Storage connection string
83-
as AIO_AZURE_DEV_CONNECTION_STRING in Github Secrets"
84-
66+
echo "::error::Please set the Azure Blob Storage connection string as AIO_AZURE_DEV_CONNECTION_STRING in Github Secrets"
8567
exit 1
8668
env:
87-
AIO_AZURE_DEV_CONNECTION_STRING:
88-
${{ secrets.AIO_AZURE_DEV_CONNECTION_STRING }}
69+
AIO_AZURE_DEV_CONNECTION_STRING: ${{ secrets.AIO_AZURE_DEV_CONNECTION_STRING }}
8970

9071
build-dev:
9172
defaults:
@@ -96,34 +77,52 @@ jobs:
9677
steps:
9778
- name: Checkout
9879
uses: actions/checkout@v3
80+
81+
- name: Setup Node v16 for Yarn v3
82+
uses: actions/setup-node@v3
9983
with:
100-
persist-credentials: false
101-
- name: NPM Install
102-
uses: bahmutov/npm-install@v1
84+
node-version: '16.15.0' # Current LTS version
85+
86+
- name: Enable Corepack for Yarn v3
87+
run: corepack enable
88+
89+
- name: Install Yarn v3
90+
uses: borales/actions-yarn@v3
91+
with:
92+
cmd: set version stable
93+
94+
- name: Install Dependencies
95+
uses: borales/actions-yarn@v3
96+
env:
97+
YARN_ENABLE_IMMUTABLE_INSTALLS: false
98+
with:
99+
cmd: install
100+
103101
- name: Gatsby Cache
104102
uses: actions/cache@v2
105103
with:
106104
path: |
107105
public
108106
.cache
109-
key:
110-
${{ needs.set-state.outputs.branch_short_ref }}-gatsby-cache-${{
111-
github.run_id }}
107+
key: ${{ needs.set-state.outputs.branch_short_ref }}-gatsby-cache-${{ github.run_id }}
112108
restore-keys: |
113109
${{ needs.set-state.outputs.branch_short_ref }}-gatsby-cache-
110+
114111
- name: Clean Cache
115112
if: needs.set-state.outputs.clean_cache == 'true'
116-
run: |
117-
npm run clean
118-
- name: Build
119-
run: |
120-
npm run build
113+
uses: borales/actions-yarn@v3
114+
with:
115+
cmd: clean
116+
117+
- name: Build site
118+
uses: borales/actions-yarn@v3
119+
with:
120+
cmd: build
121121
env:
122-
PREFIX_PATHS: true # works like --prefix-paths flag for 'gatsby build'
122+
PREFIX_PATHS: true # equivalent to --prefix-paths flag for 'gatsby build'
123123
PATH_PREFIX: ${{ needs.set-state.outputs.path_prefix }}
124124
GATSBY_ADOBE_LAUNCH_SRC: ${{ secrets.AIO_ADOBE_LAUNCH_DEV_SRC }}
125-
GATSBY_ADDITIONAL_ADOBE_ANALYTICS_ACCOUNTS:
126-
${{ secrets.AIO_REPORT_SUITE_DEV}}
125+
GATSBY_ADDITIONAL_ADOBE_ANALYTICS_ACCOUNTS: ${{ secrets.AIO_REPORT_SUITE_DEV}}
127126
GATSBY_ADOBE_ANALYTICS_ENV: 'dev'
128127
REPO_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
129128
REPO_OWNER: ${{ github.event.repository.owner.login }}
@@ -135,15 +134,15 @@ jobs:
135134
GOOGLE_DOCS_FOLDER_ID: ${{ secrets.GOOGLE_DOCS_FOLDER_ID }}
136135
GATSBY_IMS_SRC: ${{ secrets.AIO_IMS_DEV_SRC }}
137136
GATSBY_IMS_CONFIG: ${{ secrets.AIO_IMS_DEV_CONFIG }}
138-
GATSBY_ALGOLIA_APPLICATION_ID:
139-
${{ secrets.AIO_ALGOLIA_APPLICATION_ID }}
140-
GATSBY_ALGOLIA_SEARCH_API_KEY:
141-
${{ secrets.AIO_ALGOLIA_SEARCH_API_KEY }}
137+
GATSBY_ALGOLIA_APPLICATION_ID: ${{ secrets.AIO_ALGOLIA_APPLICATION_ID }}
138+
GATSBY_ALGOLIA_SEARCH_API_KEY: ${{ secrets.AIO_ALGOLIA_SEARCH_API_KEY }}
142139
GATSBY_ALGOLIA_APP_ID: ${{ secrets.AIO_ALGOLIA_APP_ID }}
143140
GATSBY_ALGOLIA_API_KEY: ${{ secrets.AIO_ALGOLIA_API_KEY }}
144141
GATSBY_ALGOLIA_INDEX_ALL_SRC: ${{ secrets.AIO_ALGOLIA_INDEX_ALL_SRC }}
145142
GATSBY_ALGOLIA_SEARCH_INDEX: ${{ secrets.AIO_ALGOLIA_SEARCH_INDEX }}
143+
GATSBY_ALGOLIA_INDEX_ENV_PREFIX: ${{ secrets.AIO_ALGOLIA_INDEX_ENV_PREFIX }}
146144
GATSBY_FEDS_PRIVACY_ID: ${{ secrets.AIO_FEDS_PRIVACY_ID }}
145+
147146
- name: Deploy
148147
uses: icaraps/static-website-deploy@master
149148
with:
@@ -160,9 +159,7 @@ jobs:
160159
uses: icaraps/gatsby-fastly-purge-action@master
161160
with:
162161
fastly-token: ${{ secrets.AIO_FASTLY_TOKEN }}
163-
fastly-url:
164-
'${{ secrets.AIO_FASTLY_DEV_URL}}${{
165-
needs.set-state.outputs.path_prefix }}'
162+
fastly-url: '${{ secrets.AIO_FASTLY_DEV_URL}}${{ needs.set-state.outputs.path_prefix }}'
166163

167164
pre-build-production:
168165
needs: [set-state]
@@ -172,12 +169,10 @@ jobs:
172169
- name: check prod azure connection string
173170
if: env.AIO_AZURE_PROD_CONNECTION_STRING == null
174171
run: |
175-
echo "::error::Please set the Azure Blob Storage connection string
176-
as AIO_AZURE_PROD_CONNECTION_STRING in Github Secrets"
172+
echo "::error::Please set the Azure Blob Storage connection string as AIO_AZURE_PROD_CONNECTION_STRING in Github Secrets"
177173
exit 1
178174
env:
179-
AIO_AZURE_PROD_CONNECTION_STRING:
180-
${{ secrets.AIO_AZURE_PROD_CONNECTION_STRING }}
175+
AIO_AZURE_PROD_CONNECTION_STRING: ${{ secrets.AIO_AZURE_PROD_CONNECTION_STRING }}
181176

182177
build-production:
183178
defaults:
@@ -188,32 +183,52 @@ jobs:
188183
steps:
189184
- name: Checkout
190185
uses: actions/checkout@v3
191-
- name: NPM Install
192-
uses: bahmutov/npm-install@v1
186+
187+
- name: Setup Node v16 for Yarn v3
188+
uses: actions/setup-node@v3
189+
with:
190+
node-version: '16.15.0' # Current LTS version
191+
192+
- name: Enable Corepack for Yarn v3
193+
run: corepack enable
194+
195+
- name: Install Yarn v3
196+
uses: borales/actions-yarn@v3
197+
with:
198+
cmd: set version stable
199+
200+
- name: Install Dependencies
201+
uses: borales/actions-yarn@v3
202+
env:
203+
YARN_ENABLE_IMMUTABLE_INSTALLS: false
204+
with:
205+
cmd: install
206+
193207
- name: Gatsby Cache
194208
uses: actions/cache@v2
195209
with:
196210
path: |
197211
public
198212
.cache
199-
key:
200-
${{ needs.set-state.outputs.branch_short_ref }}-gatsby-cache-${{
201-
github.run_id }}
213+
key: ${{ needs.set-state.outputs.branch_short_ref }}-gatsby-cache-${{ github.run_id }}
202214
restore-keys: |
203215
${{ needs.set-state.outputs.branch_short_ref }}-gatsby-cache-
216+
204217
- name: Clean Cache
205218
if: needs.set-state.outputs.clean_cache == 'true'
206-
run: |
207-
npm run clean
208-
- name: Build
209-
run: |
210-
npm run build
219+
uses: borales/actions-yarn@v3
220+
with:
221+
cmd: clean
222+
223+
- name: Build site
224+
uses: borales/actions-yarn@v3
225+
with:
226+
cmd: build
211227
env:
212-
PREFIX_PATHS: true # works like --prefix-paths flag for 'gatsby build'
228+
PREFIX_PATHS: true # equivalent to --prefix-paths flag for 'gatsby build'
213229
PATH_PREFIX: ${{ needs.set-state.outputs.path_prefix }}
214230
GATSBY_ADOBE_LAUNCH_SRC: ${{ secrets.AIO_ADOBE_LAUNCH_PROD_SRC }}
215-
GATSBY_ADDITIONAL_ADOBE_ANALYTICS_ACCOUNTS:
216-
${{ secrets.AIO_REPORT_SUITE_PROD }}
231+
GATSBY_ADDITIONAL_ADOBE_ANALYTICS_ACCOUNTS: ${{ secrets.AIO_REPORT_SUITE_PROD }}
217232
GATSBY_ADOBE_ANALYTICS_ENV: 'production'
218233
REPO_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
219234
REPO_OWNER: ${{ github.event.repository.owner.login }}
@@ -225,18 +240,16 @@ jobs:
225240
GOOGLE_DOCS_FOLDER_ID: ${{ secrets.GOOGLE_DOCS_FOLDER_ID }}
226241
GATSBY_IMS_SRC: ${{ secrets.AIO_IMS_PROD_SRC }}
227242
GATSBY_IMS_CONFIG: ${{ secrets.AIO_IMS_PROD_CONFIG }}
228-
GATSBY_ALGOLIA_APPLICATION_ID:
229-
${{ secrets.AIO_ALGOLIA_APPLICATION_ID }}
230-
GATSBY_ALGOLIA_SEARCH_API_KEY:
231-
${{ secrets.AIO_ALGOLIA_SEARCH_API_KEY }}
243+
GATSBY_ALGOLIA_APPLICATION_ID: ${{ secrets.AIO_ALGOLIA_APPLICATION_ID }}
244+
GATSBY_ALGOLIA_SEARCH_API_KEY: ${{ secrets.AIO_ALGOLIA_SEARCH_API_KEY }}
232245
GATSBY_ALGOLIA_APP_ID: ${{ secrets.AIO_ALGOLIA_APP_ID }}
233246
GATSBY_ALGOLIA_API_KEY: ${{ secrets.AIO_ALGOLIA_API_KEY }}
234247
ALGOLIA_WRITE_API_KEY: ${{ secrets.AIO_ALGOLIA_WRITE_API_KEY }}
235248
ALGOLIA_INDEXATION_MODE: ${{ secrets.AIO_ALGOLIA_INDEXATION_MODE }}
236-
ALGOLIA_INDEX_NAME:
237-
${{ secrets.ALGOLIA_INDEX_NAME || github.event.repository.name }}
249+
ALGOLIA_INDEX_NAME: ${{ secrets.ALGOLIA_INDEX_NAME || github.event.repository.name }}
238250
GATSBY_ALGOLIA_INDEX_ALL_SRC: ${{ secrets.AIO_ALGOLIA_INDEX_ALL_SRC }}
239251
GATSBY_ALGOLIA_SEARCH_INDEX: ${{ secrets.AIO_ALGOLIA_SEARCH_INDEX }}
252+
GATSBY_ALGOLIA_INDEX_ENV_PREFIX: ${{ secrets.AIO_ALGOLIA_INDEX_ENV_PREFIX }}
240253
GATSBY_FEDS_PRIVACY_ID: ${{ secrets.AIO_FEDS_PRIVACY_ID }}
241254
- name: Deploy
242255
uses: icaraps/static-website-deploy@master
@@ -254,6 +267,4 @@ jobs:
254267
uses: icaraps/gatsby-fastly-purge-action@master
255268
with:
256269
fastly-token: ${{ secrets.AIO_FASTLY_TOKEN }}
257-
fastly-url:
258-
'${{ secrets.AIO_FASTLY_PROD_URL }}${{
259-
needs.set-state.outputs.path_prefix }}'
270+
fastly-url: '${{ secrets.AIO_FASTLY_PROD_URL }}${{ needs.set-state.outputs.path_prefix }}'

0 commit comments

Comments
 (0)