Skip to content

Commit 8c16b5c

Browse files
Merge pull request #71 from DefangLabs/prebuild
Prebuild script
2 parents 8ab1507 + 230a086 commit 8c16b5c

File tree

6 files changed

+40
-34
lines changed

6 files changed

+40
-34
lines changed

.github/workflows/deploy.yml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,8 @@ jobs:
5959
with:
6060
go-version: "1.21"
6161

62-
- name: Generate CLI docs
63-
run: go run main.go ./tmp
64-
working-directory: defang/src/cmd/gendocs
65-
66-
- name: Copy CLI docs to current repository
67-
run: cp -r ./defang/src/cmd/gendocs/tmp/* ./docs/cli
68-
69-
- name: Prep CLI docs
70-
run: npm run prep-cli-docs
71-
72-
- name: Prep Samples
73-
run: npm run prep-samples
62+
- name: Pre-build
63+
run: npm run prebuild
7464

7565
- name: Build website
7666
run: npm run build
@@ -92,6 +82,7 @@ jobs:
9282
user_email: 41898282+github-actions[bot]@users.noreply.github.com
9383
cname: docs.defang.io
9484

85+
9586
- name: Notify Slack of Action Failures
9687
uses: ravsamhq/[email protected]
9788
if: ${{ always() && github.ref_name == 'main' }}

.github/workflows/test-deploy.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,8 @@ jobs:
4040
with:
4141
go-version: "1.21"
4242

43-
- name: Generate CLI docs
44-
run: go run main.go ./tmp
45-
working-directory: defang/src/cmd/gendocs
46-
47-
- name: Copy CLI docs to current repository
48-
run: cp -r ./defang/src/cmd/gendocs/tmp/* ./docs/cli
49-
50-
- name: Prep CLI docs
51-
run: npm run prep-cli-docs
52-
53-
- name: Prep Samples
54-
run: npm run prep-samples
43+
- name: Pre-build
44+
run: npm run prebuild
5545

5646
- name: Test build website
5747
run: npm run build

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55
"scripts": {
66
"docusaurus": "docusaurus",
77
"start": "docusaurus start",
8+
"prebuild": "./scripts/prebuild.sh",
89
"build": "docusaurus build",
910
"swizzle": "docusaurus swizzle",
1011
"deploy": "docusaurus deploy",
1112
"clear": "docusaurus clear",
1213
"serve": "docusaurus serve",
1314
"write-translations": "docusaurus write-translations",
1415
"write-heading-ids": "docusaurus write-heading-ids",
15-
"typecheck": "tsc",
16-
"prep-cli-docs": "node scripts/prep-cli-docs.js",
17-
"prep-samples": "node scripts/prep-samples.js"
16+
"typecheck": "tsc"
1817
},
1918
"dependencies": {
2019
"@docusaurus/core": "3.0.0",

scripts/prebuild.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
CWD=$(pwd)
6+
CLI_DOCS_PATH=$(readlink -f docs/cli)
7+
8+
# In CI (github actions), the defang and samples repositories must be cloned
9+
# into the working directory of the `defang-docs` repository.
10+
# In local development, however, the defang and samples repositories are cloned
11+
# into the parent directory of the `defang-docs` repository.
12+
if [ -d "../defang" ]; then
13+
DEFANG_PATH=$(readlink -f ../defang)
14+
else
15+
DEFANG_PATH=$(readlink -f ./defang)
16+
fi
17+
if [ -d "../samples" ]; then
18+
SAMPLES_PATH=$(readlink -f ../samples)
19+
else
20+
SAMPLES_PATH=$(readlink -f ./samples)
21+
fi
22+
23+
cd "$DEFANG_PATH/src/cmd/gendocs" && go run main.go "$CLI_DOCS_PATH"
24+
cd "$CWD"
25+
node scripts/prep-cli-docs.js
26+
node scripts/prep-samples.js "$SAMPLES_PATH/samples"

scripts/prep-cli-docs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ fs.readdirSync(directoryPath).forEach(file => {
4747

4848
fs.writeFileSync(filePath, fileContent);
4949
}
50-
});
50+
});

scripts/prep-samples.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const fs = require('fs');
22
const path = require('path');
33
const YAML = require('yaml');
44

5-
const samplesDir = path.join(__dirname, '..', 'samples', 'samples');
5+
const samplesDir = process.argv[2];
66

77
// categories are directories in the current directory (i.e. we're running in samples/ and we might have a samples/ruby/ directory)
88
const directories = fs.readdirSync(samplesDir).filter(file => fs.statSync(path.join(samplesDir, file)).isDirectory());
@@ -20,11 +20,11 @@ directories.forEach((sample) => {
2020
}
2121

2222
// The readme should contain lines that start with the following:
23-
// Title:
24-
// Short Description:
25-
// Tags:
26-
// Languages:
27-
//
23+
// Title:
24+
// Short Description:
25+
// Tags:
26+
// Languages:
27+
//
2828
// We want to extract the title, short description, tags, and languages from the readme. Tags and languages are comma separated lists.
2929
const title = readme.match(/Title: (.*)/)[1];
3030
const shortDescription = readme.match(/Short Description: (.*)/)[1];

0 commit comments

Comments
 (0)