From 26e45ca189b7efccd003013c71693be086ba4f7e Mon Sep 17 00:00:00 2001 From: Arthur Henrique Date: Fri, 5 Nov 2021 00:27:46 -0300 Subject: [PATCH] ci: Include release on tag workflow --- .github/workflows/release.yml | 46 +++++++++++++++++++++++++++++++++++ CHANGELOG.md | 3 +++ Makefile | 7 +++++- README.md | 27 ++++++++++++++++++++ 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..41983c5 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,46 @@ +name: Release +# This workflow releases a project version on GitHub and publishes the distribution files on PyPI +# everytime a tag following semantic version syntax is pushed. + +on: + push: + tags: + - '*.*.*' + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - name: Set up python version + uses: actions/setup-python@v2 + with: + python-version: '3.10' + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up project environment + run: make init + + - name: Build distributable artifacts + run: make build + + - name: Release project on Github + # Register a release on repository, versioning it according to tag and including artifacts + # See https://github.com/marketplace/actions/gh-release + uses: softprops/action-gh-release@v1 + with: + files: dist/* + fail_on_unmatched_files: true + + - name: Publish package to PyPI + # Register package distributable files on PyPI or specified index + # See https://github.com/marketplace/actions/pypi-publish + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} + repository_url: https://test.pypi.org/legacy/ + skip_existing: true + verbose: true diff --git a/CHANGELOG.md b/CHANGELOG.md index 101e8f4..9cb1d7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,3 +12,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Structure package development start point - Adopt a single-source package versioning strategy - Define package main entry-point + +### CI +- Include release on tag workflow diff --git a/Makefile b/Makefile index e4fc916..a388452 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,7 @@ SETUP_CFG = setup.cfg REQUIREMENTS_TXT ?= requirements-dev.txt # Executables definition +GIT ?= git PYTHON ?= $(VENV_DIR)/bin/python3 PIP = $(PYTHON) -m pip REMOVE = rm -fr @@ -55,6 +56,10 @@ install:: uninstall ## Install on-developing package in current environment run:: ## Execute package main entry-point $(PYTHON) -m $(PACKAGE_MODULE) +release:: ## Tag commit with current version and push it, triggering release automation + $(GIT) tag $(PACKAGE_VERSION) + $(GIT) push origin $(PACKAGE_VERSION) + TWINE_REPOSITORY=testpypi publish:: build ## Upload distribution archives to python package index $(PYTHON) -m twine upload \ @@ -77,4 +82,4 @@ veryclean:: uninstall clean ## Delete all generated files .EXPORT_ALL_VARIABLES: .ONESHELL: -.PHONY: help env init build install run publish uninstall clean veryclean +.PHONY: help env init build install run release publish uninstall clean veryclean diff --git a/README.md b/README.md index e5b0013..1c8bb11 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Python Package +[![][B5]][>8] > This intends to be an [readme-documented][-0], [open-source-licensed][-1], [semantic-versioned][-2], [conventional-committed][-3] and [changelogged][-4] git repository starting point for the development of a brand-new python package @@ -17,6 +18,9 @@ A straightforward beginning for an open-source python package project repository [>4]: https://packaging.python.org/guides/distributing-packages-using-setuptools/ "PyPA packing instructions" [>5]: https://setuptools.pypa.io/en/latest/userguide/index.html "Setuptools packing instructions" [>6]: https://packaging.python.org/en/latest/guides/single-sourcing-package-version/ "Single-sourcing package version" +[>7]: https://github.com/marketplace/actions/pypi-publish "PyPA publish-on-push github action" +[>8]: https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets "GitHub Docs: Secrets" +[>9]: https://test.pypi.org/project/python-package/ "PyPI package page" [!1]: https://github.com/generic-tree/python-package/generate "Github repository's template generation URL" [!2]: https://pypi.org/manage/account/token/ "PyPI API token creation URL" @@ -24,6 +28,14 @@ A straightforward beginning for an open-source python package project repository [B1]: https://img.shields.io/github/license/Generic-Tree/python-package?color=green "License badge" [B2]: https://www.repostatus.org/badges/latest/concept.svg "Repostatus active badge" [B3]: https://img.shields.io/static/v1?label=create%20a%20new%20repository&message=%20&style=social "Create new repository" +[B4]: https://img.shields.io/static/v1?label=create%20an%20API%20token&message=%20&style=social "Create PyPI API token" +[B5]: https://img.shields.io/pypi/v/python-package "PyPI version badge" + + +Beside consider [PyPA][>4] and [setuptools][>5] packing instructions, +and bring useful Makefile targets to help development process, +it also provides a release-and-publish-on-tag automation through +PyPA's official [pypi-publish][>7] GitHub action. ### Table of Contents @@ -32,6 +44,7 @@ A straightforward beginning for an open-source python package project repository * [Getting started](#getting-started) * [Development environment](#development-environment) + * [Continuous delivery](#continuous-delivery) * [Repo publication](#repo-publication) * [Project specifications](#project-specifications) * [Features](#features) @@ -68,6 +81,14 @@ $ . venv/bin/activate You're then ready to [start developing your distributable python modules][>4]. +### Continuous delivery +#### Release and publish on tag +To set up this automation, you need to have a *Python Package Index* account. \ +There, [![][B4]][!2] and register it into your fresh-repo [secrets][>8] as `PYPI_API_TOKEN`. + +After that, every tagged commit pushed will result in a new version of your package +released at GitHub and published to PyPI. + ### Repo publication After all, you should make this project your own. * Write a good `README.md` to present it to the world. @@ -97,11 +118,17 @@ It also powers up python packing workflow by: * Inclusion of proficient `Makefile` that improves development management * Inclusion of appropriate `.gitignore` file * Commented references and instructions through configuration files +* Inclusion of convenient [Github Actions workflows][>7] that: + * Setup project releases + * Publish package in PyPI ### Folder structure ``` . ├── .git/ Version control system folder +├── .github/ Repository customization directory +│ └── workflows Continuous automation setup folder +│ └── release.yml Release on tag procedure ├── .gitignore VCS ignored files manifest ├── CHANGELOG.md Release notes description ├── LICENSE License file