Skip to content

Fine Tune chango and Release Workflows #4758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Apr 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
575828c
try fixing github release & channel post
Bibo-Joshi Apr 14, 2025
f8dde47
override ChanGo.release to replace NEXT.VERSION
Bibo-Joshi Apr 14, 2025
3345e7c
Add chango fragment for PR #4758
Bibo-Joshi Apr 14, 2025
90cbf44
Simplify release workflow description
Bibo-Joshi Apr 14, 2025
6a68b6a
Have a go at auto-running `chango release` - first test commit that i…
Bibo-Joshi Apr 19, 2025
4e398f1
Add chango fragment for PR #4758
Bibo-Joshi Apr 19, 2025
86c3da8
Merge branch 'master' into release-fine-tune
Bibo-Joshi Apr 19, 2025
d083577
Minor tweaks - mostly next test commit that's expected to do a release
Bibo-Joshi Apr 19, 2025
aecf8f0
add some debug logging
Bibo-Joshi Apr 19, 2025
acec93b
different debug logging
Bibo-Joshi Apr 19, 2025
7970b6c
try different case-insensitivity handling
Bibo-Joshi Apr 19, 2025
e8f0b98
Try using a different var name
Bibo-Joshi Apr 19, 2025
166bc91
try again
Bibo-Joshi Apr 19, 2025
8cd8640
skip the v
Bibo-Joshi Apr 19, 2025
509821b
Add some debug prints
Bibo-Joshi Apr 19, 2025
5556889
try something else
Bibo-Joshi Apr 19, 2025
1077665
Do chango Release
Bibo-Joshi Apr 19, 2025
ace5449
Revert "Do chango Release"
Bibo-Joshi Apr 19, 2025
604b713
another fix-try
Bibo-Joshi Apr 19, 2025
195ed2b
aaaand again
Bibo-Joshi Apr 19, 2025
44c115a
Do chango Release
Bibo-Joshi Apr 19, 2025
85c6207
Revert "Do chango Release"
Bibo-Joshi Apr 19, 2025
5c64ae3
Remove debug logging
Bibo-Joshi Apr 19, 2025
83b0e7e
Add chango fragment for PR #4758
Bibo-Joshi Apr 19, 2025
540090f
typo
Bibo-Joshi Apr 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/chango.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Chango
on:
pull_request:
types:
- opened
- reopened
- synchronize

permissions: {}

jobs:
create-chango-fragment:
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write
name: Create chango Fragment
runs-on: ubuntu-latest
outputs:
IS_RELEASE_PR: ${{ steps.check_title.outputs.IS_RELEASE_PR }}

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
# needed for commit and push step at the end
persist-credentials: true
- name: Check PR Title
id: check_title
run: | # zizmor: ignore[template-injection]
if [[ "$(echo "${{ github.event.pull_request.title }}" | tr '[:upper:]' '[:lower:]')" =~ ^bump\ version\ to\ .* ]]; then
echo "COMMIT_AND_PUSH=false" >> $GITHUB_OUTPUT
echo "IS_RELEASE_PR=true" >> $GITHUB_OUTPUT
else
echo "COMMIT_AND_PUSH=true" >> $GITHUB_OUTPUT
echo "IS_RELEASE_PR=false" >> $GITHUB_OUTPUT
fi

# Create the new fragment
- uses: Bibo-Joshi/chango@9d6bd9d7612eca5fab2c5161687011be59baaf19 # v0.4.0
with:
github-token: ${{ secrets.CHANGO_PAT }}
query-issue-types: true
commit-and-push: ${{ steps.check_title.outputs.COMMIT_AND_PUSH }}

# Run `chango release` if applicable - needs some additional setup.
- name: Set up Python
if: steps.check_title.outputs.IS_RELEASE_PR == 'true'
uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5.5.0
with:
python-version: "3.x"

- name: Do Release
if: steps.check_title.outputs.IS_RELEASE_PR == 'true'
run: |
cd ./target-repo
git add changes/unreleased/*
pip install . -r docs/requirements-docs.txt
VERSION_TAG=$(python -c "from telegram import __version__; print(f'{__version__}')")
chango release --uid $VERSION_TAG

- name: Commit & Push
if: steps.check_title.outputs.IS_RELEASE_PR == 'true'
uses: stefanzweifel/git-auto-commit-action@e348103e9026cc0eee72ae06630dbe30c8bf7a79 # v5.1.0
with:
commit_message: "Do chango Release"
repository: ./target-repo
30 changes: 0 additions & 30 deletions .github/workflows/chango_fragment.yml

This file was deleted.

6 changes: 6 additions & 0 deletions .github/workflows/release_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ jobs:
actions: read # for downloading artifacts

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- name: Download all the dists
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
with:
Expand Down Expand Up @@ -150,6 +153,9 @@ jobs:
permissions: {}

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- name: Publish to Telegram Channel
env:
TAG: ${{ needs.build.outputs.TAG }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/release_test_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ jobs:
actions: read # for downloading artifacts

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- name: Download all the dists
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
with:
Expand Down
29 changes: 28 additions & 1 deletion changes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
# pylint: disable=import-error
"""Configuration for the chango changelog tool"""

import re
from collections.abc import Collection
from pathlib import Path
from typing import Optional

from chango import Version
from chango.concrete import DirectoryChanGo, DirectoryVersionScanner, HeaderVersionHistory
from chango.concrete.sections import GitHubSectionChangeNote, Section, SectionVersionNote

Expand Down Expand Up @@ -70,7 +73,31 @@ def get_sections(
return found or {"other"}


chango_instance = DirectoryChanGo(
class CustomChango(DirectoryChanGo):
"""Custom ChanGo class for overriding release"""

def release(self, version: Version) -> bool:
"""replace "14.5" with version.uid except in the contrib guide
then call super
"""
root = Path(__file__).parent.parent / "telegram"
python_files = root.rglob("*.py")
pattern = re.compile(r"NEXT\.VERSION")
excluded_paths = {root / "docs/source/contribute.rst"}
for file_path in python_files:
if str(file_path) in excluded_paths:
continue

content = file_path.read_text(encoding="utf-8")
modified = pattern.sub(version.uid, content)

if content != modified:
file_path.write_text(modified, encoding="utf-8")

return super().release(version)


chango_instance = CustomChango(
change_note_type=ChangoSectionChangeNote,
version_note_type=SectionVersionNote,
version_history_type=HeaderVersionHistory,
Expand Down
5 changes: 5 additions & 0 deletions changes/unreleased/4758.dSyCdBJWEJroH2GynR2VaJ.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
internal = "Fine Tune ``chango`` and Release Workflows"
[[pull_requests]]
uid = "4758"
author_uid = "Bibo-Joshi"
closes_threads = ["4720"]