Skip to content

Commit 40d7e2d

Browse files
committed
update scripts
1 parent 6f648c7 commit 40d7e2d

File tree

10 files changed

+493
-391
lines changed

10 files changed

+493
-391
lines changed

.github/scripts/deploy.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const { exec } = require('child_process');
2+
3+
module.exports = async ({ core, changes, deletions, operation, siteEnv, branch, pathPrefix }) => {
4+
let httpMethod, edsSiteEnv, codeRepoBranch, args;
5+
if (operation.includes('cache') || operation.includes('preview') || operation.includes('live')) {
6+
httpMethod = 'POST';
7+
} else {
8+
console.error('Unknown operation method');
9+
}
10+
11+
if (siteEnv.includes('stage')) {
12+
edsSiteEnv = "adp-devsite-stage";
13+
codeRepoBranch = "stage";
14+
} else if (siteEnv.includes('prod')) {
15+
edsSiteEnv = "adp-devsite";
16+
codeRepoBranch = "main";
17+
} else {
18+
console.error('Unknown env to deploy to');
19+
}
20+
21+
// hacky way to do operations on our adp-devsite-stage env
22+
if ((siteEnv.includes('stage') && operation.includes('preview')) || (siteEnv.includes('stage') && operation.includes('cache'))) {
23+
args = `--header "x-content-source-authorization: ${branch}"`;
24+
} else {
25+
args = '';
26+
}
27+
28+
changes.forEach((file) => {
29+
// have to pop src/pages from the file path
30+
file = file.replace('src/pages/', '');
31+
32+
const theFilePath = `${pathPrefix}/${file}`;
33+
const url = `https://admin.hlx.page/${operation}/adobedocs/${edsSiteEnv}/${codeRepoBranch}${theFilePath}`;
34+
const cmd = `curl -X${httpMethod} -vi ${args} ${url}`;
35+
36+
exec(cmd, (error, execOut, execErr) => {
37+
if (error) {
38+
console.error(`::group:: Error ${theFilePath} \n${execErr} \n::endgroup::`)
39+
return;
40+
}
41+
42+
console.log(`::group:: Running ${operation} on ${theFilePath} \nThe command: ${cmd} \n${execOut} \n::endgroup::`);
43+
});
44+
});
45+
46+
deletions.forEach((file) => {
47+
// have to pop src/pages from the file path
48+
file = file.replace('src/pages/', '');
49+
50+
const theFilePath = `${pathPrefix}/${file}`;
51+
const deleteUrl = `https://admin.hlx.page/${operation}/adobedocs/${edsSiteEnv}/${codeRepoBranch}${theFilePath}`;
52+
const deleteCmd = `curl -XDELETE -vi ${args} ${deleteUrl}`;
53+
54+
55+
exec(deleteCmd, (deleteError, deleteExecOut, deleteExecErr) => {
56+
if (deleteError) {
57+
console.error(`::group:: Deleting error ${theFilePath} \n${deleteExecErr} \n::endgroup::`)
58+
return;
59+
}
60+
61+
console.log(`::group:: Deleting ${operation} on ${theFilePath} \nThe command: ${deleteCmd} \n${deleteExecOut} \n::endgroup::`);
62+
});
63+
});
64+
}

.github/scripts/process-mds.sh

Lines changed: 0 additions & 98 deletions
This file was deleted.

.github/workflows/deploy.yml

Lines changed: 15 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -12,129 +12,20 @@ on:
1212
- stage
1313
- prod
1414
- stage & prod
15-
clean:
16-
description: "Clean cache?"
15+
baseSha:
16+
description: "Use base SHA commit to deploy from (empty string defaults to last commit before HEAD)"
17+
type: string
18+
required: false
19+
default: ""
20+
deployAll:
21+
description: "Force deploy all files"
1722
type: boolean
18-
required: true
19-
default: "no"
20-
build-navigation:
21-
description: "Build navigation file?"
22-
type: boolean
23-
required: true
24-
default: "false"
25-
build-redirections:
26-
description: "Build redirections file?"
27-
type: boolean
28-
required: true
29-
default: "false"
30-
23+
default: false
3124
jobs:
32-
set-state:
33-
runs-on: ubuntu-latest
34-
outputs:
35-
path_prefix: ${{ steps.get_path_prefix.outputs.path_prefix }}
36-
branch_short_ref: ${{ steps.get_branch.outputs.branch }}
37-
deploy_stage: ${{ contains(inputs.env, 'stage') }}
38-
deploy_prod: ${{ contains(inputs.env, 'prod') }}
39-
clean_cache: ${{ inputs.clean }}
40-
build_navigation: ${{ inputs.build-navigation }}
41-
build_redirections: ${{ inputs.build-redirections }}
42-
43-
steps:
44-
- name: Checkout
45-
uses: actions/checkout@v4
46-
47-
- name: Get path prefix
48-
uses: actions/github-script@v7
49-
id: get_path_prefix
50-
with:
51-
script: |
52-
const script = require('./.github/scripts/get-path-prefix.js');
53-
script({ core, isStage:"${{ contains(inputs.env, 'stage') }}", isProd:"${{ contains(inputs.env, 'prod') }}" });
54-
result-encoding: string
55-
56-
- name: Get branch name
57-
shell: bash
58-
run: echo "branch=${GITHUB_REF#refs/heads/}" >> "$GITHUB_OUTPUT"
59-
id: get_branch
60-
61-
echo-state:
62-
needs: [set-state]
63-
runs-on: ubuntu-latest
64-
steps:
65-
- run: echo "Deploy to stage - ${{ needs.set-state.outputs.deploy_stage }}"
66-
- run: echo "Deploy to prod - ${{ needs.set-state.outputs.deploy_prod }}"
67-
- run: echo "Clean cache - ${{ needs.set-state.outputs.clean_cache }}"
68-
- run: echo "Build navigation file - ${{ needs.set-state.outputs.build_navigation }}"
69-
- run: echo "Build redirections file - ${{ needs.set-state.outputs.build_redirections }}"
70-
- run: echo "Path prefix - ${{ needs.set-state.outputs.path_prefix }}"
71-
- run: echo "Repository org - ${{ github.event.repository.owner.login }}"
72-
- run: echo "Repository name - ${{ github.event.repository.name }}"
73-
- run: echo "Repository branch - ${{ needs.set-state.outputs.branch_short_ref }}"
74-
75-
build:
76-
defaults:
77-
run:
78-
shell: bash
79-
needs: [set-state]
80-
runs-on: ubuntu-latest
81-
steps:
82-
- name: Checkout
83-
uses: actions/checkout@v4
84-
85-
- name: Setup Node v18 for Yarn v3
86-
if: needs.set-state.outputs.build_navigation == 'true' || needs.set-state.outputs.build_redirections == 'true'
87-
uses: actions/setup-node@v4
88-
with:
89-
node-version: "18"
90-
91-
- name: Enable Corepack for Yarn v3
92-
if: needs.set-state.outputs.build_navigation == 'true' || needs.set-state.outputs.build_redirections == 'true'
93-
run: corepack enable
94-
95-
- name: Install Yarn v4
96-
if: needs.set-state.outputs.build_navigation == 'true' || needs.set-state.outputs.build_redirections == 'true'
97-
uses: borales/actions-yarn@v4
98-
with:
99-
cmd: set version stable
100-
101-
- name: Install Dependencies
102-
if: needs.set-state.outputs.build_navigation == 'true' || needs.set-state.outputs.build_redirections == 'true'
103-
uses: borales/actions-yarn@v3
104-
env:
105-
YARN_ENABLE_IMMUTABLE_INSTALLS: false
106-
with:
107-
cmd: install
108-
109-
- name: Build navigation file
110-
if: needs.set-state.outputs.build_navigation == 'true'
111-
uses: borales/actions-yarn@v3
112-
with:
113-
cmd: buildNavigation
114-
115-
- name: Build redirections file
116-
if: needs.set-state.outputs.build_redirections == 'true'
117-
uses: borales/actions-yarn@v3
118-
with:
119-
cmd: buildRedirections
120-
121-
- name: Clean cache on stage
122-
if: needs.set-state.outputs.clean_cache == 'true' && needs.set-state.outputs.deploy_stage == 'true'
123-
run: |
124-
bash .github/scripts/process-mds.sh cache stage ${{ needs.set-state.outputs.branch_short_ref }} "${{ needs.set-state.outputs.path_prefix }}"
125-
126-
- name: Clean cache on prod
127-
if: needs.set-state.outputs.clean_cache == 'true' && needs.set-state.outputs.deploy_prod == 'true'
128-
run: |
129-
bash .github/scripts/process-mds.sh cache prod ${{ needs.set-state.outputs.branch_short_ref }} "${{ needs.set-state.outputs.path_prefix }}"
130-
131-
- name: Deploy to stage
132-
if: needs.set-state.outputs.deploy_stage == 'true'
133-
run: |
134-
bash .github/scripts/process-mds.sh preview stage ${{ needs.set-state.outputs.branch_short_ref }} "${{ needs.set-state.outputs.path_prefix }}"
135-
136-
- name: Deploy to prod
137-
if: needs.set-state.outputs.deploy_prod == 'true'
138-
run: |
139-
bash .github/scripts/process-mds.sh preview prod ${{ needs.set-state.outputs.branch_short_ref }} "${{ needs.set-state.outputs.path_prefix }}"
140-
bash .github/scripts/process-mds.sh live prod ${{ needs.set-state.outputs.branch_short_ref }} "${{ needs.set-state.outputs.path_prefix }}"
25+
deployment:
26+
name: Deployment
27+
uses: AdobeDocs/adp-devsite-workflow/.github/workflows/deploy.yml@main
28+
with:
29+
env: ${{ inputs.env }}
30+
baseSha: ${{ inputs.baseSha }}
31+
deployAll: ${{ inputs.deployAll }}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
name: Reuse Deployment
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
env:
7+
description: "Select environment to deploy to"
8+
type: choice
9+
required: true
10+
default: "stage"
11+
options:
12+
- stage
13+
- prod
14+
baseSha:
15+
description: "Use base SHA commit to deploy from (empty string defaults to last commit before HEAD)"
16+
type: string
17+
required: false
18+
default: ""
19+
20+
jobs:
21+
reuse_deployment:
22+
name: Reuse Deployment
23+
uses: AdobeDocs/adp-devsite-workflow/.github/workflows/deploy.yml@main
24+
with:
25+
env: ${{ inputs.env }}
26+
baseSha: ${{ inputs.baseSha }}

0 commit comments

Comments
 (0)