gha-utils 4.11.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of gha-utils might be problematic. Click here for more details.
- gha_utils-4.11.0/PKG-INFO +349 -0
- gha_utils-4.11.0/gha_utils/__init__.py +20 -0
- gha_utils-4.11.0/gha_utils/__main__.py +49 -0
- gha_utils-4.11.0/gha_utils/changelog.py +150 -0
- gha_utils-4.11.0/gha_utils/cli.py +270 -0
- gha_utils-4.11.0/gha_utils/mailmap.py +166 -0
- gha_utils-4.11.0/gha_utils/metadata.py +1304 -0
- gha_utils-4.11.0/gha_utils/py.typed +0 -0
- gha_utils-4.11.0/gha_utils.egg-info/PKG-INFO +349 -0
- gha_utils-4.11.0/gha_utils.egg-info/SOURCES.txt +16 -0
- gha_utils-4.11.0/gha_utils.egg-info/dependency_links.txt +1 -0
- gha_utils-4.11.0/gha_utils.egg-info/entry_points.txt +2 -0
- gha_utils-4.11.0/gha_utils.egg-info/requires.txt +19 -0
- gha_utils-4.11.0/gha_utils.egg-info/top_level.txt +1 -0
- gha_utils-4.11.0/pyproject.toml +167 -0
- gha_utils-4.11.0/readme.md +285 -0
- gha_utils-4.11.0/setup.cfg +4 -0
- gha_utils-4.11.0/tests/test_changelog.py +90 -0
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: gha-utils
|
|
3
|
+
Version: 4.11.0
|
|
4
|
+
Summary: ⚙️ CLI helpers for GitHub Actions + reuseable workflows
|
|
5
|
+
Author-email: Kevin Deldycke <kevin@deldycke.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/kdeldycke/workflows
|
|
7
|
+
Project-URL: Repository, https://github.com/kdeldycke/workflows
|
|
8
|
+
Project-URL: Funding, https://github.com/sponsors/kdeldycke
|
|
9
|
+
Project-URL: Issues, https://github.com/kdeldycke/workflows/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/kdeldycke/workflows/blob/main/changelog.md
|
|
11
|
+
Keywords: build-automation,changelog-formatter,ci-cd,cli,formatting,github-actions,labels,linting,markdown,mypy,nuitka,packaging,pypi,python,release-automation,sphinx,sponsorship,terminal,typo,workflow-reusable,yaml
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Framework :: Sphinx
|
|
15
|
+
Classifier: Framework :: Pelican
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)
|
|
18
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
19
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
20
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
21
|
+
Classifier: Programming Language :: Python :: 3
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
26
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
27
|
+
Classifier: Programming Language :: Unix Shell
|
|
28
|
+
Classifier: Topic :: Documentation :: Sphinx
|
|
29
|
+
Classifier: Topic :: File Formats :: JSON
|
|
30
|
+
Classifier: Topic :: Security
|
|
31
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
32
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
33
|
+
Classifier: Topic :: Software Development :: Documentation
|
|
34
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
35
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
36
|
+
Classifier: Topic :: Software Development :: Version Control :: Git
|
|
37
|
+
Classifier: Topic :: System :: Archiving :: Packaging
|
|
38
|
+
Classifier: Topic :: System :: Installation/Setup
|
|
39
|
+
Classifier: Topic :: System :: Shells
|
|
40
|
+
Classifier: Topic :: System :: Software Distribution
|
|
41
|
+
Classifier: Topic :: Terminals
|
|
42
|
+
Classifier: Topic :: Text Processing :: Markup :: HTML
|
|
43
|
+
Classifier: Topic :: Text Processing :: Markup :: Markdown
|
|
44
|
+
Classifier: Topic :: Utilities
|
|
45
|
+
Classifier: Typing :: Typed
|
|
46
|
+
Requires-Python: >=3.10
|
|
47
|
+
Description-Content-Type: text/markdown
|
|
48
|
+
Requires-Dist: backports.strenum~=1.3.1; python_version < "3.11"
|
|
49
|
+
Requires-Dist: boltons>=24.0.0
|
|
50
|
+
Requires-Dist: bump-my-version>=0.21.0
|
|
51
|
+
Requires-Dist: click-extra~=4.11.0
|
|
52
|
+
Requires-Dist: packaging~=24.1
|
|
53
|
+
Requires-Dist: PyDriller~=2.6
|
|
54
|
+
Requires-Dist: pyproject-metadata~=0.9.0
|
|
55
|
+
Requires-Dist: tomli~=2.0.1; python_version < "3.11"
|
|
56
|
+
Requires-Dist: wcmatch>=8.5
|
|
57
|
+
Provides-Extra: test
|
|
58
|
+
Requires-Dist: coverage[toml]~=7.6.0; extra == "test"
|
|
59
|
+
Requires-Dist: pytest~=8.3.1; extra == "test"
|
|
60
|
+
Requires-Dist: pytest-cases~=3.8.3; extra == "test"
|
|
61
|
+
Requires-Dist: pytest-cov~=6.0.0; extra == "test"
|
|
62
|
+
Requires-Dist: pytest-github-actions-annotate-failures~=0.2.0; extra == "test"
|
|
63
|
+
Requires-Dist: pytest-randomly~=3.16.0; extra == "test"
|
|
64
|
+
|
|
65
|
+
# `gha-utils` CLI + reusable workflows
|
|
66
|
+
|
|
67
|
+
[](https://pypi.python.org/pypi/gha-utils)
|
|
68
|
+
[](https://pypi.python.org/pypi/gha-utils)
|
|
69
|
+
[](http://mypy-lang.org/)
|
|
70
|
+
[](https://github.com/kdeldycke/workflows/actions/workflows/tests.yaml?query=branch%3Amain)
|
|
71
|
+
[](https://app.codecov.io/gh/kdeldycke/workflows)
|
|
72
|
+
|
|
73
|
+
Thanks to this project, I am able to **release Python packages multiple times a day with only 2-clicks**.
|
|
74
|
+
|
|
75
|
+
This repository contains a collection of reusable workflows and its companion CLI called `gha-utils` (which stands for *GitHub action workflows utilities*).
|
|
76
|
+
|
|
77
|
+
It is designed for `uv`-based Python projects (and Awesome List projects as a bonus).
|
|
78
|
+
|
|
79
|
+
It takes care of:
|
|
80
|
+
|
|
81
|
+
- Version bumping
|
|
82
|
+
- Formatting autofix for: Python, Markdown, JSON, typos
|
|
83
|
+
- Linting: Python types with `mypy`, YAML, `zsh`, GitHub actions, links, Awesome lists, secrets
|
|
84
|
+
- Compiling of Python binaries for Linux / macOS / Windows on `x86_64` & `arm64`
|
|
85
|
+
- Building of Python packages and upload to PyPi
|
|
86
|
+
- Git version tagging and GitHub release creation
|
|
87
|
+
- Synchronization of: `uv.lock`, `.gitignore`, `.mailmap` and Mermaid dependency graph
|
|
88
|
+
- Auto-locking of inactive closed issues
|
|
89
|
+
- Static image optimization
|
|
90
|
+
- Sphinx documentation building & deployment, and `autodoc` updates
|
|
91
|
+
- Label management, with file-based and content-based rules
|
|
92
|
+
|
|
93
|
+
Nothing is done behind your back. A PR is created every time a change is proposed, so you can inspect it, ala dependabot.
|
|
94
|
+
|
|
95
|
+
## `gha-utils` CLI
|
|
96
|
+
|
|
97
|
+
### Ad-hoc execution
|
|
98
|
+
|
|
99
|
+
Thanks to `uv`, you can install and run `gha-utils` in one command, without polluting your system:
|
|
100
|
+
|
|
101
|
+
```shell-session
|
|
102
|
+
$ uvx gha-utils
|
|
103
|
+
Installed 45 packages in 45ms
|
|
104
|
+
Usage: gha-utils [OPTIONS] COMMAND [ARGS]...
|
|
105
|
+
|
|
106
|
+
Options:
|
|
107
|
+
--time / --no-time Measure and print elapsed execution time. [default:
|
|
108
|
+
no-time]
|
|
109
|
+
--color, --ansi / --no-color, --no-ansi
|
|
110
|
+
Strip out all colors and all ANSI codes from output.
|
|
111
|
+
[default: color]
|
|
112
|
+
-C, --config CONFIG_PATH Location of the configuration file. Supports glob
|
|
113
|
+
pattern of local path and remote URL. [default:
|
|
114
|
+
~/Library/Application Support/gha-
|
|
115
|
+
utils/*.{toml,yaml,yml,json,ini,xml}]
|
|
116
|
+
--show-params Show all CLI parameters, their provenance, defaults
|
|
117
|
+
and value, then exit.
|
|
118
|
+
-v, --verbosity LEVEL Either CRITICAL, ERROR, WARNING, INFO, DEBUG.
|
|
119
|
+
[default: WARNING]
|
|
120
|
+
--version Show the version and exit.
|
|
121
|
+
-h, --help Show this message and exit.
|
|
122
|
+
|
|
123
|
+
Commands:
|
|
124
|
+
changelog Maintain a Markdown-formatted changelog
|
|
125
|
+
mailmap-sync Update Git's .mailmap file with missing contributors
|
|
126
|
+
metadata Output project metadata
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
```shell-session
|
|
130
|
+
$ uvx gha-utils --version
|
|
131
|
+
gha-utils, version 4.9.0
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
That's the best way to get started with `gha-utils`, and experiment with its features.
|
|
135
|
+
|
|
136
|
+
### Executables
|
|
137
|
+
|
|
138
|
+
To ease deployment, standalone executables of `gha-utils`'s latest version are available as direct downloads for several platforms and architectures:
|
|
139
|
+
|
|
140
|
+
| Platform | `x86_64` | `arm64` |
|
|
141
|
+
| ----------- | --------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
|
|
142
|
+
| **Linux** | [Download `gha-utils-linux-x64.bin`](https://github.com/kdeldycke/workflows/releases/latest/download/gha-utils-linux-x64.bin) | |
|
|
143
|
+
| **macOS** | [Download `gha-utils-macos-x64.bin`](https://github.com/kdeldycke/workflows/releases/latest/download/gha-utils-macos-x64.bin) | [Download `gha-utils-macos-arm64.bin`](https://github.com/kdeldycke/workflows/releases/latest/download/gha-utils-macos-arm64.bin) |
|
|
144
|
+
| **Windows** | [Download `gha-utils-windows-x64.exe`](https://github.com/kdeldycke/workflows/releases/latest/download/gha-utils-windows-x64.exe) | |
|
|
145
|
+
|
|
146
|
+
### Development version
|
|
147
|
+
|
|
148
|
+
To play with the latest development version of `gha-utils`, you can install it directly from the repository:
|
|
149
|
+
|
|
150
|
+
```shell-session
|
|
151
|
+
$ git clone https://github.com/kdeldycke/workflows
|
|
152
|
+
$ cd workflows
|
|
153
|
+
$ python -m pip install uv
|
|
154
|
+
$ uv venv
|
|
155
|
+
$ source .venv/bin/activate
|
|
156
|
+
$ uv sync
|
|
157
|
+
$ uv run -- gha-utils
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Reusable workflows collection
|
|
161
|
+
|
|
162
|
+
This repository contains workflows to automate most of the boring tasks.
|
|
163
|
+
|
|
164
|
+
These workflows are mostly used for Python projects and their documentation, but not only. They're all [reusable GitHub actions workflows](https://docs.github.com/en/actions/learn-github-actions/reusing-workflows).
|
|
165
|
+
|
|
166
|
+
Reasons for a centralized workflow repository:
|
|
167
|
+
|
|
168
|
+
- reusability of course: no need to update dozens of repository where 95% of workflows are the same
|
|
169
|
+
- centralize all dependencies pertaining to automation: think of the point-release of an action that triggers dependabot upgrade to all your repositories depending on it
|
|
170
|
+
|
|
171
|
+
### Guidelines
|
|
172
|
+
|
|
173
|
+
I don't want to copy-n-past, keep in sync and maintain another `N`th CI/CD file at the root of my repositories.
|
|
174
|
+
|
|
175
|
+
So my policy is: move every repository-specific config in a `pyproject.toml` file, or hide the gory details in a reused workflow.
|
|
176
|
+
|
|
177
|
+
### `.github/workflows/docs.yaml` jobs
|
|
178
|
+
|
|
179
|
+
- Autofix typos
|
|
180
|
+
|
|
181
|
+
- Optimize images
|
|
182
|
+
|
|
183
|
+
- Keep `.mailmap` up to date
|
|
184
|
+
|
|
185
|
+
- Update dependency graph of Python projects
|
|
186
|
+
|
|
187
|
+
- **Requires**:
|
|
188
|
+
- Python package with a `pyproject.toml` file
|
|
189
|
+
|
|
190
|
+
- Build Sphinx-based documentation and publish it to GitHub Pages
|
|
191
|
+
|
|
192
|
+
- **Requires**:
|
|
193
|
+
- Python package with a `pyproject.toml` file
|
|
194
|
+
- All Sphinx dependencies in a `docs` [extra dependency group](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#dependencies-and-requirements):
|
|
195
|
+
```toml
|
|
196
|
+
[project.optional-dependencies]
|
|
197
|
+
docs = [
|
|
198
|
+
"furo == 2024.1.29",
|
|
199
|
+
"myst-parser ~= 3.0.0",
|
|
200
|
+
"sphinx >= 6",
|
|
201
|
+
...
|
|
202
|
+
]
|
|
203
|
+
```
|
|
204
|
+
- Sphinx configuration file at `docs/conf.py`
|
|
205
|
+
|
|
206
|
+
- Sync awesome projects from `awesome-template` repository
|
|
207
|
+
|
|
208
|
+
### Why all these `requirements/*.txt` files?
|
|
209
|
+
|
|
210
|
+
Let's look for example at the `lint-yaml` job from [`.github/workflows/lint.yaml`](https://github.com/kdeldycke/workflows/blob/main/.github/workflows/lint.yaml#L126). Here we only need the `yamllint` CLI. This CLI is [distributed on PyPi](https://pypi.org/project/yamllint/). So before executing it, we could have simply run the following step:
|
|
211
|
+
|
|
212
|
+
```yaml
|
|
213
|
+
- name: Install yamllint
|
|
214
|
+
run: |
|
|
215
|
+
pip install yamllint
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Instead, we install it via the [`requirements/yamllint.txt` file](https://github.com/kdeldycke/workflows/blob/main/requirements/yamllint.txt).
|
|
219
|
+
|
|
220
|
+
Why? Because I want the version of `yamllint` to be pinned. By pinning it, I make the workflow stable, predictable and reproducible.
|
|
221
|
+
|
|
222
|
+
So why use a dedicated requirements file? Why don't we simply add the version? Like this:
|
|
223
|
+
|
|
224
|
+
```yaml
|
|
225
|
+
- name: Install yamllint
|
|
226
|
+
run: |
|
|
227
|
+
pip install yamllint==1.35.1
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
That would indeed pin the version. But it requires the maintainer (me) to keep track of new release and update manually the version string. That's a lot of work. And I'm lazy. So this should be automated.
|
|
231
|
+
|
|
232
|
+
To automate that, the only practical way I found was to rely on dependabot. But dependabot cannot update arbitrary versions in `run:` YAML blocks. It [only supports `requirements.txt` and `pyproject.toml`](https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#pip-and-pip-compile) files for Python projects.
|
|
233
|
+
|
|
234
|
+
So to keep track of new versions of dependencies while keeping them stable, we've hard-coded all Python libraries and CLIs in the `requirements/*.txt` files. All with pinned versions.
|
|
235
|
+
|
|
236
|
+
And for the case we need to install all dependencies in one go, we have a [`requirements.txt` file at the root](https://github.com/kdeldycke/workflows/blob/main/requirements.txt) that is referencing all files from the `requirements/` subfolder.
|
|
237
|
+
|
|
238
|
+
### Permissions and token
|
|
239
|
+
|
|
240
|
+
This repository updates itself via GitHub actions. It particularly updates its own YAML files in `.github/workflows`. That's forbidden by default. So we need extra permissions.
|
|
241
|
+
|
|
242
|
+
Usually, to grant special permissions to some jobs, you use the [`permissions` parameter in workflow](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions) files. It looks like this:
|
|
243
|
+
|
|
244
|
+
```yaml
|
|
245
|
+
on: (...)
|
|
246
|
+
|
|
247
|
+
jobs:
|
|
248
|
+
|
|
249
|
+
my-job:
|
|
250
|
+
runs-on: ubuntu-latest
|
|
251
|
+
permissions:
|
|
252
|
+
contents: write
|
|
253
|
+
pull-requests: write
|
|
254
|
+
|
|
255
|
+
steps: (...)
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
But the `contents: write` permission doesn't allow write access to the workflow files in the `.github` subfolder. There is `actions: write`, but it only covers workflow runs, not their YAML source file. Even a `permissions: write-all` doesn't work. So you cannot use the `permissions` parameter to allow a repository's workflow update its own workflow files.
|
|
259
|
+
|
|
260
|
+
You will always end up with this kind or errors:
|
|
261
|
+
|
|
262
|
+
```text
|
|
263
|
+
! [remote rejected] branch_xxx -> branch_xxx (refusing to allow a GitHub App to create or update workflow `.github/workflows/my_workflow.yaml` without `workflows` permission)
|
|
264
|
+
|
|
265
|
+
error: failed to push some refs to 'https://github.com/kdeldycke/my-repo'
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
> [!NOTE]
|
|
269
|
+
> That's also why the Settings > Actions > General > Workflow permissions parameter on your repository has no effect on this issue, even with the `Read and write permissions` set:
|
|
270
|
+
> 
|
|
271
|
+
|
|
272
|
+
To bypass the limitation, we rely on a custom access token. By convention, we call it `WORKFLOW_UPDATE_GITHUB_PAT`. It will be used, [in place of the default `secrets.GITHUB_TOKEN`](https://github.com/search?q=repo%3Akdeldycke%2Fworkflows%20WORKFLOW_UPDATE_GITHUB_PAT&type=code), in steps in which we need to change the workflow YAML files.
|
|
273
|
+
|
|
274
|
+
To create this custom `WORKFLOW_UPDATE_GITHUB_PAT`:
|
|
275
|
+
|
|
276
|
+
- From your GitHub user, go to `Settings` > `Developer Settings` > `Personal Access Tokens` > `Fine-grained tokens`
|
|
277
|
+
- Click on the `Generate new token` button
|
|
278
|
+
- Choose a good token name like `workflow-self-update` to make your intention clear
|
|
279
|
+
- Choose `Only select repositories` and the list the repositories in needs of updating their workflow YAML files
|
|
280
|
+
- In the `Repository permissions` drop-down, sets:
|
|
281
|
+
- `Contents`: `Access: **Read and Write**`
|
|
282
|
+
- `Metadata` (mandatory): `Access: **Read-only**`
|
|
283
|
+
- `Pull Requests`: `Access: **Read and Write**`
|
|
284
|
+
- `Workflows`: `Access: **Read and Write**`
|
|
285
|
+
> [!NOTE]
|
|
286
|
+
> This is the only place where I can have control over the `Workflows` permission, which is not supported by the `permissions:` parameter in YAML files.
|
|
287
|
+
- Now save these parameters and copy the `github_pat_XXXX` secret token
|
|
288
|
+
- Got to your repo > `Settings` > `Security` > `Secrets and variables` > `Actions` > `Secrets` > `Repository secrets` and click `New repository secrets`
|
|
289
|
+
- Name your secret `WORKFLOW_UPDATE_GITHUB_PAT` and copy the `github_pat_XXXX` token in the `Secret` field
|
|
290
|
+
|
|
291
|
+
Now re-run your actions and they should be able to update the workflow files in `.github` folder without the `refusing to allow a GitHub App to create or update workflow` error.
|
|
292
|
+
|
|
293
|
+
### Release management
|
|
294
|
+
|
|
295
|
+
It turns out [Release Engineering is a full-time job, and full of edge-cases](https://blog.axo.dev/2023/02/cargo-dist).
|
|
296
|
+
|
|
297
|
+
Rust has [`cargo-dist`](https://github.com/axodotdev/cargo-dist). Go has... ? But there is no equivalent for Python.
|
|
298
|
+
|
|
299
|
+
So I made up a [`release.yaml` workflow](https://github.com/kdeldycke/workflows/blob/main/.github/workflows/release.yaml), which:
|
|
300
|
+
|
|
301
|
+
1. Extracts project metadata from `pyproject.toml`
|
|
302
|
+
1. Generates a build matrix of all commits / os / arch / CLI entry points
|
|
303
|
+
1. Build Python wheel with Twine
|
|
304
|
+
1. Compile binaries of all CLI with Nuitka
|
|
305
|
+
1. Tag the release commit in Git
|
|
306
|
+
1. Publish new version to PyPi
|
|
307
|
+
1. Publish a GitHub release
|
|
308
|
+
1. Attach and rename build artifacts to it
|
|
309
|
+
|
|
310
|
+
## Changelog
|
|
311
|
+
|
|
312
|
+
A [detailed changelog](changelog.md) is available.
|
|
313
|
+
|
|
314
|
+
## Used in
|
|
315
|
+
|
|
316
|
+
Check these projects to get real-life examples of usage and inspiration:
|
|
317
|
+
|
|
318
|
+
-  [Awesome Falsehood](https://github.com/kdeldycke/awesome-falsehood#readme) - Falsehoods Programmers Believe in.
|
|
319
|
+
-  [Awesome Engineering Team Management](https://github.com/kdeldycke/awesome-engineering-team-management#readme) - How to transition from software development to engineering management.
|
|
320
|
+
-  [Awesome IAM](https://github.com/kdeldycke/awesome-iam#readme) - Identity and Access Management knowledge for cloud platforms.
|
|
321
|
+
-  [Awesome Billing](https://github.com/kdeldycke/awesome-billing#readme) - Billing & Payments knowledge for cloud platforms.
|
|
322
|
+
-  [Meta Package Manager](https://github.com/kdeldycke/meta-package-manager#readme) - A unifying CLI for multiple package managers.
|
|
323
|
+
-  [Mail Deduplicate](https://github.com/kdeldycke/mail-deduplicate#readme) - A CLI to deduplicate similar emails.
|
|
324
|
+
-  [dotfiles](https://github.com/kdeldycke/dotfiles#readme) - macOS dotfiles for Python developers.
|
|
325
|
+
-  [Click Extra](https://github.com/kdeldycke/click-extra#readme) - Extra colorization and configuration loading for Click.
|
|
326
|
+
-  [Wiki bot](https://github.com/themagicalmammal/wikibot#readme) - A bot which provides features from Wikipedia like summary, title searches, location API etc.
|
|
327
|
+
-  [workflows](https://github.com/kdeldycke/workflows#readme) - Itself. Eat your own dog-food.
|
|
328
|
+
-  [Stock Analysis](https://github.com/themagicalmammal/stock-analyser#readme) - Simple to use interfaces for basic technical analysis of stocks.
|
|
329
|
+
-  [GeneticTabler](https://github.com/themagicalmammal/genetictabler#readme) - Time Table Scheduler using Genetic Algorithms.
|
|
330
|
+
-  [Excel Write](https://github.com/themagicalmammal/excel-write#readme) - Optimised way to write in excel files.
|
|
331
|
+
|
|
332
|
+
Feel free to send a PR to add your project in this list if you are relying on these scripts.
|
|
333
|
+
|
|
334
|
+
## Release process
|
|
335
|
+
|
|
336
|
+
All steps of the release process and version management are automated in the
|
|
337
|
+
[`changelog.yaml`](https://github.com/kdeldycke/workflows/blob/main/.github/workflows/changelog.yaml)
|
|
338
|
+
and
|
|
339
|
+
[`release.yaml`](https://github.com/kdeldycke/workflows/blob/main/.github/workflows/release.yaml)
|
|
340
|
+
workflows.
|
|
341
|
+
|
|
342
|
+
All there's left to do is to:
|
|
343
|
+
|
|
344
|
+
- [check the open draft `prepare-release` PR](https://github.com/kdeldycke/workflows/pulls?q=is%3Apr+is%3Aopen+head%3Aprepare-release)
|
|
345
|
+
and its changes,
|
|
346
|
+
- click the `Ready for review` button,
|
|
347
|
+
- click the `Rebase and merge` button,
|
|
348
|
+
- let the workflows tag the release and set back the `main` branch into a
|
|
349
|
+
development state.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Copyright Kevin Deldycke <kevin@deldycke.com> and contributors.
|
|
2
|
+
#
|
|
3
|
+
# This program is Free Software; you can redistribute it and/or
|
|
4
|
+
# modify it under the terms of the GNU General Public License
|
|
5
|
+
# as published by the Free Software Foundation; either version 2
|
|
6
|
+
# of the License, or (at your option) any later version.
|
|
7
|
+
#
|
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
+
# GNU General Public License for more details.
|
|
12
|
+
#
|
|
13
|
+
# You should have received a copy of the GNU General Public License
|
|
14
|
+
# along with this program; if not, write to the Free Software
|
|
15
|
+
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
16
|
+
"""Expose package-wide elements."""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
__version__ = "4.11.0"
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Copyright Kevin Deldycke <kevin@deldycke.com> and contributors.
|
|
2
|
+
#
|
|
3
|
+
# This program is Free Software; you can redistribute it and/or
|
|
4
|
+
# modify it under the terms of the GNU General Public License
|
|
5
|
+
# as published by the Free Software Foundation; either version 2
|
|
6
|
+
# of the License, or (at your option) any later version.
|
|
7
|
+
#
|
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
+
# GNU General Public License for more details.
|
|
12
|
+
#
|
|
13
|
+
# You should have received a copy of the GNU General Public License
|
|
14
|
+
# along with this program; if not, write to the Free Software
|
|
15
|
+
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
16
|
+
"""Allow the module to be run as a CLI. I.e.:
|
|
17
|
+
|
|
18
|
+
.. code-block:: shell-session
|
|
19
|
+
|
|
20
|
+
$ python -m gha_utils
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from __future__ import annotations
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def main():
|
|
27
|
+
"""Execute the CLI but force its name to not let Click defaults to:
|
|
28
|
+
|
|
29
|
+
.. code-block:: shell-session
|
|
30
|
+
$ python -m gha_utils --version
|
|
31
|
+
python -m gha_utils, version 4.0.0
|
|
32
|
+
|
|
33
|
+
Indirection via this ``main()`` method was `required to reconcile
|
|
34
|
+
<https://github.com/python-poetry/poetry/issues/5981>`_:
|
|
35
|
+
|
|
36
|
+
- plain inline package call: ``python -m gha_utils``,
|
|
37
|
+
- Poetry's script entry point: ``gha-utils = 'gha_utils.__main__:main``,
|
|
38
|
+
- Nuitka's main module invocation requirement:
|
|
39
|
+
``python -m nuitka (...) gha_utils/__main__.py``
|
|
40
|
+
|
|
41
|
+
That way we can deduce all three cases from the entry point.
|
|
42
|
+
"""
|
|
43
|
+
from gha_utils.cli import gha_utils
|
|
44
|
+
|
|
45
|
+
gha_utils(prog_name=gha_utils.name)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
if __name__ == "__main__":
|
|
49
|
+
main()
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# Copyright Kevin Deldycke <kevin@deldycke.com> and contributors.
|
|
2
|
+
#
|
|
3
|
+
# This program is Free Software; you can redistribute it and/or
|
|
4
|
+
# modify it under the terms of the GNU General Public License
|
|
5
|
+
# as published by the Free Software Foundation; either version 2
|
|
6
|
+
# of the License, or (at your option) any later version.
|
|
7
|
+
#
|
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
+
# GNU General Public License for more details.
|
|
12
|
+
#
|
|
13
|
+
# You should have received a copy of the GNU General Public License
|
|
14
|
+
# along with this program; if not, write to the Free Software
|
|
15
|
+
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import logging
|
|
20
|
+
import re
|
|
21
|
+
import sys
|
|
22
|
+
from functools import cached_property
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
from textwrap import indent
|
|
25
|
+
|
|
26
|
+
if sys.version_info >= (3, 11):
|
|
27
|
+
import tomllib
|
|
28
|
+
else:
|
|
29
|
+
import tomli as tomllib # type: ignore[import-not-found]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class Changelog:
|
|
33
|
+
"""Helpers to manipulate changelog files written in Markdown."""
|
|
34
|
+
|
|
35
|
+
def __init__(self, initial_changelog: str | None = None) -> None:
|
|
36
|
+
if not initial_changelog:
|
|
37
|
+
self.content = "# Changelog\n"
|
|
38
|
+
else:
|
|
39
|
+
self.content = initial_changelog
|
|
40
|
+
logging.debug(f"Initial content set to:\n{self.content}")
|
|
41
|
+
|
|
42
|
+
@cached_property
|
|
43
|
+
def current_version(self) -> str | None:
|
|
44
|
+
# Extract current version as defined by bump-my-version.
|
|
45
|
+
config_file = Path("./pyproject.toml").resolve()
|
|
46
|
+
logging.info(f"Open {config_file}")
|
|
47
|
+
config = tomllib.loads(config_file.read_text(encoding="UTF-8"))
|
|
48
|
+
current_version = config["tool"]["bumpversion"]["current_version"]
|
|
49
|
+
logging.info(f"Current version: {current_version}")
|
|
50
|
+
return current_version if current_version else None
|
|
51
|
+
|
|
52
|
+
def update(self) -> str:
|
|
53
|
+
r"""Adds a new empty entry at the top of the changelog.
|
|
54
|
+
|
|
55
|
+
Will return the same content as the current changelog if it has already been updated.
|
|
56
|
+
|
|
57
|
+
This is designed to be used just after a new release has been tagged. And before a
|
|
58
|
+
post-release version increment is applied with a call to:
|
|
59
|
+
|
|
60
|
+
```shell-session
|
|
61
|
+
$ bump-my-version bump --verbose patch
|
|
62
|
+
Starting BumpVersion 0.5.1.dev6
|
|
63
|
+
Reading config file pyproject.toml:
|
|
64
|
+
Specified version (2.17.5) does not match last tagged version (2.17.4)
|
|
65
|
+
Parsing version '2.17.5' using '(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)'
|
|
66
|
+
Parsed the following values: major=2, minor=17, patch=5
|
|
67
|
+
Attempting to increment part 'patch'
|
|
68
|
+
Values are now: major=2, minor=17, patch=6
|
|
69
|
+
New version will be '2.17.6'
|
|
70
|
+
Dry run active, won't touch any files.
|
|
71
|
+
Asserting files ./changelog.md contain the version string...
|
|
72
|
+
Found '[2.17.5 (unreleased)](' in ./changelog.md at line 2:
|
|
73
|
+
## [2.17.5 (unreleased)](https://github.com/kdeldycke/workflows/compare/v2.17.4...main)
|
|
74
|
+
Would change file ./changelog.md:
|
|
75
|
+
*** before ./changelog.md
|
|
76
|
+
--- after ./changelog.md
|
|
77
|
+
***************
|
|
78
|
+
*** 1,6 ****
|
|
79
|
+
# Changelog
|
|
80
|
+
|
|
81
|
+
! ## [2.17.5 (unreleased)](https://github.com/kdeldycke/workflows/compare/v2.17.4...main)
|
|
82
|
+
|
|
83
|
+
> [!IMPORTANT]
|
|
84
|
+
> This version is not released yet and is under active development.
|
|
85
|
+
--- 1,6 ----
|
|
86
|
+
# Changelog
|
|
87
|
+
|
|
88
|
+
! ## [2.17.6 (unreleased)](https://github.com/kdeldycke/workflows/compare/v2.17.4...main)
|
|
89
|
+
|
|
90
|
+
> [!IMPORTANT]
|
|
91
|
+
> This version is not released yet and is under active development.
|
|
92
|
+
Would write to config file pyproject.toml:
|
|
93
|
+
*** before pyproject.toml
|
|
94
|
+
--- after pyproject.toml
|
|
95
|
+
***************
|
|
96
|
+
*** 1,5 ****
|
|
97
|
+
[tool.bumpversion]
|
|
98
|
+
! current_version = "2.17.5"
|
|
99
|
+
allow_dirty = true
|
|
100
|
+
|
|
101
|
+
[[tool.bumpversion.files]]
|
|
102
|
+
--- 1,5 ----
|
|
103
|
+
[tool.bumpversion]
|
|
104
|
+
! current_version = "2.17.6"
|
|
105
|
+
allow_dirty = true
|
|
106
|
+
|
|
107
|
+
[[tool.bumpversion.files]]
|
|
108
|
+
Would not commit
|
|
109
|
+
Would not tag since we are not committing
|
|
110
|
+
```
|
|
111
|
+
"""
|
|
112
|
+
# Extract parts of the changelog or set default values.
|
|
113
|
+
SECTION_START = "##"
|
|
114
|
+
sections = self.content.split(SECTION_START, 2)
|
|
115
|
+
changelog_header = sections[0] if len(sections) > 0 else "# Changelog\n\n"
|
|
116
|
+
current_entry = f"{SECTION_START}{sections[1]}" if len(sections) > 1 else ""
|
|
117
|
+
past_entries = f"{SECTION_START}{sections[2]}" if len(sections) > 2 else ""
|
|
118
|
+
|
|
119
|
+
# Derive the release template from the last entry.
|
|
120
|
+
DATE_REGEX = r"\d{4}\-\d{2}\-\d{2}"
|
|
121
|
+
VERSION_REGEX = r"\d+\.\d+\.\d+"
|
|
122
|
+
|
|
123
|
+
# Replace the release date with the unreleased tag.
|
|
124
|
+
new_entry = re.sub(DATE_REGEX, "unreleased", current_entry, count=1)
|
|
125
|
+
|
|
126
|
+
# Update GitHub's comparison URL to target the main branch.
|
|
127
|
+
new_entry = re.sub(
|
|
128
|
+
rf"v{VERSION_REGEX}\.\.\.v{VERSION_REGEX}",
|
|
129
|
+
f"v{self.current_version}...main",
|
|
130
|
+
new_entry,
|
|
131
|
+
count=1,
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
# Replace the whole paragraph of changes by a notice message. The paragraph is
|
|
135
|
+
# identified as starting by a blank line, at which point everything gets
|
|
136
|
+
# replaced.
|
|
137
|
+
new_entry = re.sub(
|
|
138
|
+
r"\n\n.*",
|
|
139
|
+
"\n\n"
|
|
140
|
+
"> [!IMPORTANT]\n"
|
|
141
|
+
"> This version is not released yet and is under active development.\n\n",
|
|
142
|
+
new_entry,
|
|
143
|
+
flags=re.MULTILINE | re.DOTALL,
|
|
144
|
+
)
|
|
145
|
+
logging.info("New generated section:\n" + indent(new_entry, " " * 2))
|
|
146
|
+
|
|
147
|
+
history = current_entry + past_entries
|
|
148
|
+
if new_entry not in history:
|
|
149
|
+
history = new_entry + history
|
|
150
|
+
return (changelog_header + history).rstrip()
|