Skip to content

Commit

Permalink
ci: Include release on tag workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
artu-hnrq committed Aug 19, 2022
1 parent 13efb41 commit 26e45ca
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
46 changes: 46 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand All @@ -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
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,13 +18,24 @@ 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"

[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
Expand All @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 26e45ca

Please sign in to comment.