Skip to content

Commit aa34b34

Browse files
authored
Build and upload docs independently (#2231)
Now the docs build only on pushes to each branch, and we rely on the GitHub Pages Action to upload all the files that are present; i.e. never remove anything previously uploaded. Maybe it's worth people having an opinion on how they feel about this; how would we remove something we uploaded? It'd need to be a manual intervention now. > [!Note] > We switch from using "peaceiris"'s GitHub Action task to JamesIves'; as it seems more up to date.
2 parents b16b3f8 + e51b38b commit aa34b34

File tree

2 files changed

+67
-64
lines changed

2 files changed

+67
-64
lines changed

.github/workflows/publish-docs.yaml

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,76 +13,71 @@ jobs:
1313
runs-on: ubuntu-latest
1414
permissions:
1515
contents: write
16-
# if: ${{ github.event.workflow_run.conclusion == 'success' }}
1716
steps:
1817

19-
- name: 📥 Checkout repository
20-
uses: actions/checkout@v4
21-
with:
22-
repository: cardano-scaling/hydra
23-
ref: release
24-
# Also ensure we have all history with all tags
25-
fetch-depth: 0
26-
2718
- name: ❄ Setup Nix/Cachix
2819
uses: ./.github/actions/nix-cachix-setup
2920
with:
3021
authToken: '${{ secrets.CACHIX_CARDANO_SCALING_AUTH_TOKEN }}'
3122

32-
- name: Build stable (i.e. from `release`) documentation
33-
working-directory: docs
34-
run: |
35-
nix build .#docs
36-
37-
export out=/tmp/public/head-protocol
38-
mkdir -p $out
39-
cp result/build/* $out -r
23+
- name: 📥 Checkout repository
24+
uses: actions/checkout@v4
4025

41-
nix develop .#hydra-node-bench --command -- tx-cost --output-directory $out/benchmarks/
42-
nix develop .#hydra-node-bench --command -- micro -o $out/benchmarks/ledger-bench.html
43-
nix develop .#hydra-cluster-bench --command -- bench-e2e datasets datasets/1-node.json datasets/3-nodes.json --output-directory $out/benchmarks
26+
- name: Build documentation and compute benchmarks
27+
run: |
4428
45-
# Clean the working copy
46-
git clean -dxf
29+
# Release
30+
DERIVATION=docs
31+
OUT_PATH=
4732
48-
- name: Checkout master
49-
working-directory: docs
50-
run: |
51-
git reset origin/master --hard
52-
sed -i 's|head-protocol|head-protocol/unstable|' docusaurus.config.js
33+
[[ ${{ github.ref_name }} = "master" ]] && \
34+
DERIVATION=docs-unstable && \
35+
OUT_PATH=/unstable
5336
54-
- name: Build /unstable documentation
55-
working-directory: docs
56-
run: |
57-
nix build .#docs
37+
nix build .#${DERIVATION}
5838
59-
export out=/tmp/public/head-protocol/unstable
39+
export out=/tmp/public/head-protocol${OUT_PATH}
6040
mkdir -p $out
6141
cp result/build/* $out -r
6242
6343
nix develop .#hydra-node-bench --command -- tx-cost --output-directory $out/benchmarks/
6444
nix develop .#hydra-node-bench --command -- micro -o $out/benchmarks/ledger-bench.html
65-
nix develop .#hydra-cluster-bench --command -- bench-e2e datasets datasets/1-node.json datasets/3-nodes.json --output-directory $out/benchmarks
66-
45+
nix develop .#hydra-cluster-bench --command -- \
46+
bench-e2e \
47+
datasets \
48+
hydra-cluster/datasets/1-node.json \
49+
hydra-cluster/datasets/3-nodes.json \
50+
--output-directory $out/benchmarks
6751
6852
- name: 👉 Create redirects
6953
run: |
54+
7055
function redirect() {
7156
echo "Creating redirect: $1 -> $2"
7257
mkdir -p $(dirname $1)
7358
echo "<!DOCTYPE html><html><head><meta http-equiv=\"Refresh\" content=\"0; URL=${2}\"></head></html>" > $1
7459
}
7560
echo "hydra.family" > /tmp/public/CNAME
61+
touch /tmp/public/.nojekyll
62+
7663
redirect /tmp/public/index.html https://hydra.family/head-protocol
64+
7765
# Monthly reports moved to scaling website (2024-02-29)
66+
7867
rm -rf /tmp/public/head-protocol/monthly
68+
69+
# Note: This runs on pushes to either branch, but it doesn't matter as
70+
# it doesn't hurt to write these files twice.
71+
7972
redirect /tmp/public/head-protocol/monthly/index.html https://cardano-scaling.github.io/website/monthly
8073
redirect /tmp/public/head-protocol/unstable/monthly/index.html https://cardano-scaling.github.io/website/monthly
8174
8275
- name: 🚢 Publish Documentation
83-
uses: peaceiris/actions-gh-pages@v4
76+
uses: JamesIves/github-pages-deploy-action@v4
8477
with:
85-
github_token: ${{ secrets.GITHUB_TOKEN || github.token }}
86-
publish_dir: /tmp/public
87-
enable_jekyll: true
88-
force_orphan: true
78+
token: ${{ secrets.GITHUB_TOKEN || github.token }}
79+
folder: /tmp/public
80+
# Note: This is crucial! We _never_ remove files that we have
81+
# previously uploaded. This might be surprising if we expect something
82+
# we previously uploaded to be _removed_!
83+
clean: false

nix/hydra/docs.nix

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,42 @@
11
{ self, inputs, ... }: {
22
perSystem = { self', pkgs, lib, system, ... }: {
3-
packages.docs =
4-
let
5-
src = pkgs.stdenv.mkDerivation {
6-
name = "hydra-docs-source";
7-
dontBuild = true;
8-
dontUnpack = true;
9-
installPhase = ''
10-
mkdir -p $out
11-
mkdir -p $out/static
12-
cp -r ${lib.cleanSource "${self}/docs"}/* $out/
13-
cp ${inputs.hydra-spec.packages.${system}.default}/hydra-spec.pdf $out/static
14-
cp -r ${self'.packages.haddocks} $out/static/haddocks
3+
packages = rec {
4+
docs =
5+
let
6+
src = pkgs.stdenv.mkDerivation {
7+
name = "hydra-docs-source";
8+
dontBuild = true;
9+
dontUnpack = true;
10+
installPhase = ''
11+
mkdir -p $out
12+
mkdir -p $out/static
13+
cp -r ${lib.cleanSource "${self}/docs"}/* $out/
14+
cp ${inputs.hydra-spec.packages.${system}.default}/hydra-spec.pdf $out/static
15+
cp -r ${self'.packages.haddocks} $out/static/haddocks
16+
'';
17+
};
18+
19+
gitWrapper = pkgs.writeShellScriptBin "git" ''
20+
if [ "$1" = "--no-pager" ] && [ "$2" = "log" ] && [ "$3" = "-1" ] && [ "$4" = "--pretty=format:'%aI'" ]; then
21+
date --date="@${builtins.toString self.sourceInfo.lastModified}" +%DT%T
22+
elif [ "$1" = "--no-pager" ] && [ "$2" = "log" ] && [ "$3" = "-1" ] && [ "$4" = "--pretty=format:'%H'" ]; then
23+
echo "${if (self ? rev) then self.rev else self.sourceInfo.dirtyRev}"
24+
else
25+
echo "Pure Git Command Not Implemented: $@"
26+
fi
1527
'';
28+
in
29+
pkgs.buildYarnPackage rec {
30+
inherit src;
31+
yarnBuildMore = "yarn build";
32+
nativeBuildInputs = [ gitWrapper ];
1633
};
1734

18-
gitWrapper = pkgs.writeShellScriptBin "git" ''
19-
if [ "$1" = "--no-pager" ] && [ "$2" = "log" ] && [ "$3" = "-1" ] && [ "$4" = "--pretty=format:'%aI'" ]; then
20-
date --date="@${builtins.toString self.sourceInfo.lastModified}" +%DT%T
21-
elif [ "$1" = "--no-pager" ] && [ "$2" = "log" ] && [ "$3" = "-1" ] && [ "$4" = "--pretty=format:'%H'" ]; then
22-
echo "${if (self ? rev) then self.rev else self.sourceInfo.dirtyRev}"
23-
else
24-
echo "Pure Git Command Not Implemented: $@"
25-
fi
35+
docs-unstable = docs.overrideAttrs {
36+
configurePhase = ''
37+
sed -i 's|head-protocol|head-protocol/unstable|' docusaurus.config.js
2638
'';
27-
in
28-
pkgs.buildYarnPackage rec {
29-
inherit src;
30-
yarnBuildMore = "yarn build";
31-
nativeBuildInputs = [ gitWrapper ];
3239
};
40+
};
3341
};
3442
}

0 commit comments

Comments
 (0)