gha-utils 4.4.5__py3-none-any.whl → 4.5.1__py3-none-any.whl

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/__init__.py CHANGED
@@ -17,4 +17,4 @@
17
17
 
18
18
  from __future__ import annotations
19
19
 
20
- __version__ = "4.4.5"
20
+ __version__ = "4.5.1"
gha_utils/changelog.py CHANGED
@@ -69,14 +69,14 @@ class Changelog:
69
69
 
70
70
  ! ## [2.17.5 (unreleased)](https://github.com/kdeldycke/workflows/compare/v2.17.4...main)
71
71
 
72
- > \[!IMPORTANT\]
72
+ > [!IMPORTANT]
73
73
  > This version is not released yet and is under active development.
74
74
  --- 1,6 ----
75
75
  # Changelog
76
76
 
77
77
  ! ## [2.17.6 (unreleased)](https://github.com/kdeldycke/workflows/compare/v2.17.4...main)
78
78
 
79
- > \[!IMPORTANT\]
79
+ > [!IMPORTANT]
80
80
  > This version is not released yet and is under active development.
81
81
  Would write to config file pyproject.toml:
82
82
  *** before pyproject.toml
@@ -101,7 +101,7 @@ class Changelog:
101
101
  # Extract current version as defined by bump-my-version.
102
102
  config_file = Path("./pyproject.toml").resolve()
103
103
  logging.info(f"Open {config_file}")
104
- config = tomllib.loads(config_file.read_text(encoding="utf-8"))
104
+ config = tomllib.loads(config_file.read_text(encoding="UTF-8"))
105
105
  current_version = config["tool"]["bumpversion"]["current_version"]
106
106
  logging.info(f"Current version: {current_version}")
107
107
  assert current_version
@@ -112,15 +112,15 @@ class Changelog:
112
112
  SECTION_START = "##"
113
113
  sections = self.content.split(SECTION_START, 2)
114
114
  changelog_header = sections[0] if len(sections) > 0 else "# Changelog\n\n"
115
- recent_entry = sections[1] if len(sections) > 1 else ""
116
- past_entries = sections[2] if len(sections) > 2 else ""
115
+ current_entry = f"{SECTION_START}{sections[1]}" if len(sections) > 1 else ""
116
+ past_entries = f"{SECTION_START}{sections[2]}" if len(sections) > 2 else ""
117
117
 
118
118
  # Derive the release template from the last entry.
119
119
  DATE_REGEX = r"\d{4}\-\d{2}\-\d{2}"
120
120
  VERSION_REGEX = r"\d+\.\d+\.\d+"
121
121
 
122
122
  # Replace the release date with the unreleased tag.
123
- new_entry = re.sub(DATE_REGEX, "unreleased", recent_entry, count=1)
123
+ new_entry = re.sub(DATE_REGEX, "unreleased", current_entry, count=1)
124
124
 
125
125
  # Update GitHub's comparison URL to target the main branch.
126
126
  new_entry = re.sub(
@@ -136,21 +136,17 @@ class Changelog:
136
136
  new_entry = re.sub(
137
137
  r"\n\n.*",
138
138
  "\n\n"
139
- "> \\[!IMPORTANT\\]\n"
139
+ "> [!IMPORTANT]\n"
140
140
  "> This version is not released yet and is under active development.\n\n",
141
141
  new_entry,
142
142
  flags=re.MULTILINE | re.DOTALL,
143
143
  )
144
-
145
- # Prefix entries with section marker.
146
144
  new_entry = f"{SECTION_START}{new_entry}"
147
- history = f"{SECTION_START}{recent_entry}{SECTION_START}{past_entries}"
148
-
149
145
  logging.info("New generated section:\n" + indent(new_entry, " " * 2))
150
146
 
151
147
  # No need to update.
148
+ history = f"{current_entry}{past_entries}"
152
149
  if new_entry in history:
153
150
  return None
154
-
155
151
  # Recompose full changelog with new top entry.
156
152
  return f"{changelog_header}{new_entry}{history}"
gha_utils/cli.py CHANGED
@@ -19,14 +19,15 @@ from __future__ import annotations
19
19
  import logging
20
20
  import os
21
21
  import sys
22
- from contextlib import contextmanager
23
22
  from datetime import datetime
24
23
  from pathlib import Path
24
+ from typing import IO
25
25
 
26
26
  from click_extra import (
27
27
  Choice,
28
28
  Context,
29
29
  argument,
30
+ echo,
30
31
  extra_group,
31
32
  file_path,
32
33
  option,
@@ -40,20 +41,19 @@ from .mailmap import Mailmap
40
41
  from .metadata import Dialects, Metadata
41
42
 
42
43
 
43
- def is_stdout(filepath):
44
+ def is_stdout(filepath: Path) -> bool:
45
+ """Check if a file path is set to stdout.
46
+
47
+ Prevents the creation of a ``-`` file in the current directory.
48
+ """
44
49
  return str(filepath) == "-"
45
50
 
46
51
 
47
- @contextmanager
48
- def file_writer(filepath):
49
- """A context-aware file writer which default to stdout if no path is
50
- provided."""
52
+ def prep_path(filepath: Path) -> IO | None:
53
+ """Prepare the output file parameter for Click's echo function."""
51
54
  if is_stdout(filepath):
52
- yield sys.stdout
53
- else:
54
- writer = filepath.open("w")
55
- yield writer
56
- writer.close()
55
+ return None
56
+ return filepath.open("w", encoding="UTF-8")
57
57
 
58
58
 
59
59
  def generate_header(ctx: Context) -> str:
@@ -78,10 +78,12 @@ def remove_header(content: str) -> str:
78
78
  if still_in_header:
79
79
  # We are still in the header as long as we have blank lines or we have
80
80
  # comment lines matching the format produced by the method above.
81
- if not line.strip() or line.startswith((
82
- "# Generated by ",
83
- "# Timestamp: ",
84
- )):
81
+ if not line.strip() or line.startswith(
82
+ (
83
+ "# Generated by ",
84
+ "# Timestamp: ",
85
+ )
86
+ ):
85
87
  continue
86
88
  else:
87
89
  still_in_header = False
@@ -161,9 +163,7 @@ def metadata(ctx, format, overwrite, output_path):
161
163
 
162
164
  dialect = Dialects(format)
163
165
  content = metadata.dump(dialect=dialect)
164
-
165
- with file_writer(output_path) as f:
166
- f.write(content)
166
+ echo(content, file=prep_path(output_path))
167
167
 
168
168
 
169
169
  @gha_utils.command(short_help="Maintain a Markdown-formatted changelog")
@@ -183,7 +183,7 @@ def changelog(ctx, source, changelog_path):
183
183
  initial_content = None
184
184
  if source:
185
185
  logging.info(f"Read initial changelog from {source}")
186
- initial_content = source.read_text(encoding="utf-8")
186
+ initial_content = source.read_text(encoding="UTF-8")
187
187
 
188
188
  changelog = Changelog(initial_content)
189
189
  content = changelog.update()
@@ -195,9 +195,7 @@ def changelog(ctx, source, changelog_path):
195
195
  logging.info(f"Print updated results to {sys.stdout.name}")
196
196
  else:
197
197
  logging.info(f"Save updated results to {changelog_path}")
198
-
199
- with file_writer(changelog_path) as f:
200
- f.write(content)
198
+ echo(content, file=prep_path(changelog_path))
201
199
 
202
200
 
203
201
  @gha_utils.command(short_help="Update Git's .mailmap file with missing contributors")
@@ -245,7 +243,7 @@ def mailmap_sync(ctx, source, create_if_missing, destination_mailmap):
245
243
 
246
244
  if source.exists():
247
245
  logging.info(f"Read initial mapping from {source}")
248
- content = remove_header(source.read_text(encoding="utf-8"))
246
+ content = remove_header(source.read_text(encoding="UTF-8"))
249
247
  mailmap.parse(content)
250
248
  else:
251
249
  logging.debug(f"Mailmap source file {source} does not exists.")
@@ -271,5 +269,4 @@ def mailmap_sync(ctx, source, create_if_missing, destination_mailmap):
271
269
  logging.warning("Nothing to update, stop the sync process.")
272
270
  ctx.exit()
273
271
 
274
- with file_writer(destination_mailmap) as f:
275
- f.write(generate_header(ctx) + new_content)
272
+ echo(generate_header(ctx) + new_content, file=prep_path(destination_mailmap))
gha_utils/mailmap.py CHANGED
@@ -131,7 +131,7 @@ class Mailmap:
131
131
 
132
132
  git_cli = ("git", "log", "--pretty=format:%aN <%aE>%n%cN <%cE>")
133
133
  logging.debug(f"Run: {' '.join(git_cli)}")
134
- process = run(git_cli, capture_output=True, encoding="utf-8")
134
+ process = run(git_cli, capture_output=True, encoding="UTF-8")
135
135
 
136
136
  # Parse git CLI output.
137
137
  if process.returncode:
gha_utils/metadata.py CHANGED
@@ -267,7 +267,7 @@ class Metadata:
267
267
  env:
268
268
  GITHUB_CONTEXT: ${{ toJSON(github) }}
269
269
  run: |
270
- uv --no-progress run gha-utils --verbosity DEBUG metadata --overwrite "$GITHUB_OUTPUT"
270
+ gha-utils --verbosity DEBUG metadata --overwrite "$GITHUB_OUTPUT"
271
271
 
272
272
  .. todo::
273
273
  Try to remove reliance on GitHub context entirely so we can eliminate the
@@ -626,7 +626,7 @@ class Metadata:
626
626
  ``pyproject.toml`` exists and respects the standards. ``False`` otherwise.
627
627
  """
628
628
  if self.pyproject_path.exists() and self.pyproject_path.is_file():
629
- toml = tomllib.loads(self.pyproject_path.read_text(encoding="utf-8"))
629
+ toml = tomllib.loads(self.pyproject_path.read_text(encoding="UTF-8"))
630
630
  try:
631
631
  metadata = StandardMetadata.from_pyproject(toml)
632
632
  self._is_python_project = True
@@ -1104,7 +1104,7 @@ class Metadata:
1104
1104
  changes = ""
1105
1105
  match = re.search(
1106
1106
  rf"^##(?P<title>.+{escape(version)} .+?)\n(?P<changes>.*?)\n##",
1107
- Path("./changelog.md").read_text(encoding="utf-8"),
1107
+ Path("./changelog.md").read_text(encoding="UTF-8"),
1108
1108
  flags=re.MULTILINE | re.DOTALL,
1109
1109
  )
1110
1110
  if match:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gha-utils
3
- Version: 4.4.5
3
+ Version: 4.5.1
4
4
  Summary: ⚙️ CLI helpers for GitHub Actions + reuseable workflows
5
5
  Author-email: Kevin Deldycke <kevin@deldycke.com>
6
6
  Project-URL: Homepage, https://github.com/kdeldycke/workflows
@@ -90,11 +90,11 @@ Nothing is done behind your back. A PR is created everytime a change is proposed
90
90
 
91
91
  Standalone executables of `gha-utils`'s latest version are available as direct downloads for several platforms and architectures:
92
92
 
93
- | Platform | `x86_64` | `arm64` |
94
- | ----------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
95
- | **Linux** | [Download `gha-utils-linux-x64.bin`](https://github.com/kdeldycke/workflows/releases/latest/download/gha-utils-linux-x64.bin) | |
96
- | **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) |
97
- | **Windows** | [Download `gha-utils-windows-x64.exe`](https://github.com/kdeldycke/workflows/releases/latest/download/gha-utils-windows-x64.exe) | |
93
+ | Platform | `x86_64` | `arm64` |
94
+ | ----------- | --------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
95
+ | **Linux** | [Download `gha-utils-linux-x64.bin`](https://github.com/kdeldycke/workflows/releases/latest/download/gha-utils-linux-x64.bin) | |
96
+ | **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) |
97
+ | **Windows** | [Download `gha-utils-windows-x64.exe`](https://github.com/kdeldycke/workflows/releases/latest/download/gha-utils-windows-x64.exe) | |
98
98
 
99
99
  ### Run dev version
100
100
 
@@ -216,7 +216,7 @@ You will always end up with this kind or errors:
216
216
  error: failed to push some refs to 'https://github.com/kdeldycke/my-repo'
217
217
  ```
218
218
 
219
- > \[!NOTE\]
219
+ > [!NOTE]
220
220
  > 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:
221
221
  > ![](docs/assets/repo-workflow-permissions.png)
222
222
 
@@ -233,7 +233,7 @@ To create this custom `WORKFLOW_UPDATE_GITHUB_PAT`:
233
233
  - `Metadata` (mandatory): `Access: **Read-only**`
234
234
  - `Pull Requests`: `Access: **Read and Write**`
235
235
  - `Workflows`: `Access: **Read and Write**`
236
- > \[!NOTE\]
236
+ > [!NOTE]
237
237
  > 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.
238
238
  - Now save these parameters and copy the `github_pat_XXXX` secret token
239
239
  - Got to your repo > `Settings` > `Security` > `Secrets and variables` > `Actions` > `Secrets` > `Repository secrets` and click `New repository secrets`
@@ -0,0 +1,12 @@
1
+ gha_utils/__init__.py,sha256=Lkof_jh0QHaox_62wIshAQPe0bbkcFTLk6wFZyB7wFY,865
2
+ gha_utils/__main__.py,sha256=Dck9BjpLXmIRS83k0mghAMcYVYiMiFLltQdfRuMSP_Q,1703
3
+ gha_utils/changelog.py,sha256=mcIUIce7ATNZyBeZerTWjDKB_mrReFdDJZJyDPIhS3Y,5915
4
+ gha_utils/cli.py,sha256=NlOktO7ddL8fhwkXEB3fVw3Qj-37maWnrYpyL_cKgHw,9202
5
+ gha_utils/mailmap.py,sha256=snSQBn1BDZ21783l4yCkQc3RLIxh5X6QCunFRkDj-24,6301
6
+ gha_utils/metadata.py,sha256=qdhAH-NHPusWIicoN9Js-7idvkcnJa9wzF4mVi7giPY,47203
7
+ gha_utils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ gha_utils-4.5.1.dist-info/METADATA,sha256=n3ADFMOjC8B5IllUjVzg0eNKzW4lk38-e7gLPcb1JGE,17976
9
+ gha_utils-4.5.1.dist-info/WHEEL,sha256=Mdi9PDNwEZptOjTlUcAth7XJDFtKrHYaQMPulZeBCiQ,91
10
+ gha_utils-4.5.1.dist-info/entry_points.txt,sha256=8bJOwQYf9ZqsLhBR6gUCzvwLNI9f8tiiBrJ3AR0EK4o,54
11
+ gha_utils-4.5.1.dist-info/top_level.txt,sha256=C94Blb61YkkyPBwCdM3J_JPDjWH0lnKa5nGZeZ5M6yE,10
12
+ gha_utils-4.5.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (72.2.0)
2
+ Generator: setuptools (73.0.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,12 +0,0 @@
1
- gha_utils/__init__.py,sha256=QBMQJ3ouEfz5WZFuN6QGlA8qM7VUlElMMuR7YamFzWw,865
2
- gha_utils/__main__.py,sha256=Dck9BjpLXmIRS83k0mghAMcYVYiMiFLltQdfRuMSP_Q,1703
3
- gha_utils/changelog.py,sha256=KuM323SslStwh25fuEiom39t1kfcgwxHAwi6KNy0Lhk,5959
4
- gha_utils/cli.py,sha256=4wUG29fB0-Z-n105UBgIg5NLuqtODtoMLwKJP7RQFXo,9150
5
- gha_utils/mailmap.py,sha256=sum4XIme2Dis7XtHyO9U7ogWelZwqb-yvJ5I92PPnqg,6301
6
- gha_utils/metadata.py,sha256=d7s3_wlWweIxvv5xvtnKg_ohqojRF8eVBR2U5PxHUlA,47224
7
- gha_utils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- gha_utils-4.4.5.dist-info/METADATA,sha256=QKk6F3Y4yLI_W-UFodlLep6_FRjO3ASH_FjDPJSFfVQ,17996
9
- gha_utils-4.4.5.dist-info/WHEEL,sha256=HiCZjzuy6Dw0hdX5R3LCFPDmFS4BWl8H-8W39XfmgX4,91
10
- gha_utils-4.4.5.dist-info/entry_points.txt,sha256=8bJOwQYf9ZqsLhBR6gUCzvwLNI9f8tiiBrJ3AR0EK4o,54
11
- gha_utils-4.4.5.dist-info/top_level.txt,sha256=C94Blb61YkkyPBwCdM3J_JPDjWH0lnKa5nGZeZ5M6yE,10
12
- gha_utils-4.4.5.dist-info/RECORD,,