Skip to content

Commit

Permalink
Add a GitHub workflow to release version tags to PyPI
Browse files Browse the repository at this point in the history
  • Loading branch information
adamalton committed Nov 30, 2023
1 parent 9b662a2 commit 32cf4cf
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 11 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Publish package to PyPI

# Publishes to PyPI whenever a tag in the format "vX.X.X" is pushed.

on:
push:
tags:
- 'v*.*.*'

jobs:
build-and-publish:
name: Build package and publish to PyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.11"
- name: Install pypa/setuptools
run: >-
python -m
pip install wheel
- name: Get version from tag name
id: tag
run: echo ::set-output name=TAG_NAME::$(echo $GITHUB_REF | cut -d / -f 3)
- name: Update version in setup.py
run: >-
sed -i "s/{{VERSION_PLACEHOLDER}}/${{ steps.tag.outputs.TAG_NAME }}/g" setup.py
- name: Build a binary wheel
run: >-
python setup.py sdist bdist_wheel
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
20 changes: 15 additions & 5 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
Releasing
============

This file is here for the benefit of the package author, who can never remember what all the steps are to release this to PyPi and GitHub.
This file is here for the benefit of the package author, who can never remember what all the steps are to release this to PyPI and GitHub.

1. Bump the `VERSION` in `setup.py`.
2. Run `python setup.py sdist bdist_wheel`.

Using GitHub Workflow
---------------------

1. Push a tag in the format `vX.Y.Z`
2. Done.


Manually
--------

1. Replace the `{{VERSION_PLACEHOLDER}}` placeholder in `setup.py` with a manually incremented version number.
2. Run `python setup.py sdist`.
3. Run `pip install twine` if it's not already installed.
4. Run `twine check dist/django-csp-reports-VERSION*`
5. Run `twine upload --repository-url https://test.pypi.org/legacy/ dist/django-csp-reports-VERSION*`
6. Check that that worked.
7. Run `twine upload dist/django-csp-reports-VERSION*`
8. Check that that worked.
9. Push the VERSION bump to GitHub.
10. Tag the release: `git tag VERSION && git push origin VERSION`
9. Tag the release: `git tag VERSION && git push origin VERSION`
10. Release it on GitHub, uploading the `.tar.gz` file from the `dist/` directory: https://github.com/adamalton/django-csp-reports/releases/new


Expand Down
13 changes: 7 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
from setuptools import find_packages, setup

VERSION = "1.9.0"
import os

PACKAGES = find_packages()
REQUIREMENTS = ['django >=2.2,<5.0']
Expand All @@ -21,23 +20,25 @@
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10']
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11']


DESCRIPTION = (
"A Django app for handling reports from web browsers of violations of your website's "
"HTTP Content Security Policy."
)
LONG_DESCRIPTION = open(os.path.join(os.path.dirname(__file__), "README.md")).read()

setup(
name='django-csp-reports',
version='%s' % VERSION,
version="{{VERSION_PLACEHOLDER}}",
description=DESCRIPTION,
long_description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
long_description_content_type="text/markdown",
author='Adam Alton',
author_email='[email protected]',
url='https://github.com/adamalton/django-csp-reports',
download_url='https://github.com/adamalton/django-csp-reports/tarball/%s' % VERSION,
packages=PACKAGES,
include_package_data=True,
python_requires='>=3.4',
Expand Down

0 comments on commit 32cf4cf

Please sign in to comment.