docs, cicd: Updated to only rebuild docs on major version #38
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
| name: Deploy Rustdoc to GitHub Pages | |
| on: | |
| push: | |
| branches: [master] | |
| paths: | |
| - 'rosy/Cargo.toml' | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: true | |
| jobs: | |
| check-version: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| is_new: ${{ steps.check.outputs.is_new }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check if version changed | |
| id: check | |
| run: | | |
| # Always deploy on workflow_dispatch | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| echo "is_new=true" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| VERSION=$(grep '^version' rosy/Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/') | |
| if git rev-parse "v$VERSION" >/dev/null 2>&1; then | |
| echo "is_new=false" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "is_new=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| build: | |
| needs: check-version | |
| if: needs.check-version.outputs.is_new == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Build documentation | |
| run: cargo doc --document-private-items --no-deps -p rosy | |
| - name: Add redirect index.html | |
| run: echo '<meta http-equiv="refresh" content="0;url=rosy/index.html">' > target/doc/index.html | |
| - name: Upload Pages artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: target/doc | |
| deploy: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |