Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 27 additions & 68 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,86 +1,50 @@
name: Bump Version & Publish to PyPI
name: Publish to PyPI

on:
pull_request:
types: [closed]
branches: [master]
push:
branches:
- master

permissions:
contents: write
contents: read

jobs:
publish:
if: github.event.pull_request.merged == true
check:
runs-on: ubuntu-latest

outputs:
on_master: ${{ steps.verify.outputs.on_master }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"

- name: Install dependencies
run: pip install build twine tomli tomli-w

- name: Determine version bump type
id: bump
- name: Check if commit has a version tag
id: verify
run: |
PR_TITLE="${{ github.event.pull_request.title }}"
PR_LABELS=$(echo '${{ toJson(github.event.pull_request.labels.*.name) }}')

if echo "$PR_LABELS" | grep -q '"major"'; then
echo "part=major" >> "$GITHUB_OUTPUT"
elif echo "$PR_LABELS" | grep -q '"minor"'; then
echo "part=minor" >> "$GITHUB_OUTPUT"
TAG=$(git tag --points-at HEAD | grep -E '^v[0-9]' | head -n1)
if [ -n "$TAG" ]; then
echo "on_master=true" >> $GITHUB_OUTPUT
else
echo "part=patch" >> "$GITHUB_OUTPUT"
echo "on_master=false" >> $GITHUB_OUTPUT
fi

- name: Bump version
id: version
run: |
python - <<'PYEOF'
import tomli, tomli_w, pathlib, os

pyproject = pathlib.Path("pyproject.toml")
data = tomli.loads(pyproject.read_text())

current = data["project"]["version"]
major, minor, patch = (int(x) for x in current.split("."))

part = os.environ["BUMP_PART"]
if part == "major":
major, minor, patch = major + 1, 0, 0
elif part == "minor":
minor, patch = minor + 1, 0
else:
patch += 1

new_version = f"{major}.{minor}.{patch}"
data["project"]["version"] = new_version
pyproject.write_text(tomli_w.dumps(data))
publish:
needs: check
if: needs.check.outputs.on_master == 'true'
runs-on: ubuntu-latest

with open(os.environ["GITHUB_OUTPUT"], "a") as f:
f.write(f"new_version={new_version}\n")
steps:
- name: Checkout repository
uses: actions/checkout@v4

print(f"Bumped {current} -> {new_version}")
PYEOF
env:
BUMP_PART: ${{ steps.bump.outputs.part }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"

- name: Commit version bump
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add pyproject.toml
git commit -m "bump version to ${{ steps.version.outputs.new_version }}"
git push
- name: Install dependencies
run: pip install build twine

- name: Build package
run: python -m build
Expand All @@ -90,8 +54,3 @@ jobs:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: twine upload dist/*

- name: Create git tag
run: |
git tag "v${{ steps.version.outputs.new_version }}"
git push origin "v${{ steps.version.outputs.new_version }}"
1 change: 0 additions & 1 deletion packerpy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ class Plugin(PackerResource):

def __init__(self, name: str, version: str, version_op: str, source: str) -> None:
super().__init__(name=name)
self.name: str = name
self.version: str = version
self.version_op: str = version_op
self.source: str = source
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ classifiers = [
]
dependencies = [
"python-hcl2~=3.0",
"typing_extensions>=4.0; python_version < '3.12'",
"typing_extensions>=4.0", # not required
]

[project.urls]
Expand Down
Loading