Skip to content

Commit

Permalink
Merge pull request #45 from JenspederM/ci/add-commitizen
Browse files Browse the repository at this point in the history
ci: automate versioning with commitizen
  • Loading branch information
JenspederM authored Sep 2, 2024
2 parents e335980 + 9c8fce4 commit 563bf7a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 30 deletions.
58 changes: 32 additions & 26 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
jobs:
test:
name: Run tests
if: ${{ !startsWith(github.event.head_commit.message, 'bump:') }}
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down Expand Up @@ -40,33 +41,11 @@ jobs:
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
check_version:
name: Check if version changed
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.check-version.outputs.changed }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if version changed
id: check-version
run: |
_diff=$(echo $(git diff ${{ github.event.before }} ${{ github.event.after }}))
if [[ $_diff == *"+version"* ]]; then
echo "changed=true" >> $GITHUB_OUTPUT
echo "Version changed"
else
echo "changed=false" >> $GITHUB_OUTPUT
echo "Version did not change"
fi
pypi-publish:
name: Upload release to PyPI
runs-on: ubuntu-latest
needs:
- test
- check_version
if: ${{ needs.check_version.outputs.changed == 'true' }}
strategy:
matrix:
python-version: ["3.9"]
Expand All @@ -76,7 +55,26 @@ jobs:
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
steps:
- uses: actions/checkout@v4
- name: Check out
uses: actions/checkout@v4
with:
token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}"
fetch-depth: 0
- name: Create bump and changelog
id: cz
uses: commitizen-tools/commitizen-action@master
with:
github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
push: true
- name: Set Name and Version from pyproject.toml to output
id: project
run: |
name=$(grep "^name" pyproject.toml -m 1 | tr -s ' ' | tr -d '"' | tr -d "'" | cut -d' ' -f3 | tr "-" "_")
version=$(grep "^version" pyproject.toml -m 1 | tr -s ' ' | tr -d '"' | tr -d "'" | cut -d' ' -f3)
echo "NAME=$name" >> $GITHUB_OUTPUT
echo "VERSION=$version" >> $GITHUB_OUTPUT
echo "Releasing $name version $version"
ls -laR dist
# Download the Databricks CLI.
# See https://github.com/databricks/setup-cli
- uses: databricks/setup-cli@main
Expand All @@ -95,8 +93,16 @@ jobs:
rye sync --no-lock
- name: Build package
run: rye build
- name: list
run: ls -la
# retrieve your distributions here
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- name: Upload release to GitHub
uses: softprops/action-gh-release@v1
env:
PACKAGE_NAME: ${{ steps.project.outputs.NAME }}
VERSION: ${{ steps.project.outputs.VERSION }}
with:
tag_name: ${{ steps.cz.outputs.version }}
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
files: |
dist/${{ env.PACKAGE_NAME }}-${{ env.VERSION }}-py3-none-any.whl
dist/${{ env.PACKAGE_NAME }}-${{ env.VERSION }}.tar.gz
10 changes: 7 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
repos:
- repo: https://github.com/commitizen-tools/commitizen
rev: v3.29.0
hooks:
- id: commitizen
- repo: local
hooks:
- id: validate-codecov
name: Validate Codecov
language: system
entry: bash ./scripts/validate_codecov.sh
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v4.6.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.10.0
rev: 24.8.0
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.1
rev: v0.6.3
hooks:
# Run the linter.
- id: ruff
Expand Down
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dev-dependencies = [
"ipython",
"notebook",
"pre-commit",
"commitizen",
]

[tool.hatch.metadata]
Expand Down Expand Up @@ -74,3 +75,11 @@ lint.ignore = ["E501"] # Black takes care of line-too-long

[tool.ruff.lint.per-file-ignores]
"{tests,features}/*" = ["T201", "PLR2004", "PLR0915", "PLW1510"]

[tool.commitizen]
name = "cz_conventional_commits"
tag_format = "$version"
version_scheme = "pep440"
version_provider = "pep621"
update_changelog_on_bump = true
major_version_zero = true
20 changes: 19 additions & 1 deletion requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ anyio==4.4.0
# via jupyter-server
appnope==0.1.4
# via ipykernel
argcomplete==3.1.6
# via commitizen
argon2-cffi==23.1.0
# via jupyter-server
argon2-cffi-bindings==21.2.0
Expand Down Expand Up @@ -53,18 +55,24 @@ cfgv==3.4.0
chardet==5.2.0
# via binaryornot
charset-normalizer==3.3.2
# via commitizen
# via requests
click==8.1.7
# via cookiecutter
# via kedro
colorama==0.4.6
# via commitizen
comm==0.2.2
# via ipykernel
commitizen==3.9.1
cookiecutter==2.6.0
# via kedro
coverage==7.6.0
# via pytest-cov
debugpy==1.8.2
# via ipykernel
decli==0.6.2
# via commitizen
decorator==5.1.1
# via ipython
defusedxml==0.7.1
Expand Down Expand Up @@ -104,8 +112,9 @@ idna==3.7
# via httpx
# via jsonschema
# via requests
importlib-metadata==7.2.1
importlib-metadata==6.11.0
# via build
# via commitizen
# via jupyter-client
# via jupyter-lsp
# via jupyterlab
Expand All @@ -126,6 +135,7 @@ isort==5.13.2
jedi==0.19.1
# via ipython
jinja2==3.1.4
# via commitizen
# via cookiecutter
# via jupyter-server
# via jupyterlab
Expand Down Expand Up @@ -212,6 +222,7 @@ overrides==7.7.0
# via jupyter-server
packaging==24.1
# via build
# via commitizen
# via ipykernel
# via jupyter-server
# via jupyterlab
Expand Down Expand Up @@ -241,6 +252,7 @@ prometheus-client==0.20.0
# via jupyter-server
prompt-toolkit==3.0.47
# via ipython
# via questionary
psutil==6.0.0
# via ipykernel
ptyprocess==0.7.0
Expand Down Expand Up @@ -269,6 +281,7 @@ python-slugify==8.0.4
pytoolconfig==1.3.1
# via rope
pyyaml==6.0.1
# via commitizen
# via cookiecutter
# via jupyter-events
# via kedro
Expand All @@ -278,6 +291,8 @@ pyzmq==26.0.3
# via ipykernel
# via jupyter-client
# via jupyter-server
questionary==1.10.0
# via commitizen
referencing==0.35.1
# via jsonschema
# via jsonschema-specifications
Expand Down Expand Up @@ -321,6 +336,8 @@ soupsieve==2.5
# via beautifulsoup4
stack-data==0.6.3
# via ipython
termcolor==2.4.0
# via commitizen
terminado==0.18.1
# via jupyter-server
# via jupyter-server-terminals
Expand All @@ -338,6 +355,7 @@ tomli==2.0.1
# via pytest
# via pytoolconfig
tomlkit==0.13.0
# via commitizen
# via kedro-databricks
tornado==6.4.1
# via ipykernel
Expand Down

0 comments on commit 563bf7a

Please sign in to comment.