Skip to content

Commit 6acf29b

Browse files
authored
Merge pull request #184 from AdobeDocs/eds-migration
Merge all new Eds changes to main for prod deployment.
2 parents 609fa86 + 2f38113 commit 6acf29b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2613
-5418
lines changed

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

Lines changed: 110 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,127 @@
1-
// This script retrieves the pathPrefix from the gatsby-config.js file.
1+
// This script retrieves the pathPrefix from the config.md file and validates it against the pathPrefix from devsite-paths.json.
22
// It serves as an example for how to set up external javascript functions
33
// outside workflow .yml files when they get too big or complex to keep them inline.
44

55
// Documentation for the actions/github-script:
66
// https://github.com/actions/github-script#run-a-separate-file
77

8-
module.exports = async ({ core }) => {
9-
const { pathPrefix } = await require('../../gatsby-config.js');
8+
const CONFIG_PATH = `./src/pages/config.md`;
9+
const DEVSITE_STAGE_HOST = `https://main--adp-devsite-stage--adobedocs.aem.page`;
10+
const DEVSITE_PROD_HOST = `https://main--adp-devsite--adobedocs.aem.live`;
11+
const DEVSITE_PATHNAME = `/franklin_assets/devsitepaths.json`;
1012

11-
if (!pathPrefix) {
12-
core.setFailed(
13-
`The pathPrefix in the site's gatsby-config.js file is missing.
13+
module.exports = async ({ core, isStage, isProd }) => {
14+
const fs = await require('fs');
15+
if (!fs.existsSync(CONFIG_PATH)) {
16+
core.setFailed(
17+
`The site's config.md file is missing.
18+
19+
To fix this, either create one in ./src/pages, or auto-generate one from the site's gatsby-config.md file by building navigation file.`
20+
);
21+
return;
22+
}
1423

15-
To fix this, open your gatsby-config.js file, and add it to the config object:
24+
const string = fs.readFileSync(CONFIG_PATH).toString() ?? "";
25+
const lines = string.split('\n');
1626

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.
27+
// find the pathPrefix key
28+
const keyIndex = lines.findIndex(line => line.includes("pathPrefix:"));
2529

26-
To fix this, change the pathPrefix to include a name that starts and ends with "/":
30+
if (keyIndex < 0) {
31+
core.setFailed(
32+
`The pathPrefix in the site's config.md file is missing.
2733
28-
pathPrefix: "/commerce/frontend - core/"
34+
To fix this, open your config.md file, and add it to the config object:
35+
36+
- pathPrefix:
37+
...`
38+
);
39+
return;
40+
}
2941

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('/')) {
42+
// find the pathPrefix value
43+
const line = lines.slice(keyIndex + 1)?.find(line => line.trimStart().startsWith("-")) ?? "";
44+
45+
// remove whitespace at start, remove dash (i.e. first non-whitespace character), and remove whitespace at start and end
46+
const pathPrefix = line.trimStart().substring(1).trim();
47+
48+
if (!pathPrefix) {
3649
core.setFailed(
37-
`The pathPrefix in the site's gatsby-config.js file does not start or end with "/".
50+
`The pathPrefix in the site's config.md file is missing.
3851
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/".
52+
To fix this, open your config.md file, and add it to the config object:
4153
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-
`
54+
- pathPrefix:
55+
- /commerce/frontend-core/
56+
...`
4557
);
58+
} else if (pathPrefix === '/') {
59+
core.setFailed(
60+
`The pathPrefix in the site's config.md file is set to "/". This is not allowed.
61+
62+
To fix this, change the pathPrefix to include a name that starts and ends with "/".
63+
64+
For example: "/commerce/frontend - core/"
65+
66+
This name identifies the site within the developer.adobe.com domain:
67+
https://developer.adobe.com/document-services/<PATH_TO_FILES>.
68+
`
69+
);
70+
} else if (!pathPrefix.startsWith('/') || !pathPrefix.endsWith('/')) {
71+
core.setFailed(
72+
`The pathPrefix in the site's config.md file does not start or end with "/".
73+
74+
pathPrefix: "${pathPrefix}"
75+
76+
To fix this, change the pathPrefix to include a name that starts and ends with "/".
77+
For example: "/document-services/" or "/commerce/cloud-tools/".
78+
79+
This is required by convention because of the way we construct site URLs.
80+
For example: https://developer.adobe.com + /document-services/ + path/to/files/.
81+
`
82+
);
83+
}
84+
85+
// TODO: devsitepaths pathPrefix currently do not have a trailing slash
86+
// will need to refactor all path prefix listings to include them
87+
// but for now checked with a popped trailing slash
88+
89+
const poppedPathPrefix = pathPrefix.substring(0, pathPrefix.length-1);
90+
// must convert values to boolean from string
91+
if(isStage.toLowerCase() === 'true') {
92+
const stageEntries = await (await fetch(`${DEVSITE_STAGE_HOST}${DEVSITE_PATHNAME}`)).json();
93+
const stageEntry = stageEntries?.data?.find(entry => entry.pathPrefix === poppedPathPrefix);
94+
95+
if(!stageEntry) {
96+
core.setFailed(
97+
`The pathPrefix in the site's config.md file was not found in the STAGE gdrive's devsitepaths.json.
98+
99+
pathPrefix from config.md: "${pathPrefix}"
100+
devsitepath.json location: "${DEVSITE_STAGE_HOST}${DEVSITE_PATHNAME}"
101+
102+
To fix this, make sure the pathPrefix listed in the config.md is in the devsitepath.json location.
103+
`
104+
);
105+
}
46106
}
47-
}
48-
core.setOutput('path_prefix', pathPrefix);
49-
};
107+
108+
// must convert values to boolean from string
109+
if(isProd.toLowerCase() === 'true') {
110+
const prodEntries = await (await fetch(`${DEVSITE_PROD_HOST}${DEVSITE_PATHNAME}`)).json();
111+
const prodEntry = prodEntries?.data?.find(entry => entry.pathPrefix === poppedPathPrefix);
112+
113+
if(!prodEntry) {
114+
core.setFailed(
115+
`The pathPrefix in the site's config.md file was not found in the PROD gdrive's devsitepaths.json.
116+
117+
pathPrefix from config.md: "${pathPrefix}"
118+
devsitepath.json location: "${DEVSITE_PROD_HOST}${DEVSITE_PATHNAME}"
119+
120+
To fix this, make sure the pathPrefix listed in the config.md is in the devsitepath.json location.
121+
`
122+
);
123+
}
124+
}
125+
126+
core.setOutput('path_prefix', poppedPathPrefix);
127+
}

.github/scripts/process-mds.sh

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/bin/bash
2+
3+
fail() {
4+
echo "$@" 1>&2
5+
exit 1
6+
}
7+
8+
ROOT="./src/pages"
9+
OPERATION=$1
10+
ENV=$2
11+
CONTENT_REPO_BRANCH=$3
12+
PATH_PREFIX=$4
13+
14+
# conditional http_method
15+
case "$OPERATION" in
16+
cache | preview | live)
17+
http_method="POST"
18+
;;
19+
*)
20+
fail "Unknown operation"
21+
;;
22+
esac
23+
24+
# conditional site and code_repo_branch
25+
case "$ENV" in
26+
stage)
27+
site="adp-devsite-stage"
28+
code_repo_branch="stage"
29+
;;
30+
prod)
31+
site="adp-devsite"
32+
code_repo_branch="main"
33+
;;
34+
*)
35+
fail "Unknown env"
36+
;;
37+
esac
38+
39+
# conditional args
40+
if [ "$ENV" == "stage" ] && [ "$OPERATION" == "preview" ]
41+
then
42+
args="--header \"x-content-source-authorization: ${CONTENT_REPO_BRANCH}\""
43+
else
44+
args=""
45+
fi
46+
47+
process()
48+
{
49+
filename=$1
50+
path="${PATH_PREFIX:1}/${filename#$ROOT/}"
51+
url="https://admin.hlx.page/${OPERATION}/adobedocs/${site}/${code_repo_branch}/${path}"
52+
cmd="curl -X${http_method} -vi ${args} ${url}"
53+
54+
echo ""
55+
echo ""
56+
echo "--------------------------------------------------------------------------------"
57+
echo ""
58+
echo "${cmd}"
59+
echo ""
60+
61+
# run command and extract failure string
62+
failure=$(eval "${cmd} | grep -e \"x-error:\"")
63+
64+
# append to failures
65+
if [ "$failure" != "" ]
66+
then
67+
failures="${failures}\n${cmd}\n${failure}\n"
68+
fi
69+
70+
# write failures to stderr so it can be accessed outside this subshell later
71+
echo $failures > 2
72+
}
73+
74+
summarize() {
75+
echo ""
76+
echo ""
77+
echo "================================================================================"
78+
echo ""
79+
80+
# read failures from stderr to access it from this parent shell
81+
read -r failures < 2
82+
83+
if [ "${failures}" == "" ]
84+
then
85+
echo "Success!"
86+
else
87+
echo "Failures:"
88+
echo -e "${failures}"
89+
fi
90+
91+
echo ""
92+
}
93+
94+
# process mds in root
95+
# TODO: may want to only process certain types of files
96+
find "${ROOT}" -type f \( -name "*.md" -o -name "*.json" \) -exec echo "{}" \; | while read i; do process $i; done
97+
98+
summarize

0 commit comments

Comments
 (0)