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
51 changes: 51 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Release

on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+"

permissions:
contents: write
id-token: write

jobs:
release:
name: Release
runs-on: ubuntu-latest
environment: release
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Check tag matches VERSION
run: |
version="$(cat VERSION)"
if [ "$GITHUB_REF_NAME" != "$version" ]; then
echo "::error::Tag $GITHUB_REF_NAME does not match VERSION $version. Run 'make release VERSION=x.y.z'."
exit 1
fi

- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: "3.13"

- name: Run tests
run: |
pip install -r requirements.txt
pytest

- name: Build
run: |
pip install build
python -m build

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
Comment thread
jclusso marked this conversation as resolved.
Resolved
with:
skip-existing: true

- name: Create GitHub release
run: gh release create "$GITHUB_REF_NAME" --verify-tag --generate-notes
env:
GH_TOKEN: ${{ github.token }}
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.PHONY: release

release:
ifndef VERSION
$(error VERSION is required, e.g. make release VERSION=1.2.3)
endif
@echo "$(VERSION)" | grep -Eq '^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$$' || { echo "error: VERSION must be x.y.z"; exit 1; }
@test -z "$$(git status --porcelain)" || { echo "error: working tree not clean"; exit 1; }
@test "$$(git branch --show-current)" = master || { echo "error: release from master"; exit 1; }
@git fetch -q --tags origin master
@! git rev-parse -q --verify "refs/tags/$(VERSION)" >/dev/null || { echo "error: tag $(VERSION) already exists"; exit 1; }
@cur="$$(cat VERSION)"; [ "$$cur" != "$(VERSION)" ] && [ "$$(printf '%s\n' "$$cur" "$(VERSION)" | sort -V | tail -1)" = "$(VERSION)" ] || { echo "error: VERSION must be greater than $$cur"; exit 1; }
@test "$$(git rev-parse HEAD)" = "$$(git rev-parse origin/master)" || { echo "error: master is not in sync with origin"; exit 1; }
pytest
Comment thread
jclusso marked this conversation as resolved.
Resolved
@echo "$(VERSION)" > VERSION
@git commit -q -am "Release $(VERSION)"
@git tag -a $(VERSION) -m $(VERSION)
@echo "Tagged $(VERSION). Push the commit and tag to release: git push --follow-tags"
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ Tests can be run with the following command:
pytest
```

## Cutting a Release

Run `make release VERSION=x.y.z` on an up to date `master` with a clean tree,
then `git push --follow-tags`. It runs the tests, bumps `VERSION`, commits,
and tags `x.y.z`. Pushing the tag triggers the release workflow, which
publishes to PyPI and creates the GitHub release.

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/emailable/emailable-python.
Loading