|
1 | | -name: Generate Documentation |
| 1 | +name: Doc |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | 5 | branches: |
6 | 6 | - main |
7 | | - # only match branches that look like Minecraft versions |
8 | | - - "*.*" |
9 | 7 | workflow_dispatch: |
10 | 8 |
|
| 9 | + |
11 | 10 | permissions: |
12 | 11 | contents: write |
| 12 | + pages: write |
| 13 | + id-token: write |
| 14 | + |
| 15 | +concurrency: |
| 16 | + group: "pages" |
| 17 | + cancel-in-progress: true |
13 | 18 |
|
14 | 19 | jobs: |
15 | 20 | deploy: |
| 21 | + environment: |
| 22 | + name: github-pages |
| 23 | + url: ${{ steps.deployment.outputs.page_url }} |
16 | 24 | runs-on: ubuntu-latest |
17 | 25 | steps: |
18 | 26 | - name: Checkout Repository |
19 | 27 | uses: actions/checkout@v3 |
20 | | - |
21 | | - - name: Install Rust Toolchain |
22 | | - uses: rs-workspace/rust-toolchain@v0.1.0 |
| 28 | + - uses: actions-rs/toolchain@v1 |
23 | 29 | with: |
24 | 30 | toolchain: nightly |
25 | | - |
26 | | - - name: Generate Documentation |
27 | | - run: RUSTDOCFLAGS="--enable-index-page -Zunstable-options" cargo doc --workspace --no-deps |
28 | | - |
29 | | - - name: Prepare Documentation |
30 | | - run: | |
31 | | - BRANCH_NAME=$(echo "${GITHUB_REF##*/}" | tr '/' '_') # Get branch name safely |
32 | | - mkdir -p versioned_docs/$BRANCH_NAME |
33 | | - cp -r target/doc/* versioned_docs/$BRANCH_NAME |
34 | | -
|
35 | | - - name: Checkout to Docs Branch |
36 | | - run: | |
37 | | - git config --global user.name "github-actions[bot]" |
38 | | - git config --global user.email "github-actions[bot]@users.noreply.github.com" |
39 | | - git fetch origin docs || git checkout --orphan docs |
40 | | - git checkout docs |
41 | | - cp -r versioned_docs/* ./ # Copy docs to branch root |
42 | | - rm -rf versioned_docs # Clean up |
43 | | - rm -rf target # Clean up |
44 | | -
|
45 | | - - name: Generate branches.html |
46 | | - run: | |
47 | | - VERSIONS=$(ls -d */ | sed 's#/##' | sort -r) # Get all version directories and sort them (latest first) |
48 | | - echo "<!DOCTYPE html>" > branches.html |
49 | | - echo "<html lang=\"en\">" >> branches.html |
50 | | - echo "<head>" >> branches.html |
51 | | - echo " <meta charset=\"UTF-8\">" >> branches.html |
52 | | - echo " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">" >> branches.html |
53 | | - echo " <title>Azalea Docs</title>" >> branches.html |
54 | | - echo "</head>" >> branches.html |
55 | | - echo "<body>" >> branches.html |
56 | | - echo " <h1>Azalea Docs</h1>" >> branches.html |
57 | | - echo " <p>Welcome to the documentation for Azalea.</p>" >> branches.html |
58 | | - echo " <h2>Available Versions</h2>" >> branches.html |
59 | | - echo " <ul>" >> branches.html |
60 | | -
|
61 | | - # Update branches.html with available versions |
62 | | - for VERSION in $VERSIONS; do |
63 | | - echo " <li><a href=\"https://azalea.matdoes.dev/$VERSION/index.html\">$VERSION</a></li>" >> branches.html |
64 | | - done |
65 | | -
|
66 | | - echo " </ul>" >> branches.html |
67 | | - echo "</body>" >> branches.html |
68 | | - echo "</html>" >> branches.html |
69 | | -
|
70 | | - echo "branches.html generated successfully." |
71 | | -
|
72 | | - - name: Create Index Page |
73 | | - run: | |
74 | | - if [ ! -f index.html ]; then |
75 | | - echo "<meta http-equiv=refresh content=0;url=main/azalea>" > index.html |
76 | | - fi |
77 | | -
|
78 | | - - name: Deploy Documentation to Docs Branch |
79 | | - run: | |
80 | | - git add . |
81 | | - git commit -m "Update documentation for $GITHUB_REF_NAME" || echo "No changes to commit" |
82 | | - git push origin docs |
| 31 | + - run: cargo doc --workspace --no-deps |
| 32 | + - uses: "finnp/create-file-action@master" |
| 33 | + env: |
| 34 | + FILE_NAME: "./target/doc/index.html" |
| 35 | + FILE_DATA: '<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0;url=''./azalea''"/></head></html>' # Redirect to default page |
| 36 | + |
| 37 | + - name: Setup Pages |
| 38 | + uses: actions/configure-pages@v2 |
| 39 | + - name: Upload artifact |
| 40 | + uses: actions/upload-pages-artifact@v1 |
| 41 | + with: |
| 42 | + path: './target/doc/' |
| 43 | + - name: Deploy to GitHub Pages |
| 44 | + id: deployment |
| 45 | + uses: actions/deploy-pages@v1 |
0 commit comments