From 36d019ea0f8d1c14d4f0acafba5d648f5a0d5a8f Mon Sep 17 00:00:00 2001 From: Mattt Date: Wed, 31 Jul 2024 09:39:13 -0700 Subject: [PATCH] Extract release process into separate workflow (#1839) * Extract release process into separate workflow * Remove workflow_dispatch trigger --- .github/workflows/ci.yaml | 44 +-------------------- .github/workflows/release.yaml | 70 ++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 81a4e3e5d..9687cda72 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -5,7 +5,7 @@ on: branches: - main tags: - - "**" + - "v*" pull_request: branches: - main @@ -93,45 +93,3 @@ jobs: python -m uv pip install '.[dev]' - name: Test run: make test-integration - - release: - needs: - - test-go - - test-python - - test-integration - if: startsWith(github.ref, 'refs/tags/v') - outputs: - cog_version: ${{ steps.build-python-package.outputs.version }} - runs-on: ubuntu-latest-8-cores - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - - name: Build - run: make cog - - uses: goreleaser/goreleaser-action@v4 - with: - version: latest - args: release --clean - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Build Python package - id: build-python-package - run: | - # clean package built for go client - rm -rf dist - # install build - pip install build - # build package - python -m build --wheel - # set output - echo "version=$(ls dist/ | cut -d- -f2)" >> $GITHUB_OUTPUT - - name: Push Python package - uses: pypa/gh-action-pypi-publish@release/v1 - with: - user: __token__ - password: ${{ secrets.PYPI_TOKEN }} - packages-dir: dist diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 000000000..19bbe63c0 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,70 @@ +name: Release + +on: + workflow_run: + workflows: ["CI"] + types: + - completed + branches: + - main + +concurrency: + group: release-${{ github.ref }} + cancel-in-progress: true + +jobs: + check-tag: + name: "Check Tag" + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + outputs: + is-release: ${{ steps.check-tag.outputs.is-release }} + steps: + - name: Check if commit has a version tag + id: check-tag + run: | + if [[ ${{ github.event.workflow_run.head_branch }} =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "is-release=true" >> $GITHUB_OUTPUT + else + echo "is-release=false" >> $GITHUB_OUTPUT + fi + + release-cli: + name: "CLI" + needs: check-tag + if: needs.check-tag.outputs.is-release == 'true' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - name: Build + run: make cog + - uses: goreleaser/goreleaser-action@v4 + with: + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + release-python-package: + name: "Python Package" + needs: check-tag + if: needs.check-tag.outputs.is-release == 'true' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.12 + - name: Build Python package + run: | + pip install build + python -m build --wheel + - name: Push Python package + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_TOKEN }} + packages-dir: dist