diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ff448d8..9d9bf21 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,13 +1,15 @@ -name: ci +name: SDK Release -on: [push, pull_request] - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: false +on: + workflow_dispatch: + pull_request: + types: [closed] + branches: + - main jobs: compile: + if: github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true runs-on: ubuntu-latest steps: - name: Checkout repo @@ -33,6 +35,7 @@ jobs: fi test: + if: github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true runs-on: ubuntu-latest steps: - name: Checkout repo @@ -57,25 +60,86 @@ jobs: poetry run pytest -rP . fi - publish: + release: needs: [compile, test] - if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') runs-on: ubuntu-latest + permissions: + contents: write + steps: - - name: Checkout repo + - name: Checkout main uses: actions/checkout@v4 + with: + ref: main + fetch-depth: 0 + + - name: Read version from pyproject.toml + id: version + run: | + VERSION=$(grep -m1 '^version = ' pyproject.toml | grep -oP '"\K[^"]+') + if [ -z "$VERSION" ]; then + echo "ERROR: Could not read version from pyproject.toml" + exit 1 + fi + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT + echo "TAG=v$VERSION" >> $GITHUB_OUTPUT + + - name: Get latest git tag + id: latest_tag + run: | + LATEST=$(git describe --tags --abbrev=0 2>/dev/null || echo "none") + echo "LATEST_TAG=$LATEST" >> $GITHUB_OUTPUT + + - name: Check if version was bumped + id: check + run: | + TAG="${{ steps.version.outputs.TAG }}" + LATEST="${{ steps.latest_tag.outputs.LATEST_TAG }}" + if [ "$TAG" = "$LATEST" ]; then + echo "bumped=false" >> $GITHUB_OUTPUT + echo "Version $TAG already tagged — skipping release." + else + echo "bumped=true" >> $GITHUB_OUTPUT + echo "New version detected: $TAG (previous: $LATEST)" + fi + - name: Set up python + if: steps.check.outputs.bumped == 'true' uses: actions/setup-python@v4 with: python-version: "3.10" + - name: Bootstrap poetry + if: steps.check.outputs.bumped == 'true' run: | curl -sSL https://install.python-poetry.org | python - -y --version 1.5.1 + - name: Install dependencies + if: steps.check.outputs.bumped == 'true' run: poetry install - - name: Publish to pypi + + - name: Create and push tag + if: steps.check.outputs.bumped == 'true' + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git tag "${{ steps.version.outputs.TAG }}" + git push origin "${{ steps.version.outputs.TAG }}" + + - name: Publish to PyPI + if: steps.check.outputs.bumped == 'true' run: | poetry config pypi-token.pypi "$PYPI_TOKEN" poetry --no-interaction -v publish --build env: PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} + + - name: Create GitHub release with generated notes + if: steps.check.outputs.bumped == 'true' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release create "${{ steps.version.outputs.TAG }}" \ + --title "${{ steps.version.outputs.TAG }}" \ + --generate-notes \ + --latest \ No newline at end of file