From 4f76aa9980d5af9415c9f53ac9f4558ca86f180f Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Sat, 6 Jul 2024 13:24:02 -0400 Subject: [PATCH 1/2] book: Publish both main and latest-release versions Also change the index to redirect to the latest release instead of `main`. --- .github/workflows/book.yml | 43 +++++++++++++++++++++++++------------- book/head_redirect.html | 8 ------- book/redirect.html | 8 +++++++ 3 files changed, 36 insertions(+), 23 deletions(-) delete mode 100644 book/head_redirect.html create mode 100644 book/redirect.html diff --git a/.github/workflows/book.yml b/.github/workflows/book.yml index ba1369f97..c8dd40de3 100644 --- a/.github/workflows/book.yml +++ b/.github/workflows/book.yml @@ -2,6 +2,7 @@ name: Book on: push: branches: [main] + tags: ['*'] permissions: contents: write # Adapted from: @@ -21,24 +22,36 @@ jobs: echo `pwd`/mdbook >> $GITHUB_PATH - name: Deploy GitHub Pages run: | - cd book - mdbook build - git worktree add gh-pages gh-pages + # Configure git user so that `git commit` works. git config user.name "Deploy from CI" git config user.email "" - cd gh-pages + + # Get the highest `uefi` release tag. + highest_tag="$(git tag --list | grep uefi-v | sort -V | tail -1)" + + # Create worktrees for both the `main` branch and the highest tag. + git worktree add --detach wt-main main + git worktree add --detach wt-tag "${highest_tag}" + + # Create a worktree for the `gh-pages` branch. + git worktree add wt-gh-pages gh-pages + # Delete the ref to avoid keeping history. - git update-ref -d refs/heads/gh-pages - # Place the book under a "HEAD" directory so that we can later - # add other versions (e.g. "stable" or "v0.17") without breaking - # URLs. - rm -rf HEAD - mv ../book HEAD - git add HEAD - # Add an index in the root to redirect to HEAD. If we eventually - # serve multiple versions, this can be changed to a real index. - cp ../head_redirect.html index.html - git add index.html + git -C wt-gh-pages update-ref -d refs/heads/gh-pages + + # Delete existing book builds. + rm -rf wt-gh-pages/HEAD wt-gh-pages/latest-release + + # Build the book for both `main` and the highest tag. + mdbook build --dest-dir wt-gh-pages/HEAD wt-main + mdbook build --dest-dir wt-gh-pages/latest-release wt-tag + + cd wt-gh-pages + + # Add an index in the root to redirect to the latest release. + cp ../redirect.html index.html + # Commit and push. + git add HEAD latest-release index.html git commit -m "Deploy $GITHUB_SHA to gh-pages" git push --force diff --git a/book/head_redirect.html b/book/head_redirect.html deleted file mode 100644 index 7c75cfd02..000000000 --- a/book/head_redirect.html +++ /dev/null @@ -1,8 +0,0 @@ - - - -Redirecting to latest documentation - - - -Redirecting to ./HEAD... diff --git a/book/redirect.html b/book/redirect.html new file mode 100644 index 000000000..4c1ec9acb --- /dev/null +++ b/book/redirect.html @@ -0,0 +1,8 @@ + + + +Redirecting to latest release documentation + + + +Redirecting to ./latest-release... From 46ff933c38df995526c4d91538c7eae1784dee44 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Sat, 6 Jul 2024 13:25:13 -0400 Subject: [PATCH 2/2] wip --- .github/workflows/book.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/book.yml b/.github/workflows/book.yml index c8dd40de3..a3f2225da 100644 --- a/.github/workflows/book.yml +++ b/.github/workflows/book.yml @@ -9,7 +9,7 @@ permissions: # https://github.com/rust-lang/mdBook/wiki/Automated-Deployment%3A-GitHub-Actions#github-pages-deploy jobs: deploy: - if: github.repository == 'rust-osdev/uefi-rs' + # if: github.repository == 'rust-osdev/uefi-rs' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4