Skip to content

Commit

Permalink
Fully automated release workflow (#7)
Browse files Browse the repository at this point in the history
* automation experiments

* more

* fix workflow

* fix workflow 2

* fix workflow 3

* fix workflow 4

* fix workflow 5

* fix workflow 6

* removed diag output and updted changelog
  • Loading branch information
rschmied committed Sep 25, 2024
1 parent f92146a commit b985cdf
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 83 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Print the ref
shell: bash
run: echo "${GITHUB_REF}"
with:
fetch-depth: 0 # Required due to the way Git works, without it this action won't be able to find any or the correct tags

- name: Install uv
uses: astral-sh/setup-uv@v2
Expand All @@ -39,6 +37,11 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Create the version file
run: |
./version.sh
cat src/eve2cml/_version.py
- name: Install the project
run: uv sync --all-extras --dev

Expand Down
157 changes: 82 additions & 75 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Required due to the way Git works, without it this action won't be able to find any or the correct tags

- name: Install uv
uses: astral-sh/setup-uv@v2
Expand All @@ -30,86 +32,91 @@ jobs:
python-version-file: ".python-version"

- name: Build a binary wheel and a source tarball
run: uv build
run: |
./version.sh
uv build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

- name: >-
Publish Python 🐍 distribution 📦 to PyPI
github-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and upload them to GitHub Release
needs:
- build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')

permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes-from-tag '${{ github.ref_name }}'
--draft
- name: Upload artifact signatures to GitHub Release
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
TWINE_REPOSITORY: pypi
#
run: uvx twine upload dist/*
# github-release:
# name: >-
# Sign the Python 🐍 distribution 📦 with Sigstore
# and upload them to GitHub Release
# needs:
# - publish-to-pypi
# runs-on: ubuntu-latest
#
# permissions:
# contents: write # IMPORTANT: mandatory for making GitHub Releases
# id-token: write # IMPORTANT: mandatory for sigstore
#
# steps:
# - name: Download all the dists
# uses: actions/download-artifact@v4
# with:
# name: python-package-distributions
# path: dist/
# - name: Sign the dists with Sigstore
# uses: sigstore/[email protected]
# with:
# inputs: >-
# ./dist/*.tar.gz
# ./dist/*.whl
# - name: Create GitHub Release
# env:
# GITHUB_TOKEN: ${{ github.token }}
# run: >-
# gh release create
# '${{ github.ref_name }}'
# --repo '${{ github.repository }}'
# --notes ""
# - name: Upload artifact signatures to GitHub Release
# env:
# GITHUB_TOKEN: ${{ github.token }}
# # Upload to GitHub Release using the `gh` CLI.
# # `dist/` contains the built packages, and the
# # sigstore-produced signatures and certificates.
# run: >-
# gh release upload
# '${{ github.ref_name }}' dist/**
# --repo '${{ github.repository }}'

# publish-to-testpypi:
# name: Publish Python 🐍 distribution 📦 to TestPyPI
# needs:
# - build
# runs-on: ubuntu-latest
#
# environment:
# name: testpypi
# url: https://test.pypi.org/p/<package-name>
#
# permissions:
# id-token: write # IMPORTANT: mandatory for trusted publishing
#
# steps:
# - name: Download all the dists
# uses: actions/download-artifact@v4
# with:
# name: python-package-distributions
# path: dist/
# - name: Publish distribution 📦 to TestPyPI
# uses: pypa/gh-action-pypi-publish@release/v1
# with:
# repository-url: https://test.pypi.org/legacy/
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
publish-to-pypi:
name: Publish Python 🐍 distribution 📦 to PyPI
needs:
- build
runs-on: ubuntu-latest

environment:
name: pypi
url: https://test.pypi.org/p/eve2cml

# https://docs.pypi.org/trusted-publishers/adding-a-publisher/
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/

- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://pypi.org/legacy/

# - name: Publish Python 🐍 distribution 📦 to PyPI
# env:
# TWINE_USERNAME: __token__
# TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
# TWINE_REPOSITORY: pypi
# #
# run: uvx twine upload dist/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ cython_debug/
UNLs/
ZIPs/
assets/header.xcf
src/eve2cml/_version.py

.DS_Store
*.yaml
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# CHANGELOG

- v0.1.0b6
- v0.1.1
- updated release workflows, no functional difference to 0.1.0
- v0.1.0
- replace pdm with uv
- updated all github actions to newer versions
- automate the PyPI release process
- allow more annotations to be rotated (with 2.8)
- updated documentation
- a small/cosmetic fix around the centered line output
- v0.1.0b5
- updated dependencies
- added installation instructions to README
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.PHONY: build check clean cov covo format mrproper sync test

build:
$(shell ./version.sh)
uv build

clean:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ lint.ignore = [
]
include = ["**/*.py", "**/*.pyi", "**/pyproject.toml"]


[tool.pytest.ini_options]
minversion = "6.0"
addopts = "-ra -q"
Expand All @@ -79,6 +78,7 @@ testpaths = ["tests", "integration"]
source = ["src"]

[tool.uv]
cache-keys = [{ git = true }]
dev-dependencies = [
"mypy>=1.11.2",
"pytest>=8.3.3",
Expand Down
1 change: 0 additions & 1 deletion src/eve2cml/_version.py

This file was deleted.

2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# Original Git-derived version identifier
version=$(git describe --always --tags --dirty --long)

# Check if the version contains Git metadata (commits and commit hash)
if [[ "$version" =~ ([0-9]+\.[0-9]+\.[0-9]+)(-([0-9]+)-g([0-9a-f]+)(-dirty)?)? ]]; then
core_version="${BASH_REMATCH[1]}" # 0.1.0
commit_count="${BASH_REMATCH[3]}" # 1 (optional)
commit_hash="${BASH_REMATCH[4]}" # 281941e (optional)
dirty="${BASH_REMATCH[5]}" # -dirty (optional)

# If there's no Git metadata, the version is already PEP 440 compliant
if [[ -z "$commit_count" ]]; then
pep440_version="$core_version"
else
# Construct the PEP 440 compliant version
pep440_version="${core_version}+${commit_count}.g${commit_hash}"

# Append .dirty if the version has '-dirty'
if [[ -n "$dirty" ]]; then
pep440_version="${pep440_version}.dirty"
fi
fi
else
pep440_version="0.0.0+unknown"
fi
echo "__version__ = \"$pep440_version\"" >src/eve2cml/_version.py

0 comments on commit b985cdf

Please sign in to comment.