Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 208 additions & 0 deletions .github/scripts/multi-branch-render.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
#! /usr/bin/env bash
set -efuo pipefail

SCRIPT_NAME="$(basename "$0")"

PAGES_BRANCH='gh-pages'
PAGES_DIR='docs'
PAGES_INDEX="${PAGES_DIR}/index.html"
PAGES_BRANCHES="${PAGES_DIR}/branches"

RENDERED_DIR="rendered"

function main
{
[[ $# -eq 0 ]] || usage-error "unexpected arguments: $*"
expect-git-clean

local to_render
to_render="$(get-current-branch '!=')"

switch-to-pages-branch
commit-spliced-merge "$to_render"
render-latest-branch "$to_render"
generate-index > "$PAGES_INDEX"

git add "$PAGES_DIR"
git commit -m "Update multi-branch index with \"$to_render\" rendering."
git-show-tip

sed 's/^ //' <<__EOF

-=*=- Success! -=*=-

Note: you are now on the "$PAGES_BRANCH" tip. Have a nice day!

__EOF
}

## Top-level steps as functions
function expect-git-clean
{
local dirty
dirty="$(
git status \
--porcelain=v1 \
--untracked-files=all \
| tee /dev/stderr
)"

[[ -z "$dirty" ]] || usage-error 'dirty worktree'

local tl
tl="$(git rev-parse --show-toplevel)"

local pwd
pwd="$(readlink -f "$PWD")"

[[ "$tl" == "$pwd" ]] \
|| usage-error "expected to be in working tree root \"$tl\" rather than \"$pwd\""
}

function get-current-branch
{
[[ $# -eq 1 ]] && local op="$1"

local branch
branch="$(git branch --show-current)"

local binop=("$branch" "$op" "$PAGES_BRANCH")

[[ "${binop[@]}" ]] \
|| usage-error "expected current branch ${binop[*]}"

echo "$branch"
}

function switch-to-pages-branch
{
[[ $# -eq 0 ]]

if ! git switch "$PAGES_BRANCH" 2> /dev/null
then
initialize-pages-branch
fi
}

function initialize-pages-branch
{
git switch --orphan "$PAGES_BRANCH"
mkdir "$PAGES_DIR"

local mbrstub
mbrstub='multi-branch-render stub'

sed 's/^ //' > "$PAGES_INDEX" << __EOF
<html>
<head><title>${mbrstub}</title></head>
<body>${mbrstub}; stay tuned!</body>
</html>
__EOF

git restore --source='main' \
--staged --worktree \
-- .gitignore

git add "$PAGES_INDEX" .gitignore
git commit -m "initial \"$PAGES_BRANCH\" stub"

# Give the user an understanding of the stub:
}

function commit-spliced-merge
{
[[ $# -eq 1 ]] && local to_render="$1"

# precondition checks:
get-current-branch '==' > /dev/null # We're on the pages branch
expect-git-clean

# Overlay everything from "$to_render" _except_ the docs dir which is "owned" by "$PAGES_BRANCH":
git restore --source="$to_render" \
--staged --worktree \
-- . ":!${PAGES_DIR}"

git add .

local tree
tree="$(git write-tree)"

local msg="merge ${to_render} contents into ${PAGES_BRANCH} (without render update)"

local commit
commit="$(
git commit-tree "$tree" \
-p "$PAGES_BRANCH" \
-p "$to_render" \
-m "$msg"
)"

git update-ref -m "merge ${to_render} (custom): $msg" HEAD "$commit"
}

function render-latest-branch
{
[[ $# -eq 1 ]] && local to_render="$1"

echo "Rendering the \"$to_render\" contents..."
rmdir-recursive-if-there "$RENDERED_DIR"
make

local render_path="$PAGES_BRANCHES/$to_render"

rmdir-recursive-if-there "$render_path"
mkdir -p "$(dirname "$render_path")"
mv "$RENDERED_DIR" "$render_path"
}

function generate-index
{
sed 's/^ //' <<__EOF
<html>
<head>
<title>multi-branch renders</title>
</head>
<body>
<ul>
__EOF

for b in $(ls "$PAGES_BRANCHES" | sort)
do
echo " <li><a href="./branches/${b}/index.html">${b}</a></li>"
done

sed 's/^ //' <<__EOF
</ul>
</body>
</html>
__EOF
}

## Reusable utilities
function git-show-tip
{
echo 'Created commit:'
git --no-pager log -1
}

function rmdir-recursive-if-there
{
[[ $# -eq 1 ]]
if [[ -d "$1" ]]
then
rm -r "$1"
fi
}

function usage-error
{
{
echo -en '\nincorrect usage: '
echo "$@"
echo
} >&2

exit 1
}

main "$@"
51 changes: 51 additions & 0 deletions .github/workflows/publish-multibranch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Publish (multi-branch)

on:
push

env:
CARGO_TERM_COLOR: always

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: write

# Allow only one concurrent deployment, skipping runs queued between the run
# in-progress and latest queued. However, do NOT cancel in-progress runs as we
# want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
render-and-publish-multibranch:
runs-on: ubuntu-latest

steps:
- name: Setup Pages
uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@ef8a148080ab6020fd15196c2084a2eea5ff2d25 # v22

- name: Restore Nix store cache
id: nix-cache
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
path: /tmp/nix-closure
key: nix-devshell-${{ runner.os }}-${{ hashFiles('flake.lock', 'flake.nix') }}

- name: Import cached Nix store paths
if: steps.nix-cache.outputs.cache-hit == 'true'
run: nix-store --import < /tmp/nix-closure/store.nar

- name: Checkout `${{ github.ref }}`
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0

- name: Render `${{ github.ref }}` to `gh-pages`
run: nix develop -c .github/scripts/multi-branch-render.sh

- name: Push to `gh-pages`
run: git push origin gh-pages:gh-pages
9 changes: 7 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,11 @@ written.
<tr> <td>400</td> <td class="left"><a href="zips/zip-0400.rst">Wallet.dat format</a></td> <td>Draft</td> <td class="left"></td>
<tr> <td><span class="reserved">402</span></td> <td class="left"><a class="reserved" href="zips/zip-0402.rst">New Wallet Database Format</a></td> <td>Reserved</td> <td class="left"><a href="https://github.com/zcash/zips/issues/365">zips#365</a></td>
<tr> <td><span class="reserved">403</span></td> <td class="left"><a class="reserved" href="zips/zip-0403.rst">Verification Behaviour of zcashd</a></td> <td>Reserved</td> <td class="left"><a href="https://github.com/zcash/zips/issues/404">zips#404</a></td>
<tr> <td><span class="reserved">416</span></td> <td class="left"><a class="reserved" href="zips/zip-0416.rst">Support for Unified Addresses in zcashd</a></td> <td>Reserved</td> <td class="left"><a href="https://github.com/zcash/zips/issues/503">zips#503</a></td>
<tr> <td><span class="reserved">416</span></td> <td class="left"><a class="reserved" href="zips/zip-0416.rst">Spending Key Derivation in the `zcashd` wallet</a></td> <td>Reserved</td> <td class="left"><a href="https://github.com/zcash/zips/issues/1175">zips#1175</a></td>
<tr> <td>2002</td> <td class="left"><a href="zips/zip-2002.rst">Explicit Fees</a></td> <td>Draft</td> <td class="left"><a href="https://github.com/zcash/zips/issues/803">zips#803</a></td>
<tr> <td>2003</td> <td class="left"><a href="zips/zip-2003.rst">Disallow version 4 transactions</a></td> <td>Draft</td> <td class="left"><a href="https://github.com/zcash/zips/issues/825">zips#825</a></td>
<tr> <td>2004</td> <td class="left"><a href="zips/zip-2004.rst">Remove the dependency of consensus on note encryption</a></td> <td>Draft</td> <td class="left"><a href="https://github.com/zcash/zips/issues/917">zips#917</a></td>
<tr> <td>CROSSLINK</td> <td class="left"><a href="zips/zip-CROSSLINK.md">The Crosslink Consensus Protocol</a></td> <td>Draft</td> <td class="left"></td>
<tr> <td>guide-markdown</td> <td class="left"><a href="zips/zip-guide-markdown.md">{Something Short and To the Point}</a></td> <td>Draft</td> <td class="left"></td>
<tr> <td>guide</td> <td class="left"><a href="zips/zip-guide.rst">{Something Short and To the Point}</a></td> <td>Draft</td> <td class="left"></td>
<tr> <td>template</td> <td class="left"><a href="zips/zip-template.md">{Template for new ZIPs}</a></td> <td>Draft</td> <td class="left"></td>
Expand All @@ -233,6 +234,9 @@ be deleted.
<tr> <td class="left">draft-arya-deploy-nu7</td> <td class="left"><a href="zips/draft-arya-deploy-nu7.md">Deployment of the NU7 Network Upgrade</a></td> <td class="left"><a href="https://github.com/zcash/zips/issues/839">zips#839</a></td>
<tr> <td class="left">draft-ecc-authenticated-reply-addrs</td> <td class="left"><a href="zips/draft-ecc-authenticated-reply-addrs.md">Authenticated Reply Addresses</a></td> <td class="left"><a href="https://github.com/zcash/zips/issues/1230">zips#1230</a></td>
<tr> <td class="left">draft-ecc-onchain-accountable-voting</td> <td class="left"><a href="zips/draft-ecc-onchain-accountable-voting.md">On-chain Accountable Voting</a></td> <td class="left"></td>
<tr> <td class="left">draft-shieldedlabs-crosslink-construction</td> <td class="left"><a href="zips/draft-shieldedlabs-crosslink-construction.rst">CCC-SL: Crosslink Consensus Construction from Shielded Labs</a></td> <td class="left"></td>
<tr> <td class="left">draft-shieldedlabs-crosslink-ledger-state</td> <td class="left"><a href="zips/draft-shieldedlabs-crosslink-ledger-state.rst">RSM-SL-v1: Crosslink Ledger State and Ledger Mutations</a></td> <td class="left"></td>
<tr> <td class="left">draft-shieldedlabs-crosslink-overview</td> <td class="left"><a href="zips/draft-shieldedlabs-crosslink-overview.rst">Shielded Labs Crosslink v1: Protocol Overview and Architecture</a></td> <td class="left"></td>
<tr> <td class="left">draft-str4d-orchard-balance-proof</td> <td class="left"><a href="zips/draft-str4d-orchard-balance-proof.md">Air drops, Proof-of-Balance, and Stake-weighted Polling</a></td> <td class="left"><a href="https://github.com/zcash/zips/issues/1229">zips#1229</a></td>
</table></embed>

Expand Down Expand Up @@ -368,7 +372,7 @@ Index of ZIPs
<tr> <td>401</td> <td class="left"><a href="zips/zip-0401.rst">Addressing Mempool Denial-of-Service</a></td> <td>Active</td>
<tr> <td><span class="reserved">402</span></td> <td class="left"><a class="reserved" href="zips/zip-0402.rst">New Wallet Database Format</a></td> <td>Reserved</td>
<tr> <td><span class="reserved">403</span></td> <td class="left"><a class="reserved" href="zips/zip-0403.rst">Verification Behaviour of zcashd</a></td> <td>Reserved</td>
<tr> <td><span class="reserved">416</span></td> <td class="left"><a class="reserved" href="zips/zip-0416.rst">Support for Unified Addresses in zcashd</a></td> <td>Reserved</td>
<tr> <td><span class="reserved">416</span></td> <td class="left"><a class="reserved" href="zips/zip-0416.rst">Spending Key Derivation in the `zcashd` wallet</a></td> <td>Reserved</td>
<tr> <td><strike>1001</strike></td> <td class="left"><strike><a href="zips/zip-1001.rst">Keep the Block Distribution as Initially Defined — 90% to Miners</a></strike></td> <td>Obsolete</td>
<tr> <td><strike>1002</strike></td> <td class="left"><strike><a href="zips/zip-1002.rst">Opt-in Donation Feature</a></strike></td> <td>Obsolete</td>
<tr> <td><strike>1003</strike></td> <td class="left"><strike><a href="zips/zip-1003.rst">20% Split Evenly Between the ECC and the Zcash Foundation, and a Voting System Mandate</a></strike></td> <td>Obsolete</td>
Expand All @@ -390,6 +394,7 @@ Index of ZIPs
<tr> <td>2003</td> <td class="left"><a href="zips/zip-2003.rst">Disallow version 4 transactions</a></td> <td>Draft</td>
<tr> <td>2004</td> <td class="left"><a href="zips/zip-2004.rst">Remove the dependency of consensus on note encryption</a></td> <td>Draft</td>
<tr> <td>2005</td> <td class="left"><a href="zips/zip-2005.md">Orchard Quantum Recoverability</a></td> <td>Proposed</td>
<tr> <td>CROSSLINK</td> <td class="left"><a href="zips/zip-CROSSLINK.md">The Crosslink Consensus Protocol</a></td> <td>Draft</td>
<tr> <td>guide-markdown</td> <td class="left"><a href="zips/zip-guide-markdown.md">{Something Short and To the Point}</a></td> <td>Draft</td>
<tr> <td>guide</td> <td class="left"><a href="zips/zip-guide.rst">{Something Short and To the Point}</a></td> <td>Draft</td>
<tr> <td>template</td> <td class="left"><a href="zips/zip-template.md">{Template for new ZIPs}</a></td> <td>Draft</td>
Expand Down
Loading
Loading