Skip to content

Commit 29c4319

Browse files
committed
Add timezone as an input
1 parent 718967b commit 29c4319

File tree

5 files changed

+36
-13
lines changed

5 files changed

+36
-13
lines changed

.github/workflows/create-release-pr.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ on:
2020
description: Exact version number to target. Only used if bump_type is set to `exact`.
2121
required: false
2222
default: ""
23+
timezone:
24+
type: string
25+
description: IANA timezone to use when computing the current date
26+
default: "America/Los_Angeles"
27+
required: false
2328

2429
jobs:
2530
prepare-release:
@@ -28,6 +33,7 @@ jobs:
2833
env:
2934
BUMP_TYPE: ${{ inputs.bump_type }}
3035
EXACT_VERSION: ${{ inputs.exact_version }}
36+
CHANGELOG_TIMEZONE: ${{ inputs.timezone }}
3137

3238
steps:
3339
# Get the version of _this_ repository that is in use so that we can use

.github/workflows/pytest.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
python-version:
21-
- "3.8"
21+
- "3.9"
2222
- "3.12"
2323

2424
steps:

bumpchanges/bump.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
"Work with CHANGELOG.md files."
22

33
import argparse
4+
import datetime
5+
import logging
46
import os
57
import tempfile
8+
import zoneinfo
69

710
from logging import getLogger
8-
911
from pathlib import Path
1012

1113
from .changelog import Changelog, ChangelogError
1214
from .logging import setup_logging
1315

1416

15-
def update_changelog(changelog_file: Path, repo_url: str, version: str):
17+
def update_changelog(changelog_file: Path, repo_url: str, version: str, date: datetime.date):
1618
"Rewrite a CHANGELOG file for a new release."
1719

1820
try:
@@ -21,7 +23,7 @@ def update_changelog(changelog_file: Path, repo_url: str, version: str):
2123
getLogger(__name__).exception("Could not parse changelog")
2224
raise
2325

24-
changelog.update_version(version)
26+
changelog.update_version(version, date)
2527

2628
changelog_file.write_text(changelog.render(), encoding="utf-8")
2729

@@ -57,7 +59,7 @@ def write_commit_details(version: str):
5759
bodyfile.write(f"""\
5860
Update CHANGELOG in preparation for release **{version}**.
5961
60-
Merging this PR will trigger another workflow to create the release tag **v{version}**."
62+
Merging this PR will trigger another workflow to create the release tag **v{version}**.
6163
6264
| Input | Value |
6365
| ----- | ----- |
@@ -68,7 +70,7 @@ def write_commit_details(version: str):
6870

6971
outputs["pr_bodyfile"] = bodyfile.name
7072

71-
outputs["pr_title"] = f"Prepare for version **`{version}`**"
73+
outputs["pr_title"] = f"Prepare for version `{version}`"
7274
outputs["commit_message"] = f"Update CHANGELOG for version `{version}`"
7375

7476
Path(os.environ["GITHUB_OUTPUT"]).write_text(
@@ -87,5 +89,20 @@ def entrypoint():
8789
args = parser.parse_args()
8890
setup_logging()
8991

90-
update_changelog(args.changelog, args.repo_url, args.version)
92+
try:
93+
input_timezone = os.environ["CHANGELOG_TIMEZONE"]
94+
try:
95+
tzinfo = zoneinfo.ZoneInfo(input_timezone)
96+
except zoneinfo.ZoneInfoNotFoundError:
97+
logging.getLogger(__name__).warning(
98+
"Time zone `%s` not found! Defaulting to UTC", input_timezone
99+
)
100+
tzinfo = datetime.timezone.utc
101+
except KeyError:
102+
logging.getLogger(__name__).notice("No time zone provided, defaulting to UTC")
103+
tzinfo = datetime.timezone.utc
104+
105+
now_date = datetime.datetime.now(tzinfo).date()
106+
107+
update_changelog(args.changelog, args.repo_url, args.version, now_date)
91108
write_commit_details(args.version)

bumpchanges/changelog.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import datetime
44
import itertools
55
import logging
6+
import os
67
import re
78

89
from dataclasses import dataclass, field
@@ -304,7 +305,7 @@ def __init__(self, changelog_file: Path, repo_url: str):
304305
if not self.versions:
305306
raise ChangelogError("No versions!")
306307

307-
def update_version(self, next_version: str):
308+
def update_version(self, next_version: str, date: datetime.date):
308309
"Move all unreleased changes under the new version."
309310
if not self.versions or self.versions[0].version != "Unreleased":
310311
logging.getLogger(__name__).warning(
@@ -315,9 +316,8 @@ def update_version(self, next_version: str):
315316
# Change the version and date of the unreleased section. For now
316317
# explicitly assume UTC, but that should probably be an input.
317318
self.versions[0].version = next_version
318-
self.versions[0].date = (
319-
datetime.datetime.now(datetime.timezone.utc).date().isoformat()
320-
)
319+
self.versions[0].date = date.isoformat()
320+
321321

322322
def render(self) -> str:
323323
"Render the CHANGELOG to markdown."

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ dynamic = ["version"]
66

77
keywords = ["changelog", "ci"]
88

9-
requires-python = ">=3.8"
9+
requires-python = ">=3.9"
1010

1111
dependencies = [
1212
"linkify-it-py>=2.0.3",
@@ -38,7 +38,7 @@ version-file = "bumpchanges/_version.py"
3838
legacy_tox_ini = """
3939
[tox]
4040
env_list =
41-
py3.8
41+
py3.9
4242
py3.12
4343
4444
[testenv]

0 commit comments

Comments
 (0)