Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Host Documentation for multiple versions/branch #188

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
74 changes: 45 additions & 29 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,61 @@
name: Doc
name: Generate Documentation

on:
push:
branches:
- main
workflow_dispatch:


permissions:
contents: write
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: true

jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1

- name: Install Rust Toolchain
uses: rs-workspace/rust-toolchain@v0.1.0
with:
toolchain: nightly
- run: cargo doc --workspace --no-deps
- uses: "finnp/create-file-action@master"
env:
FILE_NAME: "./target/doc/index.html"
FILE_DATA: '<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0;url=''./azalea''"/></head></html>' # Redirect to default page

- name: Setup Pages
uses: actions/configure-pages@v2
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
path: './target/doc/'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1

- name: Generate Documentation
run: RUSTDOCFLAGS="--enable-index-page -Zunstable-options" cargo doc --workspace --no-deps

- name: Prepare Documentation
run: |
BRANCH_NAME=$(echo "${GITHUB_REF##*/}" | tr '/' '_') # Get branch name safely
mkdir -p versioned_docs/$BRANCH_NAME
cp -r target/doc/* versioned_docs/$BRANCH_NAME

- name: Checkout to Docs Branch
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git fetch origin docs || git checkout --orphan docs
git checkout docs
cp -r versioned_docs/* ./ # Copy docs to branch root
rm -rf versioned_docs # Clean up
rm -rf target # Clean up

- name: Generate README.md
run: |
VERSIONS=$(ls -d */ | sed 's#/##' | sort -r) # Get all version directories and sort them (latest first)
rm README.md # Delete README.md and generate a new one
echo "# Azalea Docs" > README.md
echo "Welcome to the documentation for Azalea Crate." >> README.md
echo "" >> README.md

# Update README.md with available versions
echo "## Available Versions" >> README.md
for VERSION in $VERSIONS; do
echo "- [$VERSION](./$VERSION/index.html)" >> README.md
done

echo "README.md updated successfully."

- name: Deploy Documentation to Docs Branch
run: |
git add .
git commit -m "Update documentation for $GITHUB_REF_NAME" || echo "No changes to commit"
git push origin docs
Loading