Skip to content

Commit

Permalink
Automatically create GitHub Release (#138)
Browse files Browse the repository at this point in the history
* Create a GitHub Release on pushed version tag

* Add build to dev dependencies

* Clean up python-versions code in QA workflow

* Release workflow publishes to pypi (probably)

* Upload man page to release

* Fix bug in release workflow

* Run actionlint on workflows

* Only run actionlint once lol

* Fix syntax error in release script

* Check out before linting workflows

* Use yq to pull release version

* Formatting SNAFU in release.yaml

* Update dev docs

* Full path to man file in release workflow

* Dev deps should install build

* github release shouldn't need a checkout

* Consistent output names
  • Loading branch information
jfhbrook authored Nov 23, 2023
1 parent d36f0de commit 527a295
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 24 deletions.
26 changes: 17 additions & 9 deletions .github/workflows/qa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ on:
pull_request:
branches: [ "main" ]
jobs:
make-versions:
python-versions:
runs-on: ubuntu-latest
outputs:
versions: ${{ steps.make-versions.outputs.versions }}
versions: ${{ steps.python-versions.outputs.versions }}
steps:
- uses: actions/checkout@v4
- name: Make versions
id: make-versions
- name: Get Python versions
id: python-versions
run: |
classifiers="$(yq -p toml -o toml '.project.classifiers[]' pyproject.toml | grep "Programming Language :: Python :: " | grep "\.")"
versions="$(echo "$classifiers" | sed -e 's/Programming Language :: Python :: \([0-9.]*\)$/"\1"/g' | tr '\n' ',' | sed -e 's/,$//g')"
echo "versions=[$versions]" > "$GITHUB_OUTPUT"
CLASSIFIERS="$(yq -p toml -o toml '.project.classifiers[]' pyproject.toml | grep "Programming Language :: Python :: " | grep "\.")"
VERSIONS="$(echo "${CLASSIFIERS}" | sed -e 's/Programming Language :: Python :: \([0-9.]*\)$/"\1"/g' | tr '\n' ',' | sed -e 's/,$//g')"
echo "versions=[${VERSIONS}]" > "${GITHUB_OUTPUT}"
qa:
name: Run QA checks
runs-on: ubuntu-latest
needs: make-versions
needs: python-versions
strategy:
matrix:
python-version: ${{fromJson(needs.make-versions.outputs.versions)}}
python-version: ${{fromJson(needs.python-versions.outputs.versions)}}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -48,3 +48,11 @@ jobs:
npx pyright@latest
- name: Run tests
run: pytest ./tests

actionlint:
name: Run actionlint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run actionlint
uses: raven-actions/actionlint@v1
99 changes: 99 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Release
on:
push:
tags:
- 'v*'
jobs:
versions:
runs-on: ubuntu-latest
outputs:
python-version: ${{ steps.python-version.outputs.python_version }}
release-version: ${{ steps.release-version.outputs.release_version }}
steps:
- uses: actions/checkout@v4
- name: Get latest supported Python version
id: python-version
run: |
CLASSIFIERS="$(yq -p toml -o toml '.project.classifiers[]' pyproject.toml | grep "Programming Language :: Python :: " | grep "\.")"
VERSION="$(echo "${CLASSIFIERS}" | sed -e 's/Programming Language :: Python :: \([0-9.]*\)$/"\1"/g' | tail -n 1)"
echo "python_version=[${VERSION}]" > "${GITHUB_OUTPUT}"
# See: https://stackoverflow.com/questions/58177786/get-the-current-pushed-tag-in-github-actions
- name: Get release version
id: release-version
run: |
VERSION="$(yq -p toml -o toml -r '.project.version' pyproject.toml)"
echo "release_version=${VERSION}" >> "${GITHUB_OUTPUT}"
build:
runs-on: ubuntu-latest
needs:
- versions
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ needs.versions.outputs.python-version }}
uses: actions/setup-python@v4
with:
python-version: "${{ needs.versions.outputs.python-version }}"
- name: Install the world
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -e .[dev]
- name: Build Package Distributions
run: python -m build
- name: Store Package Distributions
uses: actions/upload-artifact@v3
with:
name: package-distributions
path: dist/
- name: Build Man Page
run: sphinx-build -M man docs _build
- name: Store Man Page
uses: actions/upload-artifact@v3
with:
name: man-page
path: _build/man

pypi-release:
runs-on: ubuntu-latest
needs:
- build
environment:
name: pypi
url: https://pypi.org/p/pypi
permissions:
id-token: write
steps:
- name: Download distributions
uses: actions/download-artifact@v3
with:
name: package-distributions
path: dist/
- name: Publish release to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

github-release:
runs-on: ubuntu-latest
needs:
- versions
- build
steps:
- name: Download distributions
uses: actions/download-artifact@v3
with:
name: package-distributions
path: dist/
- name: Download man page
uses: actions/download-artifact@v3
with:
name: man-page
path: man
- name: Create a GitHub release
uses: marvinpinto/action-automatic-releases@latest
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
draft: false
prerelease: false
title: Release v${{ needs.versions.outputs.release-version }}
files: |
dist/*
man/pyee.1
37 changes: 23 additions & 14 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,31 +175,40 @@ I try to use git tags to tag versions - there's a just task:
just tag
```

### Build and Publish

To publish the package, run:
### Push the Tag to GitHub

```bash
just publish
git push origin main --tags
```

This should automatically build the package and upload with twine. However,
you can also build the package manually with `just build`, or upload the
existing build with `just upload`.

## Push the Tag to GitHub
### Check on GitHub Actions

```bash
git push origin main --tags
```
This should trigger a GitHub Action which publishes to PyPI and creates a
GitHub Release. Go to GitHub and make sure it worked.

## Check on RTD
### Check on RTD

RTD should build automatically but I find there's a delay so I like to kick it
off manually. Log into [RTD](https://readthedocs.org), log in, then go
to [the pyee project page](https://readthedocs.org/projects/pyee/) and build
latest and stable.

## (Optional) Announce on Twitter

### (Optional) Announce on Twitter

It's not official, but I like to announce the release on Twitter.


### (Optional) Build and Publish Manually

If you want to publish the package manually, run:

```bash
just publish
```

This should automatically build the package and upload with twine. However,
you can also build the package manually with `just build`, or upload the
existing build with `just upload`.


2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ _clean-build:

# Tag the release in git
tag:
. ./venv/bin/activate && git tag -a "$(python3 -c 'import toml; print(toml.load(open("pyproject.toml", "r"))["project"]["version"])')" -m "Release $(python3 -c 'import toml; print(toml.load(open("pyproject.toml", "r"))["project"]["version"])')"
. ./venv/bin/activate && git tag -a "v$(python3 -c 'import toml; print(toml.load(open("pyproject.toml", "r"))["project"]["version"])')" -m "Release $(python3 -c 'import toml; print(toml.load(open("pyproject.toml", "r"))["project"]["version"])')"

# Upload built packages
upload:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies = [

[project.optional-dependencies]
dev = [
"build",
"flake8",
"flake8-black",
"pytest",
Expand Down

0 comments on commit 527a295

Please sign in to comment.