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
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Normalize line endings in the repository so the files are identical on every
# platform. This matters for CHANGELOG.rst: python-semantic-release looks for its
# insertion flag in that file, and it builds the flag with the line separator of the
# current platform. With CRLF in the working tree, the flag is not found on Linux.
* text=auto eol=lf
8 changes: 8 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Lines starting with '#' are comments.
# Each line is a file pattern followed by one or more owners.

# Default owners for everything in the repository.
# Only @Telefonica/toolium is listed on purpose: the code owner rule is used to
# guarantee that at least one approval comes from a member of that team. If a
# second team were added here, an approval from either team would satisfy it.
* @Telefonica/toolium
30 changes: 30 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!--
The pull request title decides the release: it is the only thing semantic-release reads.
Use a conventional commit prefix.

feat: ... -> minor release (3.9.0 -> 3.10.0)
fix: ... -> patch release (3.9.0 -> 3.9.1)
feat!: ... -> major release (3.9.0 -> 4.0.0)
chore: ... -> no release; listed in the changelog when something else releases

Any other prefix (docs:, ci:, test:, perf:, refactor:, style:, build:) is ignored: no
version bump, no changelog entry. A performance improvement is written as fix:.

Add [skip release] to the title to merge now and release later, together with another PR.

See RELEASING.md for the details.
-->

## What does this change?

<!-- A short description of the change, and why it is needed. -->

## How was it tested?

<!-- Unit tests added, or the manual steps followed. -->

## Checklist

- [ ] The **title of this pull request** follows the convention above
- [ ] `ruff check .` and `ruff format --check .` pass
- [ ] `python -m pytest` passes
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: build

on:
pull_request:
push:
branches:
- master

jobs:
python-versions:
Expand Down
108 changes: 108 additions & 0 deletions .github/workflows/release-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: release-test

# Rehearses the release flow without touching PyPI, master or the real versioning.
#
# It can be started in two ways:
# - Manually, from the Actions tab (workflow_dispatch). GitHub only shows the button
# when this file exists on the default branch, so this path works after the first
# merge to master.
# - Pushing to a branch named test/*, which works before that first merge.
#
# The version is a prerelease (X.Y.Z-dev.N), so TestPyPI and PyPI never see a version
# that could be confused with a real release. The release commit and tag are created
# locally inside the run, but never pushed, so nothing lands in the repository: each run
# leaves the remote branches and tags untouched.

on:
workflow_dispatch:
push:
branches:
- 'test/**'

permissions:
contents: read

# Sequential runs, so two rehearsals never race on the shared version calculation.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:
rehearsal:
name: Build prerelease and publish on TestPyPI
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/p/toolium
permissions:
id-token: write # required for TestPyPI trusted publishing (OIDC)
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0 # semantic-release needs the full history and tags
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up python
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Calculate the next prerelease version
id: version
uses: python-semantic-release/python-semantic-release@v10
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
# The action requires the `commit_sha` output whenever a release happens, and
# python-semantic-release only sets it inside its tagging step. So a tag must be
# created locally for the action to succeed. Nothing reaches the remote: push and
# vcs_release stay off, so the commit and the tag exist only inside this run and the
# branch is left untouched.
commit: 'true'
tag: 'true'
push: 'false'
vcs_release: 'false'
# The changelog is generated, so its entry for this version can be reviewed in the
# run summary below.
changelog: 'true'
# This action runs in its own Docker container, which does not include the `build`
# package, so its build_command would fail with "No module named build". The build
# is done in a later step on the runner instead, where it is installed.
build: 'false'
- name: Show the version that would be released
run: |
echo "::notice::Rehearsal version: ${{ steps.version.outputs.version }} (tag ${{ steps.version.outputs.tag }})"
- name: Build sdist and wheel
run: python -m build
- name: Show the changelog entry that would be generated
run: |
python - <<'PY' >> "$GITHUB_STEP_SUMMARY"
import re
import pathlib

version = '${{ steps.version.outputs.version }}'
text = pathlib.Path('CHANGELOG.rst').read_text(encoding='utf-8')
match = re.search(rf'(v{re.escape(version)} \(.*?)\n(?=\S*\.\. _changelog-|\Z)', text, re.S)
body = match.group(1).rstrip() if match else "No entry was generated for this version."
print(f"## Changelog entry for `{version}`\n")
print("```rst")
print(body)
print("```")
PY
- name: Check distribution metadata
run: twine check dist/*
- name: Upload distribution
uses: actions/upload-artifact@v7
with:
name: dist-testpypi
path: dist/
- name: Publish on TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
# A rehearsal may be run several times, and TestPyPI rejects uploads of a file
# that already exists. With this, a repeated run reports success instead of
# failing on the duplicate.
skip-existing: true
126 changes: 126 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: release

on:
push:
branches:
- master

permissions:
contents: read

# Only one release at a time, and never cancel one in progress: cancelling while
# semantic-release is pushing its version commit would leave the repository inconsistent.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:
release:
name: Version and tag
# A commit message containing [skip release] postpones the release: the workflow is
# skipped, and the commits it carries (including feat: and fix: ones) stay pending, so
# the next release includes them. It only affects this workflow, not CI.
if: ${{ !contains(github.event.head_commit.message, '[skip release]') }}
runs-on: ubuntu-latest
permissions:
contents: write # required to push the version commit and the tag
outputs:
released: ${{ steps.release.outputs.released }}
tag: ${{ steps.release.outputs.tag }}
version: ${{ steps.release.outputs.version }}
steps:
- name: Generate GitHub App token
id: ci-token
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3
with:
client-id: ${{ vars.GH_CI_APP_CLIENT_ID }}
private-key: ${{ secrets.GH_CI_APP_PRIVATE_KEY }}
permission-contents: write
- name: Checkout master
uses: actions/checkout@v6
with:
ref: ${{ github.ref_name }} # always the tip of master, not the triggering SHA
fetch-depth: 0 # semantic-release needs the full history and tags
token: ${{ steps.ci-token.outputs.token }}
- name: Force the branch to the current commit
run: git reset --hard "$GITHUB_SHA"
- name: Set up python
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Calculate version, update changelog, commit and tag
id: release
uses: python-semantic-release/python-semantic-release@v10
with:
github_token: ${{ steps.ci-token.outputs.token }}
# This action runs in its own Docker container, which does not include the `build`
# package, so its build_command would fail with "No module named build". The build
# is done in a later step on the runner instead, where it is installed.
build: 'false'
- name: Build sdist and wheel
if: steps.release.outputs.released == 'true'
run: python -m build
- name: Check distribution metadata
if: steps.release.outputs.released == 'true'
run: twine check dist/*
- name: Upload distribution
if: steps.release.outputs.released == 'true'
uses: actions/upload-artifact@v7
with:
name: dist
path: dist/

publish:
name: Publish on PyPI
needs: release
if: needs.release.outputs.released == 'true'
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/toolium
permissions:
id-token: write # required for PyPI trusted publishing (OIDC)
steps:
- name: Download distribution
uses: actions/download-artifact@v5
with:
name: dist
path: dist/
- name: Publish distribution on PyPI
uses: pypa/gh-action-pypi-publish@release/v1

github-release:
name: Publish GitHub release
needs: release
if: needs.release.outputs.released == 'true'
runs-on: ubuntu-latest
permissions:
contents: read # the release is created with the app token, not with this one
steps:
- name: Generate GitHub App token
id: ci-token
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3
with:
client-id: ${{ vars.GH_CI_APP_CLIENT_ID }}
private-key: ${{ secrets.GH_CI_APP_PRIVATE_KEY }}
permission-contents: write
- name: Checkout master
uses: actions/checkout@v6
with:
# publish-action runs `semantic-release publish`, which reads its configuration
# from pyproject.toml, so the repository has to be present in the workspace.
ref: ${{ github.ref_name }}
- name: Download distribution
uses: actions/download-artifact@v5
with:
name: dist
path: dist/
- name: Upload the distribution to the GitHub release
uses: python-semantic-release/publish-action@v10
with:
github_token: ${{ steps.ci-token.outputs.token }}
tag: ${{ needs.release.outputs.tag }}
Loading
Loading