aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/doc.yml
blob: f2b577ef4315d7217b843a92327f0625c68bc523 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
name: Generate Documentation

on:
  push:
    branches:
      - main
      # only match branches that look like Minecraft versions
      - "*.*"
  workflow_dispatch:

permissions:
  contents: write

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v3

      - name: Install Rust Toolchain
        uses: rs-workspace/rust-toolchain@v0.1.0
        with:
          toolchain: nightly

      - 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 branches.html
        run: |
          VERSIONS=$(ls -d */ | sed 's#/##' | sort -r)  # Get all version directories and sort them (latest first)
          echo "<!DOCTYPE html>" > branches.html
          echo "<html lang=\"en\">" >> branches.html
          echo "<head>" >> branches.html
          echo "  <meta charset=\"UTF-8\">" >> branches.html
          echo "  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">" >> branches.html
          echo "  <title>Azalea Docs</title>" >> branches.html
          echo "</head>" >> branches.html
          echo "<body>" >> branches.html
          echo "  <h1>Azalea Docs</h1>" >> branches.html
          echo "  <p>Welcome to the documentation for Azalea.</p>" >> branches.html
          echo "  <h2>Available Versions</h2>" >> branches.html
          echo "  <ul>" >> branches.html

          # Update branches.html with available versions
          for VERSION in $VERSIONS; do
            echo "    <li><a href=\"https://azalea.matdoes.dev/$VERSION/index.html\">$VERSION</a></li>" >> branches.html
          done

          echo "  </ul>" >> branches.html
          echo "</body>" >> branches.html
          echo "</html>" >> branches.html

          echo "branches.html generated successfully."

      - name: Create Index Page
        run: |
          if [ ! -f index.html ]; then
            echo "<meta http-equiv=refresh content=0;url=main/azalea>" > index.html
          fi

      - 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