From 6fc14615de18cb97d22122bfc84c033abfe1a5c3 Mon Sep 17 00:00:00 2001 From: Daniel Tomlinson Date: Sat, 4 Jan 2025 14:33:07 +0000 Subject: [PATCH 1/2] update ci/cd --- .github/workflows/codacy.yml | 6 +- .github/workflows/publish.yml | 28 ++++++++- CHANGELOG.md | 22 +++++++ cliff.toml | 107 ++++++++++++++++++++++++++++++++++ makefile | 6 +- 5 files changed, 162 insertions(+), 7 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 cliff.toml diff --git a/.github/workflows/codacy.yml b/.github/workflows/codacy.yml index 5226662..1e6c643 100644 --- a/.github/workflows/codacy.yml +++ b/.github/workflows/codacy.yml @@ -1,9 +1,9 @@ name: Codacy Analysis on: - push: - branches: - - main + # push: + # branches: + # - main pull_request: branches: - main diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 795da4a..986a677 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -5,6 +5,9 @@ on: tags: - "v*" +permissions: + contents: write + jobs: publish-package: runs-on: ubuntu-latest @@ -14,7 +17,7 @@ jobs: uses: actions/checkout@v4.2.2 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5.3.0 with: python-version: "3.11" @@ -28,7 +31,7 @@ jobs: - name: Load cached venv id: cached-poetry-dependencies - uses: actions/cache@v3 + uses: actions/cache@v4.2.0 with: path: .venv key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }} @@ -41,7 +44,26 @@ jobs: if: steps.cached-poetry-dependencies.outputs.cache-hit == 'true' run: poetry install --no-interaction --only-root + - name: Build package + run: | + poetry build + + - name: Generate changelog for latest tag + uses: orhun/git-cliff-action@v4.4.2 + with: + config: cliff.toml + args: --latest + env: + OUTPUT: CHANGELOG.md + GITHUB_REPO: ${{ github.repository }} + + - name: Create release + uses: softprops/action-gh-release@v2.1.0 + with: + files: dist/* + body_path: CHANGELOG.md + - name: Publish package run: | poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }} - poetry publish --build + poetry publish diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..9066312 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,22 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [v0.1.1] - 2025-01-01 + +### ๐Ÿฅฑ Miscellaneous Tasks + +- Post-release fixes by [@dtomlinson91](https://github.com/dtomlinson91) in [#2](https://github.com/dtomlinson91/python-snaptime/pull/2) + + post-release fixes + + +## [v0.1.0] - 2025-01-01 + +### โœจ Features + +- Initial release by [@dtomlinson91](https://github.com/dtomlinson91) in [#1](https://github.com/dtomlinson91/python-snaptime/pull/1) + +[v0.1.1]: https://github.com/dtomlinson91/python-snaptime/compare/v0.1.0..v0.1.1 diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 0000000..e8683ee --- /dev/null +++ b/cliff.toml @@ -0,0 +1,107 @@ +# git-cliff ~ configuration file +# https://git-cliff.org/docs/configuration + +[remote.github] +owner = "dtomlinson91" +repo = "python-snaptime" +# token = "" + +[changelog] +# template for the changelog footer +header = """ +# Changelog\n +All notable changes to this project will be documented in this file. + +This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n +""" +# template for the changelog body +# https://keats.github.io/tera/docs/#introduction +body = """ +{%- macro remote_url() -%} + https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }} +{%- endmacro -%} +{% if version -%} + ## [{{ version | trim_start_matches(pat="4,v") | trim_start_matches(pat="5,v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} +{% else -%} + ## [Unreleased] +{% endif -%} +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | upper_first }} + {% for commit in commits %} + - {% if commit.breaking %}๐Ÿ’ฅ **BREAKING CHANGE**: {% endif %}{{ commit.message | upper_first -}}\ + {% if commit.remote.username %} by [@{{ commit.remote.username }}](https://github.com/{{ commit.remote.username }}){%- endif -%} + {% if commit.remote.pr_number %} in \ + [#{{ commit.remote.pr_number }}]({{ self::remote_url() }}/pull/{{ commit.remote.pr_number }}) \ + {%- endif -%} + {% if commit.body %} + \n{% for line in commit.body | split(pat="\n") %} + {{- line | indent(prefix=" ", first=true) }} + {% endfor -%} + {% endif -%} + {% endfor %} +{% endfor %}\n +""" + +# template for the changelog footer +footer = """ +{% for release in releases -%} + {% if release.version -%} + {% if release.previous.version -%} + [{{ release.version | trim_start_matches(pat="4,v") | trim_start_matches(pat="5,v") }}]: \ + https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}\ + /compare/{{ release.previous.version }}..{{ release.version }} + {% endif -%} + {% else -%} + [unreleased]: https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}\ + /compare/{{ release.previous.version }}..HEAD + {% endif -%} +{% endfor %} +""" +# remove the leading and trailing whitespace from the templates +trim = true + +[git] +# parse the commits based on https://www.conventionalcommits.org +conventional_commits = true +# filter out the commits that are not conventional +filter_unconventional = true +# process each line of a commit as an individual commit +split_commits = false + + +# regex for parsing and grouping commits +commit_parsers = [ + { message = "^feat", group = "โœจ Features" }, + { message = "^fix", group = "๐Ÿ› Bug Fixes" }, + { message = "^doc", group = "๐Ÿ“˜ Documentation" }, + { message = "^perf", group = "๐ŸŽ Performance" }, + { message = "^refactor", group = "๐Ÿ›  Refactor/Improvement" }, + { message = "^style", group = "๐ŸŽจ Styling", skip = true }, + { message = "^test", group = "๐Ÿงช Testing", skip = true }, + { message = "^build", group = "๐Ÿงฑ Build", skip = true }, + { body = ".*security", group = "๐Ÿ” Security", skip = true }, + { message = "^chore\\(deps.*\\)", skip = true }, + { message = "^chore\\(pr\\)", skip = true }, + { message = "^chore\\(pull\\)", skip = true }, + { message = "^chore\\(release\\): prepare for", skip = true }, + { message = "^chore|^ci", group = "๐Ÿฅฑ Miscellaneous Tasks", skip = false }, +] +# protect breaking changes from being skipped due to matching a skipping commit_parser +protect_breaking_commits = true +# filter out the commits that are not matched by commit parsers +filter_commits = true +# regex for matching git tags +tag_pattern = "^(v[0-9]+.[0-9]+.[0-9]+)(?:.dev[0-9]+)?$" +# regex for skipping tags +skip_tags = "v0.1.0-beta.1" +# regex for ignoring tags +ignore_tags = "" +# sort the tags topologically +topo_order = false +# sort the commits inside sections by oldest/newest order +sort_commits = "oldest" + +commit_preprocessors = [ + # remove issue numbers from commits + { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "" }, +] diff --git a/makefile b/makefile index a932b66..e944148 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -.PHONY: lint test +.PHONY: lint test changelog lint: @echo "Linting the code" @@ -13,3 +13,7 @@ test: @echo "Running tests" poetry run pytest --cov=python_snaptime poetry run coverage html + +changelog: + @echo "Generating changelog" + git cliff > CHANGELOG.md From 6dccbadeaca0587be8b841167d99b48ebea0cacf Mon Sep 17 00:00:00 2001 From: Daniel Tomlinson Date: Sat, 4 Jan 2025 14:51:47 +0000 Subject: [PATCH 2/2] update changelog generation tag --- cliff.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cliff.toml b/cliff.toml index e8683ee..f3aa406 100644 --- a/cliff.toml +++ b/cliff.toml @@ -91,7 +91,8 @@ protect_breaking_commits = true # filter out the commits that are not matched by commit parsers filter_commits = true # regex for matching git tags -tag_pattern = "^(v[0-9]+.[0-9]+.[0-9]+)(?:.dev[0-9]+)?$" +tag_pattern = "^(v[0-9]+.[0-9]+.[0-9]+)$" +# tag_pattern = "^(v[0-9]+.[0-9]+.[0-9]+)(?:.dev[0-9]+)?$" # regex for skipping tags skip_tags = "v0.1.0-beta.1" # regex for ignoring tags