Skip to content

Commit f1eb6d5

Browse files
authored
fix(docs): Show latest released code on published site (AztecProtocol#3716)
Our docs build script checks a `INCLUDE_RELEASED_CODE` env var to determine what code snippets to include in the site build (either latest released version or master). This should be set when deploying the site to the public, which happens on every build on master. So we need to set this env var when on master. However, just setting the env var doesn't work, since we need to get it inside the docs docker build context. Also, we need this build to be seen as different than a build in a branch by the `check_rebuild` script, even if they have the same content hash, since `INCLUDE_RELEASED_CODE` affects the result. One option for fixing this would've been adding a mechanism for passing args to the `build` script in `build-system` which in turn passes them as `ARG`s to the `docker build` call, so they can be turned into `ENV` vars visible by our scripts. Another option could've been defining a different `Dockerfile`, a `Dockerfile.master`, where this `ENV` var is hardcoded. However, neither of these solves the `check_rebuild` issue. So what we're doing is manually changing the contents of the `docs` folder by writing a `.env` file with the env var we need to set, and loading it when building. This both gets the env var inside the docker context (since we're passing it in a file) and triggers a rebuild when needed (since it changes the inputs used for calculating the content hash). Separately from the issues above, we need to manually fetch additional commits from the repo, since we need to load code from the released commit. We're doing that in the same step where we set up the `.env`, which is after the checkout but before the build step. While this approach seems to work, it is doing much stuff around build-system, rather than playing along with it. So @charlielye I'd appreciate your comments here before merging!
1 parent bd5614c commit f1eb6d5

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

.circleci/config.yml

+7
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,13 @@ jobs:
852852
- run:
853853
name: "Copy docs dockerignore"
854854
command: cp docs/.dockerignore .
855+
- run:
856+
name: "Configure build for master"
857+
command: |
858+
if [ "$CIRCLE_BRANCH" == "master" ]; then
859+
echo "Configuring build for master"
860+
echo "INCLUDE_RELEASED_CODE=1" >> docs/.env
861+
fi
855862
- run:
856863
name: "Build docs"
857864
command: build docs

docs/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
.env.development.local
1717
.env.test.local
1818
.env.production.local
19+
.env
1920

2021
npm-debug.log*
2122
yarn-debug.log*

docs/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"deploy": "docusaurus deploy",
1313
"clear": "rm -rf 'processed-docs' 'processed-docs-cache' docs/apis && docusaurus clear",
1414
"serve": "docusaurus serve",
15-
"preprocess": "yarn node ./src/preprocess/index.js",
15+
"preprocess": "yarn node -r dotenv/config ./src/preprocess/index.js",
1616
"preprocess:dev": "nodemon --config nodemon.json ./src/preprocess/index.js",
1717
"typedoc": "rm -rf docs/apis && docusaurus generate-typedoc && cp -a docs/apis processed-docs/",
1818
"typedoc:dev": "nodemon -w ../yarn-project -e '*.js,*.ts,*.nr,*.md' --exec \"rm -rf docs/apis && yarn docusaurus generate-typedoc && cp -a docs/apis processed-docs/\"",
@@ -40,6 +40,7 @@
4040
"@tsconfig/docusaurus": "^1.0.5",
4141
"concurrently": "^8.0.1",
4242
"docusaurus-plugin-typedoc": "^0.20.2",
43+
"dotenv": "^16.3.1",
4344
"nodemon": "^3.0.1",
4445
"typedoc": "^0.25.1",
4546
"typedoc-plugin-markdown": "^3.16.0",

docs/yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -4043,6 +4043,11 @@ dot-prop@^5.2.0:
40434043
dependencies:
40444044
is-obj "^2.0.0"
40454045

4046+
dotenv@^16.3.1:
4047+
version "16.3.1"
4048+
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e"
4049+
integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==
4050+
40464051
duplexer3@^0.1.4:
40474052
version "0.1.5"
40484053
resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.5.tgz#0b5e4d7bad5de8901ea4440624c8e1d20099217e"

0 commit comments

Comments
 (0)