diff --git a/.github/workflows/publish-wheels.yml b/.github/workflows/publish-wheels.yml new file mode 100644 index 00000000..7d36b852 --- /dev/null +++ b/.github/workflows/publish-wheels.yml @@ -0,0 +1,58 @@ +name: Publish Wheels + +on: + push: + tags: + - "v[0-9]*" + - "test*" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + with: + ref: ${{ github.ref }} + fetch-depth: 0 + + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Build wheel and sdist + run: | + python -m pip install --upgrade pip build + python -m build + + - uses: actions/upload-artifact@v4 + with: + name: dist + path: dist/* + + publish: + name: Publish to PyPI + needs: [build] + runs-on: ubuntu-latest + permissions: + id-token: write + contents: read + steps: + - uses: actions/download-artifact@v4 + with: + name: dist + path: dist + + - name: Publish to TestPyPI (test tags) + if: startsWith(github.ref, 'refs/tags/test') + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + packages-dir: dist + skip-existing: true + verbose: true + + - name: Publish to PyPI (real releases) + if: startsWith(github.ref, 'refs/tags/v') + uses: pypa/gh-action-pypi-publish@release/v1 + with: + packages-dir: dist diff --git a/.github/workflows/pull_request_closed.yml b/.github/workflows/pull_request_closed.yml index 52ed0d63..42fd6b5b 100644 --- a/.github/workflows/pull_request_closed.yml +++ b/.github/workflows/pull_request_closed.yml @@ -19,11 +19,21 @@ jobs: ref: develop fetch-depth: 0 token: ${{ secrets.BOT_ACCESS_TOKEN }} + - name: Bump version run: ./.github/workflows/version_bumper.sh ./pyproject.toml + id: bump + - name: Commit and push run: | git config user.name "AVSlabBot" git config user.email "cuavslab@gmail.com" git commit -a -m "[AUTO] Bump minor version number" git push + + - name: Create tag + if: ${{ steps.bump.outputs.updated_version != '' }} + run: | + git tag -a "v${{ steps.bump.outputs.updated_version }}" \ + -m "Release v${{ steps.bump.outputs.updated_version }}" + git push --tags diff --git a/.github/workflows/version_bumper.sh b/.github/workflows/version_bumper.sh index ae7d2465..ee19c165 100755 --- a/.github/workflows/version_bumper.sh +++ b/.github/workflows/version_bumper.sh @@ -23,12 +23,20 @@ if [[ $version_line =~ $regex ]]; then last_number=${BASH_REMATCH[2]} incremented_number=$((last_number + 1)) updated_version=${BASH_REMATCH[1]}$incremented_number - + # Update the version in the pyproject.toml file sed -i "s/version = \"${BASH_REMATCH[1]}${last_number}\"/version = \"$updated_version\"/" "$file" - + echo "Version updated to $updated_version in $file" else echo "Error: Version not found in $file or not in X.Y.Z format" exit 1 -fi \ No newline at end of file +fi + + +# Expose the update versions to GitHub Actions +if [[ -n "${GITHUB_OUTPUT:-}" ]]; then + { + echo "updated_version=$updated_version" + } >> "$GITHUB_OUTPUT" +fi