|
| 1 | +name: "Build documentation index" |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - master |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + build-and-deploy: |
| 16 | + name: Build index.html |
| 17 | + runs-on: ubuntu-latest |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Cache git metadata |
| 21 | + uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4 |
| 22 | + with: |
| 23 | + path: .git |
| 24 | + key: git-metadata-${{ github.sha }} |
| 25 | + restore-keys: | |
| 26 | + git-metadata-${{ github.sha }} |
| 27 | + git-metadata |
| 28 | +
|
| 29 | + - name: Checkout Github Pages branch |
| 30 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 31 | + with: |
| 32 | + fetch-depth: 0 |
| 33 | + token: ${{ github.event_name == 'push' && secrets.COMMAND_BOT_PAT || github.token }} |
| 34 | + |
| 35 | + - name: Get stable branches |
| 36 | + id: branch |
| 37 | + run: | |
| 38 | + branches=$(git ls-remote --heads origin "heads/stable[0-9][0-9]" | awk '{gsub(/^refs\/heads\/stable/, "", $2); print $2}' | sort -n -r | tr '\n' ' ') |
| 39 | + echo "branches=$branches" >> $GITHUB_OUTPUT |
| 40 | +
|
| 41 | + - name: Setup php |
| 42 | + uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2.37.0 |
| 43 | + |
| 44 | + - name: Generate index.html |
| 45 | + run: | |
| 46 | + php build/build-index.php ${{ steps.branch.outputs.branches }} |
| 47 | + mv build/index.html /tmp/index.html |
| 48 | + mv build/static/ /tmp/static/ |
| 49 | +
|
| 50 | + - name: Verify index.html structure and links |
| 51 | + run: | |
| 52 | + # Temporarily put index.html in build folder for verification |
| 53 | + cp /tmp/index.html build/index.html |
| 54 | + php build/verify-index.php |
| 55 | +
|
| 56 | + - name: Switch to gh-pages branch |
| 57 | + if: github.event_name == 'push' |
| 58 | + run: | |
| 59 | + git fetch origin gh-pages |
| 60 | + git checkout gh-pages |
| 61 | + git config --local user.email "nextcloud-command@users.noreply.github.com" |
| 62 | + git config --local user.name "nextcloud-command" |
| 63 | + |
| 64 | + - name: Commit and push changes |
| 65 | + if: github.event_name == 'push' |
| 66 | + run: | |
| 67 | + # Move the generated index.html and static files to the root of the gh-pages branch |
| 68 | + rm -rf index.html static/ |
| 69 | + mv /tmp/index.html index.html |
| 70 | + mv /tmp/static/ static/ |
| 71 | + git add index.html static/ |
| 72 | + git commit -m "chore: update index.html for documentation" || echo "No changes to commit" |
| 73 | + git push origin gh-pages || echo "Nothing to push (expected if no changes)" |
| 74 | + env: |
| 75 | + GH_TOKEN: ${{ secrets.COMMAND_BOT_PAT }} |
0 commit comments