Skip to content

Commit 9e7f979

Browse files
committed
fix: update deployment workflow and clean up
# This is the 1st commit message:
1 parent 9ced5fc commit 9e7f979

File tree

10 files changed

+144
-94
lines changed

10 files changed

+144
-94
lines changed

.github/linters/.yaml-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ rules:
5050
key-duplicates: enable
5151
line-length:
5252
level: warning
53-
max: 100
53+
max: 200
5454
allow-non-breakable-words: true
5555
allow-non-breakable-inline-mappings: true
5656
new-line-at-end-of-file: disable

.github/scripts/get-path-prefix.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// This script retrieves the pathPrefix from the gatsby-config.js file.
2+
// It serves as an example for how to set up external javascript functions
3+
// outside workflow .yml files when they get too big or complex to keep them inline.
4+
5+
// Documentation for the actions/github-script:
6+
// https://github.com/actions/github-script#run-a-separate-file
7+
8+
module.exports = async ({ core }) => {
9+
const { pathPrefix } = await require('../../gatsby-config.js');
10+
11+
if (!pathPrefix) {
12+
core.setFailed(
13+
`The pathPrefix in the site's gatsby-config.js file is missing.
14+
15+
To fix this, open your gatsby-config.js file, and add it to the config object:
16+
17+
module.exports = {
18+
pathPrefix: "/commerce/frontend-core/",
19+
...
20+
}`
21+
);
22+
} else if (pathPrefix === '/') {
23+
core.setFailed(
24+
`The pathPrefix in the site's gatsby-config.js file is set to "/". This is not allowed.
25+
26+
To fix this, change the pathPrefix to include a name that starts and ends with "/":
27+
28+
pathPrefix: "/commerce/frontend - core/"
29+
30+
This name identifies the site within the developer.adobe.com domain:
31+
https://developer.adobe.com/document-services/<PATH_TO_FILES>.
32+
`
33+
);
34+
} else {
35+
if (!pathPrefix.startsWith('/') || !pathPrefix.endsWith('/')) {
36+
core.setFailed(
37+
`The pathPrefix in the site's gatsby-config.js file does not start or end with "/".
38+
39+
To fix this, change the pathPrefix to include a name that starts and ends with "/".
40+
For example: "/document-services/" or "/commerce/cloud-tools/".
41+
42+
This is required by convention because of the way we construct site URLs.
43+
For example: https://developer.adobe.com + /document-services/ + path/to/files/.
44+
`
45+
);
46+
}
47+
}
48+
core.setOutput('path_prefix', pathPrefix);
49+
};

.github/workflows/deploy.yml

Lines changed: 47 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,46 @@
11
---
2-
name: Deploy
2+
name: Deployment
33
on:
44
workflow_dispatch:
55
inputs:
66
env:
7-
description: "Deploy to (dev|prod|dev prod)"
7+
description: 'Deploy to (dev|prod|dev prod)'
88
required: true
9-
default: "dev"
9+
default: 'dev'
1010
clean:
11-
description: "Clean cache (yes|no)"
11+
description: 'Clean cache (yes|no)'
1212
required: true
13-
default: "no"
13+
default: 'no'
1414
excludeSubfolder:
15-
description: "Exclude a subfolder from deletion"
15+
description: 'Exclude a subfolder from deletion'
1616
required: false
17-
default: ""
17+
default: ''
1818
jobs:
1919
set-state:
2020
runs-on: ubuntu-latest
2121
outputs:
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.result }}
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,11 +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: echo "Repository branch - ${{
67-
needs.set-state.outputs.branch_short_ref}}"
54+
- run: echo "Repository branch - ${{ needs.set-state.outputs.branch_short_ref }}"
6855
- run: echo "Path prefix - ${{ needs.set-state.outputs.path_prefix }}"
69-
- run: echo "Exclude subfolder - ${{
70-
needs.set-state.outputs.exclude_subfolder }}"
56+
- run: echo "Exclude subfolder - ${{ needs.set-state.outputs.exclude_subfolder }}"
7157

7258
pre-build-dev:
7359
needs: [set-state]
@@ -77,9 +63,7 @@ jobs:
7763
- name: check dev azure connection string
7864
if: env.AIO_AZURE_DEV_CONNECTION_STRING == null
7965
run: |
80-
echo "::error::Please set the Azure Blob Storage connection string
81-
as AIO_AZURE_DEV_CONNECTION_STRING in Github Secrets"
82-
66+
echo "::error::Please set the Azure Blob Storage connection string as AIO_AZURE_DEV_CONNECTION_STRING in Github Secrets"
8367
exit 1
8468
env:
8569
AIO_AZURE_DEV_CONNECTION_STRING: ${{ secrets.AIO_AZURE_DEV_CONNECTION_STRING }}
@@ -97,18 +81,18 @@ jobs:
9781
- name: Setup Node v16 for Yarn v3
9882
uses: actions/setup-node@v3
9983
with:
100-
node-version: "16.15.0" # Current LTS version
84+
node-version: '16.15.0' # Current LTS version
10185

10286
- name: Enable Corepack for Yarn v3
10387
run: corepack enable
10488

10589
- name: Install Yarn v3
106-
uses: borales/actions-yarn@v3.0.0
90+
uses: borales/actions-yarn@v3
10791
with:
10892
cmd: set version stable
10993

11094
- name: Install Dependencies
111-
uses: borales/actions-yarn@v3.0.0
95+
uses: borales/actions-yarn@v3
11296
env:
11397
YARN_ENABLE_IMMUTABLE_INSTALLS: false
11498
with:
@@ -120,25 +104,26 @@ jobs:
120104
path: |
121105
public
122106
.cache
123-
key: ${{ needs.set-state.outputs.branch_short_ref }}-gatsby-cache-${{
124-
github.run_id }}
107+
key: ${{ needs.set-state.outputs.branch_short_ref }}-gatsby-cache-${{ github.run_id }}
125108
restore-keys: |
126109
${{ needs.set-state.outputs.branch_short_ref }}-gatsby-cache-
127110
128111
- name: Clean Cache
129112
if: needs.set-state.outputs.clean_cache == 'true'
130-
uses: borales/actions-yarn@v3.0.0
113+
uses: borales/actions-yarn@v3
131114
with:
132115
cmd: clean
133116

134117
- name: Build site
135-
uses: borales/[email protected]
118+
uses: borales/actions-yarn@v3
119+
with:
120+
cmd: build
136121
env:
137-
PREFIX_PATHS: true # works like --prefix-paths flag for 'gatsby build'
122+
PREFIX_PATHS: true # equivalent to --prefix-paths flag for 'gatsby build'
138123
PATH_PREFIX: ${{ needs.set-state.outputs.path_prefix }}
139124
GATSBY_ADOBE_LAUNCH_SRC: ${{ secrets.AIO_ADOBE_LAUNCH_DEV_SRC }}
140125
GATSBY_ADDITIONAL_ADOBE_ANALYTICS_ACCOUNTS: ${{ secrets.AIO_REPORT_SUITE_DEV}}
141-
GATSBY_ADOBE_ANALYTICS_ENV: "dev"
126+
GATSBY_ADOBE_ANALYTICS_ENV: 'dev'
142127
REPO_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
143128
REPO_OWNER: ${{ github.event.repository.owner.login }}
144129
REPO_NAME: ${{ github.event.repository.name }}
@@ -156,17 +141,15 @@ jobs:
156141
GATSBY_ALGOLIA_INDEX_ALL_SRC: ${{ secrets.AIO_ALGOLIA_INDEX_ALL_SRC }}
157142
GATSBY_ALGOLIA_SEARCH_INDEX: ${{ secrets.AIO_ALGOLIA_SEARCH_INDEX }}
158143
GATSBY_FEDS_PRIVACY_ID: ${{ secrets.AIO_FEDS_PRIVACY_ID }}
159-
with:
160-
cmd: build
161144

162145
- name: Deploy
163146
uses: icaraps/static-website-deploy@master
164147
with:
165-
enabled-static-website: "true"
166-
source: "public"
148+
enabled-static-website: 'true'
149+
source: 'public'
167150
target: ${{ needs.set-state.outputs.path_prefix }}
168151
connection-string: ${{ secrets.AIO_AZURE_DEV_CONNECTION_STRING }}
169-
remove-existing-files: "true"
152+
remove-existing-files: 'true'
170153
exclude-subfolder: ${{ needs.set-state.outputs.exclude_subfolder }}
171154
- name: Delay purge
172155
run: sleep 60s
@@ -175,8 +158,7 @@ jobs:
175158
uses: icaraps/gatsby-fastly-purge-action@master
176159
with:
177160
fastly-token: ${{ secrets.AIO_FASTLY_TOKEN }}
178-
fastly-url: "${{ secrets.AIO_FASTLY_DEV_URL}}${{
179-
needs.set-state.outputs.path_prefix }}"
161+
fastly-url: '${{ secrets.AIO_FASTLY_DEV_URL}}${{ needs.set-state.outputs.path_prefix }}'
180162

181163
pre-build-production:
182164
needs: [set-state]
@@ -186,8 +168,7 @@ jobs:
186168
- name: check prod azure connection string
187169
if: env.AIO_AZURE_PROD_CONNECTION_STRING == null
188170
run: |
189-
echo "::error::Please set the Azure Blob Storage connection string
190-
as AIO_AZURE_PROD_CONNECTION_STRING in Github Secrets"
171+
echo "::error::Please set the Azure Blob Storage connection string as AIO_AZURE_PROD_CONNECTION_STRING in Github Secrets"
191172
exit 1
192173
env:
193174
AIO_AZURE_PROD_CONNECTION_STRING: ${{ secrets.AIO_AZURE_PROD_CONNECTION_STRING }}
@@ -205,18 +186,18 @@ jobs:
205186
- name: Setup Node v16 for Yarn v3
206187
uses: actions/setup-node@v3
207188
with:
208-
node-version: "16.15.0" # Current LTS version
189+
node-version: '16.15.0' # Current LTS version
209190

210191
- name: Enable Corepack for Yarn v3
211192
run: corepack enable
212193

213194
- name: Install Yarn v3
214-
uses: borales/actions-yarn@v3.0.0
195+
uses: borales/actions-yarn@v3
215196
with:
216197
cmd: set version stable
217198

218199
- name: Install Dependencies
219-
uses: borales/actions-yarn@v3.0.0
200+
uses: borales/actions-yarn@v3
220201
env:
221202
YARN_ENABLE_IMMUTABLE_INSTALLS: false
222203
with:
@@ -228,27 +209,26 @@ jobs:
228209
path: |
229210
public
230211
.cache
231-
key: ${{ needs.set-state.outputs.branch_short_ref }}-gatsby-cache-${{
232-
github.run_id }}
212+
key: ${{ needs.set-state.outputs.branch_short_ref }}-gatsby-cache-${{ github.run_id }}
233213
restore-keys: |
234214
${{ needs.set-state.outputs.branch_short_ref }}-gatsby-cache-
235215
236216
- name: Clean Cache
237217
if: needs.set-state.outputs.clean_cache == 'true'
238-
uses: borales/actions-yarn@v3.0.0
218+
uses: borales/actions-yarn@v3
239219
with:
240220
cmd: clean
241221

242222
- name: Build site
243-
uses: borales/actions-yarn@v3.0.0
223+
uses: borales/actions-yarn@v3
244224
with:
245225
cmd: build
246226
env:
247-
PREFIX_PATHS: true # works like --prefix-paths flag for 'gatsby build'
227+
PREFIX_PATHS: true # equivalent to --prefix-paths flag for 'gatsby build'
248228
PATH_PREFIX: ${{ needs.set-state.outputs.path_prefix }}
249229
GATSBY_ADOBE_LAUNCH_SRC: ${{ secrets.AIO_ADOBE_LAUNCH_PROD_SRC }}
250230
GATSBY_ADDITIONAL_ADOBE_ANALYTICS_ACCOUNTS: ${{ secrets.AIO_REPORT_SUITE_PROD }}
251-
GATSBY_ADOBE_ANALYTICS_ENV: "production"
231+
GATSBY_ADOBE_ANALYTICS_ENV: 'production'
252232
REPO_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
253233
REPO_OWNER: ${{ github.event.repository.owner.login }}
254234
REPO_NAME: ${{ github.event.repository.name }}
@@ -272,11 +252,11 @@ jobs:
272252
- name: Deploy
273253
uses: icaraps/static-website-deploy@master
274254
with:
275-
enabled-static-website: "true"
276-
source: "public"
255+
enabled-static-website: 'true'
256+
source: 'public'
277257
target: ${{ needs.set-state.outputs.path_prefix }}
278258
connection-string: ${{ secrets.AIO_AZURE_PROD_CONNECTION_STRING }}
279-
remove-existing-files: "true"
259+
remove-existing-files: 'true'
280260
exclude-subfolder: ${{ needs.set-state.outputs.exclude_subfolder }}
281261
- name: Delay purge
282262
run: sleep 60s
@@ -285,5 +265,4 @@ jobs:
285265
uses: icaraps/gatsby-fastly-purge-action@master
286266
with:
287267
fastly-token: ${{ secrets.AIO_FASTLY_TOKEN }}
288-
fastly-url: "${{ secrets.AIO_FASTLY_PROD_URL }}${{
289-
needs.set-state.outputs.path_prefix }}"
268+
fastly-url: '${{ secrets.AIO_FASTLY_PROD_URL }}${{ needs.set-state.outputs.path_prefix }}'

.github/workflows/github-pages.yml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
---
22
name: Github Pages
3-
on:
4-
push:
5-
branches: [main]
3+
on: workflow_dispatch
64
jobs:
75
build-and-deploy:
86
runs-on: ubuntu-latest
97
steps:
108
- name: Checkout
119
uses: actions/checkout@v3
12-
- name: NPM Install
10+
- name: Yarn Install
1311
uses: bahmutov/npm-install@v1
1412
- name: Build
1513
run: |
@@ -18,8 +16,7 @@ jobs:
1816
PREFIX_PATHS: true # works like --prefix-paths flag for 'gatsby build'
1917
PATH_PREFIX: ${{ github.event.repository.name }}
2018
ADOBE_LAUNCH_SRC: ${{ secrets.AIO_ADOBE_LAUNCH_SRC }}
21-
ADOBE_LAUNCH_SRC_INCLUDE_IN_DEVELOPMENT:
22-
${{ secrets.ADOBE_LAUNCH_SRC_INCLUDE_IN_DEVELOPMENT }}
19+
ADOBE_LAUNCH_SRC_INCLUDE_IN_DEVELOPMENT: ${{ secrets.ADOBE_LAUNCH_SRC_INCLUDE_IN_DEVELOPMENT }}
2320
REPO_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2421
REPO_OWNER: ${{ github.event.repository.owner.login }}
2522
REPO_NAME: ${{ github.event.repository.name }}
@@ -29,9 +26,13 @@ jobs:
2926
GOOGLE_DOCS_TOKEN: ${{ secrets.GOOGLE_DOCS_TOKEN }}
3027
GOOGLE_DOCS_FOLDER_ID: ${{ secrets.GOOGLE_DOCS_FOLDER_ID }}
3128
- name: Deploy to GH Pages
32-
uses: JamesIves/github-pages-deploy-action@3.7.1
29+
uses: JamesIves/github-pages-deploy-action@v4
3330
with:
34-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35-
BRANCH: gh-pages # The branch the action should deploy to.
36-
FOLDER: public # The folder the action should deploy.
37-
CLEAN: true # Automatically remove deleted files from deploy branch
31+
token: ${{ secrets.GITHUB_TOKEN }}
32+
branch: gh-pages # The branch the action should deploy to.
33+
folder: public # The folder the action should deploy.
34+
clean: true # Automatically remove deleted files from deploy branch
35+
- name: GH Pages URL
36+
id: gh-pages-url
37+
run: |
38+
echo "View GH-Pages: $(https://adobedocs.github.io/${{ github.event.repository.name }})"

0 commit comments

Comments
 (0)