Add GitHub Actions workflow for versioning and release #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Auto-bump version, release, and publish | |
| on: | |
| push: | |
| branches: | |
| - Publish | |
| permissions: | |
| contents: write | |
| jobs: | |
| bump-release-publish: | |
| name: Auto-bump version and publish | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| python -m pip install build twine toml | |
| - name: Auto-increment version | |
| id: bump | |
| run: | | |
| python - << 'PY' | |
| import os | |
| import toml | |
| from pathlib import Path | |
| path = Path("pyproject.toml") | |
| data = toml.loads(path.read_text(encoding="utf-8")) | |
| version = data["project"]["version"] | |
| major, minor, patch = version.split(".") | |
| patch = str(int(patch) + 1) | |
| new_version = ".".join([major, minor, patch]) | |
| data["project"]["version"] = new_version | |
| path.write_text(toml.dumps(data), encoding="utf-8") | |
| print(f"Bumped version: {version} -> {new_version}") | |
| # Export for later steps | |
| github_output = os.environ["GITHUB_OUTPUT"] | |
| with open(github_output, "a", encoding="utf-8") as f: | |
| f.write(f"new_version={new_version}\n") | |
| PY | |
| - name: Commit updated version on Publish | |
| run: | | |
| git config user.name "github-actions" | |
| git config user.email "[email protected]" | |
| git add pyproject.toml | |
| if git diff --cached --quiet; then | |
| echo "No version change to commit on Publish." | |
| else | |
| git commit -m "Auto-bump version to ${{ steps.bump.outputs.new_version }}" | |
| git push origin HEAD:Publish | |
| fi | |
| - name: Sync pyproject.toml to main | |
| # Only run if we actually bumped/committed something | |
| run: | | |
| VERSION="${{ steps.bump.outputs.new_version }}" | |
| echo "Syncing version $VERSION to main branch" | |
| # Make sure we have the latest branches | |
| git fetch origin | |
| # Switch to main and pull latest | |
| git checkout main | |
| git pull origin main | |
| # Bring over the bumped pyproject.toml from Publish | |
| git checkout Publish -- pyproject.toml | |
| # Stage and commit if there is a change | |
| if git diff --cached --quiet; then | |
| echo "No changes to commit on main." | |
| else | |
| git add pyproject.toml | |
| git commit -m "Sync version to ${VERSION} from Publish" | |
| git push origin main | |
| fi | |
| - name: Build distributions | |
| run: | | |
| python -m build | |
| - name: Publish to PyPI | |
| env: | |
| TWINE_USERNAME: "__token__" | |
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
| run: | | |
| twine upload dist/* | |
| - name: Create GitHub release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ steps.bump.outputs.new_version }} | |
| name: docker-enumsensitive v${{ steps.bump.outputs.new_version }} | |
| generate_release_notes: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |