fix: remove nested html/ from mdBook output before deploy #55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Workflow for building and deploying a mdBook site to GitHub Pages. | |
| # - On push to main: deploys to docs/ on gh-pages. | |
| # - On pull_request: deploys a preview under pr-preview/pr-<number>/ on gh-pages, | |
| # comments the preview URL, and cleans up when the PR closes. | |
| # | |
| # Repo Settings required: | |
| # Pages -> Source: "Deploy from a branch" -> gh-pages / /docs | |
| # Actions -> General -> Workflow permissions: "Read and write permissions" | |
| # | |
| # See: https://rust-lang.github.io/mdBook/index.html | |
| name: Deploy mdBook site to Pages | |
| on: | |
| push: | |
| branches: ["main"] | |
| pull_request: | |
| types: [opened, synchronize, reopened, closed] | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| deploy: | |
| if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' | |
| runs-on: ubuntu-latest | |
| concurrency: | |
| group: pages | |
| cancel-in-progress: false | |
| env: | |
| CARGO_HOME: ${{ github.workspace }}/.cargo | |
| RUSTUP_HOME: ${{ github.workspace }}/.rustup | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Cache Cargo registry and git index | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ${{ env.CARGO_HOME }}/registry | |
| ${{ env.CARGO_HOME }}/git | |
| key: ${{ runner.os }}-cargo-registry-${{ hashFiles('scripts/install-mdbook.sh') }} | |
| restore-keys: | | |
| ${{ runner.os }}-cargo-registry- | |
| # Cache full RUSTUP_HOME (rustc + toolchain + settings) so rustup does minimal work on restore. | |
| - name: Cache Rust toolchain (rustc) | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ env.RUSTUP_HOME }} | |
| key: ${{ runner.os }}-rust-toolchain-${{ hashFiles('scripts/install-mdbook.sh') }} | |
| restore-keys: | | |
| ${{ runner.os }}-rust-toolchain- | |
| # Exact key only (no restore-keys) so we never restore a bin/ missing a tool (e.g. linkcheck2). | |
| - name: Cache installed mdBook binaries | |
| id: mdbook-cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ${{ env.CARGO_HOME }}/bin | |
| key: ${{ runner.os }}-mdbook-bin-${{ hashFiles('scripts/install-mdbook.sh') }} | |
| # Script skips install when cached binaries already match versions in install-mdbook.sh | |
| - name: Install mdBook | |
| run: bash scripts/install-mdbook.sh | |
| env: | |
| REPO_ROOT: ${{ github.workspace }} | |
| - name: Add Cargo bin to PATH | |
| run: echo "${CARGO_HOME}/bin" >> "$GITHUB_PATH" | |
| - name: Build with mdBook | |
| run: ${{ env.CARGO_HOME }}/bin/mdbook build | |
| - name: Remove nested html output | |
| run: rm -rf ./book/html | |
| - name: Deploy to GitHub Pages | |
| uses: JamesIves/github-pages-deploy-action@v4 | |
| with: | |
| branch: gh-pages | |
| folder: ./book | |
| target-folder: docs | |
| clean: true | |
| clean-exclude: pr-preview | |
| gqm-main: | |
| needs: deploy | |
| uses: ./.github/workflows/gqm_update.yml | |
| preview: | |
| if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository | |
| runs-on: ubuntu-latest | |
| concurrency: preview-${{ github.ref }} | |
| env: | |
| CARGO_HOME: ${{ github.workspace }}/.cargo | |
| RUSTUP_HOME: ${{ github.workspace }}/.rustup | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Cache Cargo registry and git index | |
| if: github.event.action != 'closed' | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ${{ env.CARGO_HOME }}/registry | |
| ${{ env.CARGO_HOME }}/git | |
| key: ${{ runner.os }}-cargo-registry-${{ hashFiles('scripts/install-mdbook.sh') }} | |
| restore-keys: | | |
| ${{ runner.os }}-cargo-registry- | |
| # Cache full RUSTUP_HOME (rustc + toolchain + settings) so rustup does minimal work on restore. | |
| - name: Cache Rust toolchain (rustc) | |
| if: github.event.action != 'closed' | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ env.RUSTUP_HOME }} | |
| key: ${{ runner.os }}-rust-toolchain-${{ hashFiles('scripts/install-mdbook.sh') }} | |
| restore-keys: | | |
| ${{ runner.os }}-rust-toolchain- | |
| # Exact key only (no restore-keys) so we never restore a bin/ missing a tool (e.g. linkcheck2). | |
| - name: Cache installed mdBook binaries | |
| if: github.event.action != 'closed' | |
| id: mdbook-cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ${{ env.CARGO_HOME }}/bin | |
| key: ${{ runner.os }}-mdbook-bin-${{ hashFiles('scripts/install-mdbook.sh') }} | |
| # Script skips install when cached binaries already match versions in install-mdbook.sh | |
| - name: Install mdBook | |
| if: github.event.action != 'closed' | |
| run: bash scripts/install-mdbook.sh | |
| env: | |
| REPO_ROOT: ${{ github.workspace }} | |
| - name: Add Cargo bin to PATH | |
| if: github.event.action != 'closed' | |
| run: echo "${CARGO_HOME}/bin" >> "$GITHUB_PATH" | |
| - name: Set preview site-url | |
| if: github.event.action != 'closed' | |
| run: | | |
| sed -i 's|site-url = "/managing-innersource-projects/"|site-url = "/managing-innersource-projects/pr-preview/pr-${{ github.event.pull_request.number }}/"|' book.toml | |
| - name: Build with mdBook | |
| if: github.event.action != 'closed' | |
| run: ${{ env.CARGO_HOME }}/bin/mdbook build | |
| - name: Remove nested html output | |
| if: github.event.action != 'closed' | |
| run: rm -rf ./book/html | |
| - name: Deploy PR preview | |
| uses: rossjrw/pr-preview-action@v1 | |
| with: | |
| source-dir: ./book | |
| preview-branch: gh-pages | |
| umbrella-dir: pr-preview | |
| gqm-preview: | |
| if: github.event_name == 'pull_request' && github.event.action != 'closed' && github.event.pull_request.head.repo.full_name == github.repository | |
| needs: preview | |
| uses: ./.github/workflows/gqm_update.yml |