name: Documentation
on:
push:
branches: [ main ]
tags: [ 'v*' ]
workflow_dispatch:
permissions:
contents: write
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
build-and-deploy:
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout repository
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 with:
fetch-depth: 0
- name: Install Rust
uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 with:
toolchain: stable
- name: Rust Cache
uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4
- name: Build documentation
run: |
RUSTDOCFLAGS="--html-in-header docs/docs-header.html" cargo doc --no-deps --all-features
- name: Prepare deployment
run: |
mkdir -p target/deploy
# Determine version
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
else
VERSION="latest"
fi
# Initialize target/deploy with existing gh-pages content if possible
git checkout gh-pages || git checkout -b gh-pages
cp -r . target/deploy_tmp || true
git checkout $GITHUB_SHA
if [ -d "target/deploy_tmp" ]; then
cp -r target/deploy_tmp/* target/deploy/ || true
rm -rf target/deploy_tmp
fi
# Copy new docs to versioned directory
mkdir -p target/deploy/$VERSION
cp -r target/doc/* target/deploy/$VERSION/
# Create root redirect to latest
cat <<EOF > target/deploy/index.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="0; url=latest/pinner/index.html">
</head>
<body>
<p>Redirecting to <a href="latest/pinner/index.html">latest documentation</a>...</p>
</body>
</html>
EOF
# Update versions.json
# Get all directories in target/deploy that match latest or v*
cd target/deploy
VERSIONS=$(ls -d latest v* 2>/dev/null | sort -V -r | jq -R . | jq -s .)
# Ensure 'latest' is first
if echo "$VERSIONS" | jq -e '. | contains(["latest"])' > /dev/null; then
VERSIONS=$(echo "$VERSIONS" | jq '["latest"] + (. - ["latest"])')
fi
echo "$VERSIONS" > versions.json
cd ../..
- name: Setup Pages
uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d
- name: Upload artifact
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 with:
path: 'target/deploy'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@cd2ce8fcbc39b97be8ca5fce6e763baed58fa128