Skip to content

Commit

Permalink
chore(release): Add PyPI action & extract copr step
Browse files Browse the repository at this point in the history
Due to latest changes to python semantic release
PyPI release is no longer supported and the separate
action (https://github.com/pypa/gh-action-pypi-publish)
is recomended to use while releasing to PyPI.
For the trusted publishing we had to set up the PyPI
account owning mrack to trust neoave/mrack repository
which I did and set up the actions jobs to build
the python package and trigger a truster build.
As an addition i have extracted copr to separate job.

Some resources:
https://docs.pypi.org/trusted-publishers/
https://python-semantic-release.readthedocs.io/en/latest/index.html
https://github.com/pypa/gh-action-pypi-publish
https://python-semantic-release.readthedocs.io/en/latest/migrating_from_v7.html

we had to move from v7 to 8 to use PyPI and have
build steps separate as v7 does that inplace.

Signed-off-by: Tibor Dudlák <[email protected]>
  • Loading branch information
Tiboris committed Sep 19, 2023
1 parent 9bbd987 commit cdc62dc
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 11 deletions.
68 changes: 63 additions & 5 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
run: tox -e py

release:
name: mrack semantic release
name: mrack semantic release 🐕
runs-on: ubuntu-latest
needs: [pre-commit, test]
if: github.repository == 'neoave/mrack'
Expand All @@ -58,8 +58,8 @@ jobs:
fetch-depth: 0
- name: Get the new version using python-semantic-release
run: |
pip3 install python-semantic-release==7.34.4
echo "NEW_VERSION="`semantic-release print-version --noop` >> ${GITHUB_ENV}
pip3 install python-semantic-release==8.0.8
echo "NEW_VERSION="`semantic-release version --print` >> ${GITHUB_ENV}
- name: Update the mrack.spec changelog with initiator and basic message
run: |
# get the history of commits and generate changelog from it
Expand All @@ -75,12 +75,70 @@ jobs:
sed -ri \
"s/\%changelog/\%changelog\\n\*\ $TODAY\ $RELEASE_ACTOR\ -\ $NEW_VERSION-1/" \
mrack.spec
- name: Add version to specfile
run: |
export SPEC_VERSION_REGEX="s/^Version:(\s+)(.*)/Version:\1$NEW_VERSION/"
echo $SPEC_VERSION_REGEX
sed -i -E $SPEC_VERSION_REGEX mrack.spec
- name: Add specfile to commit
run: git add mrack.spec
- name: Python Semantic Release
uses: relekang/python-semantic-release@v7.34.4
uses: relekang/python-semantic-release@v8.0.8
with:
github_token: ${{ secrets.TIBORIS_GH_TOKEN }}
pypi_token: ${{ secrets.PYPI_TOKEN }}

copr-build:
name: Copr 📦 build for mrack
runs-on: ubuntu-latest
needs: [release]
steps:
- name: Trigger COPR build
run: curl -X POST ${{ secrets.COPR_WEBHOOK_URL }}

python-build:
name: Build 🐍 distribution 📦
runs-on: ubuntu-latest
needs: [release]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: >-
Publish 🐍 distribution 📦 to PyPI
# only publish to PyPI on tag pushes
if: startsWith(github.ref, 'refs/tags/')
needs: [python-build]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/mrack/
# IMPORTANT: mandatory for trusted publishing which is setup on pypi
permissions:
id-token: write
steps:
- name: Download all the dists from artifacts
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: list dist dir
run: ls -la dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
8 changes: 2 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@ pythonpath = [

[tool.semantic_release]
version_source = "commit"
commit_subject = "chore: Release version {version}"
commit_message = "Releasing mrack version {version}"
version_variable = [
commit_message = "chore: Release version {version}\n\nReleasing new mrack version"
version_variables = [
"src/mrack/version.py:VERSION",
"docs/conf.py:release",
]
version_pattern = [
"mrack.spec:Version:\\s+{version}",
]
branch = "main"
commit = true
tag = true

0 comments on commit cdc62dc

Please sign in to comment.