diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d7fa127e9..68fbcedd7 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -59,18 +59,8 @@ jobs: with: go-version: "1.21" - - name: Generate CLI docs - run: go run main.go ./tmp - working-directory: defang/src/cmd/gendocs - - - name: Copy CLI docs to current repository - run: cp -r ./defang/src/cmd/gendocs/tmp/* ./docs/cli - - - name: Prep CLI docs - run: npm run prep-cli-docs - - - name: Prep Samples - run: npm run prep-samples + - name: Pre-build + run: npm run prebuild - name: Build website run: npm run build @@ -92,6 +82,7 @@ jobs: user_email: 41898282+github-actions[bot]@users.noreply.github.com cname: docs.defang.io + - name: Notify Slack of Action Failures uses: ravsamhq/notify-slack-action@2.5.0 if: ${{ always() && github.ref_name == 'main' }} diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 4ac10fe9d..2e0803f2e 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -40,18 +40,8 @@ jobs: with: go-version: "1.21" - - name: Generate CLI docs - run: go run main.go ./tmp - working-directory: defang/src/cmd/gendocs - - - name: Copy CLI docs to current repository - run: cp -r ./defang/src/cmd/gendocs/tmp/* ./docs/cli - - - name: Prep CLI docs - run: npm run prep-cli-docs - - - name: Prep Samples - run: npm run prep-samples + - name: Pre-build + run: npm run prebuild - name: Test build website run: npm run build diff --git a/package.json b/package.json index 4541adeee..a39efe4d3 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "scripts": { "docusaurus": "docusaurus", "start": "docusaurus start", + "prebuild": "./scripts/prebuild.sh", "build": "docusaurus build", "swizzle": "docusaurus swizzle", "deploy": "docusaurus deploy", @@ -12,9 +13,7 @@ "serve": "docusaurus serve", "write-translations": "docusaurus write-translations", "write-heading-ids": "docusaurus write-heading-ids", - "typecheck": "tsc", - "prep-cli-docs": "node scripts/prep-cli-docs.js", - "prep-samples": "node scripts/prep-samples.js" + "typecheck": "tsc" }, "dependencies": { "@docusaurus/core": "3.0.0", diff --git a/scripts/prebuild.sh b/scripts/prebuild.sh new file mode 100755 index 000000000..6717004dc --- /dev/null +++ b/scripts/prebuild.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +set -e + +CWD=$(pwd) +CLI_DOCS_PATH=$(readlink -f docs/cli) + +# In CI (github actions), the defang and samples repositories must be cloned +# into the working directory of the `defang-docs` repository. +# In local development, however, the defang and samples repositories are cloned +# into the parent directory of the `defang-docs` repository. +if [ -d "../defang" ]; then + DEFANG_PATH=$(readlink -f ../defang) +else + DEFANG_PATH=$(readlink -f ./defang) +fi +if [ -d "../samples" ]; then + SAMPLES_PATH=$(readlink -f ../samples) +else + SAMPLES_PATH=$(readlink -f ./samples) +fi + +cd "$DEFANG_PATH/src/cmd/gendocs" && go run main.go "$CLI_DOCS_PATH" +cd "$CWD" +node scripts/prep-cli-docs.js +node scripts/prep-samples.js "$SAMPLES_PATH/samples" diff --git a/scripts/prep-cli-docs.js b/scripts/prep-cli-docs.js index 323f15df2..9ec2fd591 100644 --- a/scripts/prep-cli-docs.js +++ b/scripts/prep-cli-docs.js @@ -47,4 +47,4 @@ fs.readdirSync(directoryPath).forEach(file => { fs.writeFileSync(filePath, fileContent); } -}); \ No newline at end of file +}); diff --git a/scripts/prep-samples.js b/scripts/prep-samples.js index d4f9d544f..4efe8ad04 100644 --- a/scripts/prep-samples.js +++ b/scripts/prep-samples.js @@ -2,7 +2,7 @@ const fs = require('fs'); const path = require('path'); const YAML = require('yaml'); -const samplesDir = path.join(__dirname, '..', 'samples', 'samples'); +const samplesDir = process.argv[2]; // categories are directories in the current directory (i.e. we're running in samples/ and we might have a samples/ruby/ directory) const directories = fs.readdirSync(samplesDir).filter(file => fs.statSync(path.join(samplesDir, file)).isDirectory()); @@ -20,11 +20,11 @@ directories.forEach((sample) => { } // The readme should contain lines that start with the following: - // Title: - // Short Description: - // Tags: - // Languages: - // + // Title: + // Short Description: + // Tags: + // Languages: + // // We want to extract the title, short description, tags, and languages from the readme. Tags and languages are comma separated lists. const title = readme.match(/Title: (.*)/)[1]; const shortDescription = readme.match(/Short Description: (.*)/)[1];