|
| 1 | +name: Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v[0-9]+.[0-9]+.[0-9]+' |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + pages: write |
| 11 | + id-token: write |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: 'pages' |
| 15 | + cancel-in-progress: false |
| 16 | + |
| 17 | +env: |
| 18 | + CARGO_TERM_COLOR: always |
| 19 | + RUST_BACKTRACE: 1 |
| 20 | + |
| 21 | +jobs: |
| 22 | + verify-tag: |
| 23 | + name: Verify Tag |
| 24 | + runs-on: ubuntu-latest |
| 25 | + outputs: |
| 26 | + should_deploy: ${{ steps.check.outputs.should_deploy }} |
| 27 | + steps: |
| 28 | + - name: Checkout code |
| 29 | + uses: actions/checkout@v4 |
| 30 | + with: |
| 31 | + fetch-depth: 0 |
| 32 | + |
| 33 | + - name: Check if tag is on main or master branch |
| 34 | + id: check |
| 35 | + run: | |
| 36 | + git fetch origin main master || true |
| 37 | + BRANCHES=$(git branch -r --contains ${{ github.ref }}) |
| 38 | + |
| 39 | + if echo "$BRANCHES" | grep -qE 'origin/(main|master)'; then |
| 40 | + echo "✓ Tag is on main or master branch" |
| 41 | + echo "should_deploy=true" >> $GITHUB_OUTPUT |
| 42 | + else |
| 43 | + echo "✗ Tag is not on main or master branch, skipping deployment" |
| 44 | + echo "Tag is on: $BRANCHES" |
| 45 | + echo "should_deploy=false" >> $GITHUB_OUTPUT |
| 46 | + fi |
| 47 | + |
| 48 | + - name: Verify version consistency |
| 49 | + if: steps.check.outputs.should_deploy == 'true' |
| 50 | + run: | |
| 51 | + # Extract version from git tag (remove 'v' prefix) |
| 52 | + TAG_VERSION="${{ github.ref_name }}" |
| 53 | + TAG_VERSION="${TAG_VERSION#v}" |
| 54 | + # Extract version from Cargo.toml |
| 55 | + CARGO_VERSION=$(grep -m1 '^version' Cargo.toml | sed 's/.*"\(.*\)"/\1/') |
| 56 | + echo "Git tag version: $TAG_VERSION" |
| 57 | + echo "Cargo.toml version: $CARGO_VERSION" |
| 58 | + if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then |
| 59 | + echo "ERROR: Version mismatch! Tag version ($TAG_VERSION) != Cargo.toml version ($CARGO_VERSION)" |
| 60 | + exit 1 |
| 61 | + fi |
| 62 | + echo "✓ Version check passed!" |
| 63 | +
|
| 64 | + check: |
| 65 | + uses: ./.github/workflows/check.yml |
| 66 | + needs: verify-tag |
| 67 | + if: needs.verify-tag.outputs.should_deploy == 'true' |
| 68 | + |
| 69 | + test: |
| 70 | + uses: ./.github/workflows/test.yml |
| 71 | + needs: verify-tag |
| 72 | + if: needs.verify-tag.outputs.should_deploy == 'true' |
| 73 | + |
| 74 | + build: |
| 75 | + name: Build documentation |
| 76 | + runs-on: ubuntu-latest |
| 77 | + needs: [verify-tag, check, test] |
| 78 | + if: needs.verify-tag.outputs.should_deploy == 'true' |
| 79 | + steps: |
| 80 | + - name: Checkout code |
| 81 | + uses: actions/checkout@v4 |
| 82 | + |
| 83 | + - name: Install Rust toolchain |
| 84 | + uses: dtolnay/rust-toolchain@nightly |
| 85 | + |
| 86 | + - name: Build docs |
| 87 | + env: |
| 88 | + RUSTDOCFLAGS: -D rustdoc::broken_intra_doc_links -D missing-docs |
| 89 | + run: | |
| 90 | + cargo doc --no-deps --all-features |
| 91 | + printf '<meta http-equiv="refresh" content="0;url=%s/index.html">' $(cargo tree | head -1 | cut -d' ' -f1) > target/doc/index.html |
| 92 | +
|
| 93 | + - name: Upload artifact |
| 94 | + uses: actions/upload-pages-artifact@v3 |
| 95 | + with: |
| 96 | + path: target/doc |
| 97 | + |
| 98 | + deploy: |
| 99 | + name: Deploy to GitHub Pages |
| 100 | + environment: |
| 101 | + name: github-pages |
| 102 | + url: ${{ steps.deployment.outputs.page_url }} |
| 103 | + runs-on: ubuntu-latest |
| 104 | + needs: [verify-tag, build] |
| 105 | + if: needs.verify-tag.outputs.should_deploy == 'true' |
| 106 | + steps: |
| 107 | + - name: Deploy to GitHub Pages |
| 108 | + id: deployment |
| 109 | + uses: actions/deploy-pages@v4 |
0 commit comments