From 385e4087ea18de4f0cc7d7187d4a5ba98f6e84dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Leegwater=20Sim=C3=B5es?= Date: Thu, 16 Nov 2023 01:09:12 +0100 Subject: [PATCH] Add "ci" and "publish" workflows The `ci` workflow will trigger the others appropriately, depending whether it is a release (semver tag), or a pull request or a push to master --- .github/workflows/check.yml | 9 ++------- .github/workflows/ci.yml | 24 ++++++++++++++++++++++++ .github/workflows/publish.yml | 28 ++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 357949a..4f1f468 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -1,11 +1,6 @@ -name: Check `healm` +name: Check on: - push: - branches: - - master - pull_request: - branches: - - master + workflow_call: jobs: test: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..008fa2e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,24 @@ +name: CI + +on: + pull_request: + branches: + - master + push: + branches: + - master + tags: + - v*.*.* + +jobs: + check: + uses: ./.github/workflows/check.yml + + publish: + uses: ./.github/workflows/publish.yml + if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') + needs: check + with: + version: ${{ github.ref_name }} + secrets: + crates-io-token: ${{ secrets.CRATES_IO_TOKEN }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..7b8f4c4 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,28 @@ +name: Publish +on: + workflow_call: + inputs: + version: + description: 'Semver of the version to publish' + type: string + required: true + secrets: + crates-io-token: + description: 'Token for publishing to crates.io' + required: true + +jobs: + publish: + runs-on: ubuntu-latest + container: + image: rust:latest + steps: + - uses: actions/checkout@v3 + - name: check manifest version + run: | + version=$(grep -oP '(?<=^version = ").*(?="$)' Cargo.toml) + if [ "$version" != "${{ inputs.version }}" ]; then + echo "Version mismatch: Cargo.toml version is $version, but workflow input version is ${{ inputs.version }}" + exit 1 + fi + - run: cargo publish --token ${{ secrets.crates-io-token }} --dry-run