|
| 1 | +name: Publish release |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: [release/**] |
| 5 | +jobs: |
| 6 | + check_version_bump: |
| 7 | + name: Check version bump |
| 8 | + runs-on: ubuntu-latest |
| 9 | + permissions: |
| 10 | + contents: read |
| 11 | + steps: |
| 12 | + - name: Checkout |
| 13 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 |
| 14 | + - name: Setup Rust toolchain for ubuntu-latest |
| 15 | + uses: actions-rust-lang/setup-rust-toolchain@fb51252c7ba57d633bc668f941da052e410add48 |
| 16 | + - name: Read source branch version |
| 17 | + id: source_version |
| 18 | + run: echo "version=$(cargo read-manifest | jq -r .version)" >> $GITHUB_OUTPUT |
| 19 | + - name: Update cargo index |
| 20 | + run: cargo search |
| 21 | + - name: Read crates.io version |
| 22 | + id: crates_io_version |
| 23 | + run: echo "version=$(cargo search --limit 1 $(cargo read-manifest | jq -r .name) | grep -oP '(?<=")([0-9]+.[0-9]+.[0-9]+)(?=")')" >> $GITHUB_OUTPUT |
| 24 | + - name: Parse and compare versions |
| 25 | + run: | |
| 26 | + source_version="${{ steps.source_version.outputs.version }}" |
| 27 | + crates_io_version="${{ steps.crates_io_version.outputs.version }}" |
| 28 | + if [ "$(printf '%s\n' "$crates_io_version" "$source_version" | sort -V | head -n1)" != "$source_version" ]; then |
| 29 | + echo "Source branch version ($source_version) is higher than crates.io version ($crates_io_version)." |
| 30 | + else |
| 31 | + echo "Source branch version ($source_version) is not higher than crates.io version ($crates_io_version)." |
| 32 | + exit 1 |
| 33 | + fi |
| 34 | + crates_io: |
| 35 | + name: Publish crates.io |
| 36 | + needs: check_version_bump |
| 37 | + environment: CRATES_IO |
| 38 | + runs-on: ubuntu-latest |
| 39 | + permissions: |
| 40 | + contents: read |
| 41 | + steps: |
| 42 | + - name: Checkout |
| 43 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 |
| 44 | + - name: Setup Rust toolchain for ubuntu-latest |
| 45 | + uses: actions-rust-lang/setup-rust-toolchain@fb51252c7ba57d633bc668f941da052e410add48 |
| 46 | + - name: Login to crates.io |
| 47 | + uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505 |
| 48 | + with: |
| 49 | + command: login |
| 50 | + args: ${{ secrets.CRATES_IO_TOKEN }} |
| 51 | + - name: Publish to crates.io |
| 52 | + uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505 |
| 53 | + with: |
| 54 | + command: publish |
| 55 | + github: |
| 56 | + name: Publish GitHub |
| 57 | + needs: crates_io |
| 58 | + environment: GITHUB_RELEASE |
| 59 | + runs-on: ubuntu-latest |
| 60 | + permissions: |
| 61 | + contents: write |
| 62 | + steps: |
| 63 | + - name: Checkout |
| 64 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 |
| 65 | + - name: Setup Rust toolchain for ubuntu-latest |
| 66 | + uses: actions-rust-lang/setup-rust-toolchain@fb51252c7ba57d633bc668f941da052e410add48 |
| 67 | + - name: Package |
| 68 | + uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505 |
| 69 | + with: |
| 70 | + command: package |
| 71 | + args: --all-features |
| 72 | + - name: Read crate name |
| 73 | + id: crate_name |
| 74 | + run: echo "crate_name=$(cargo read-manifest | jq -r .name)" >> $GITHUB_OUTPUT |
| 75 | + - name: Read version |
| 76 | + id: version |
| 77 | + run: echo "version=$(cargo read-manifest | jq -r .version)" >> $GITHUB_OUTPUT |
| 78 | + - name: Create release |
| 79 | + env: |
| 80 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Provided by GitHub Actions |
| 81 | + run: gh release create "${{ steps.version.outputs.version }}" --repo="$GITHUB_REPOSITORY" --title="Release ${{ steps.version.outputs.version }}" --generate-notes --latest "./target/package/${{ steps.crate_name.outputs.crate_name }}-${{ steps.version.outputs.version }}.crate" |
0 commit comments