diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..0ad80f2 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,62 @@ +on: + release: + types: + - prereleased + - released + +name: Release + +env: + TAG: ${{ github.event.release.tag_name }} + +jobs: + check-version: + name: Check Version + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Version + run: | + set -ex + cargo_version="$(sed -n 's/^version\s*=\s*"\(.*\)"\s*$/\1/p' Cargo.toml)" + test "$cargo_version" = "${TAG#v}" + + test: + name: Test + needs: check-version + uses: ./.github/workflows/test.yml + + publish: + name: Publish + needs: test + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - uses: taiki-e/install-action@v2 + with: + tool: protoc,sccache + - name: Install toolchain + uses: dtolnay/rust-toolchain@stable + - name: Package + run: | + cargo package + - name: Publish + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + run: | + cargo publish + + failure: + needs: [check-version, test, publish] + if: cancelled() || failure() + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Remove tag + run: | + git push --delete origin "$TAG" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bec5a85..51461a0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,6 +3,7 @@ on: branches: [ "main" ] pull_request: branches: [ "main" ] + workflow_call: name: Test