Skip to content

Commit

Permalink
Release workflow opens PR for changelog against master branch
Browse files Browse the repository at this point in the history
closes: #416
  • Loading branch information
dkliban committed Jun 21, 2021
1 parent 9516b33 commit 48beb08
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/416.feature
@@ -0,0 +1 @@
Release workflow opens PR against master with the latest changelog.
17 changes: 17 additions & 0 deletions templates/github/.github/workflows/release.yml.j2
Expand Up @@ -276,3 +276,20 @@ jobs:

- name: Create release on GitHub
run: bash .github/workflows/scripts/create_release_from_tag.sh {{ "${{ github.event.inputs.release }}" }}

- name: Stage changelog for master branch
run: python .github/workflows/scripts/stage-changelog-for-master.py {{ "${{ github.event.inputs.release }}" }}

- name: Create Pull Request for Changelog
uses: peter-evans/create-pull-request@v3
with:
committer: {{ 'pulpbot <pulp-infra@redhat.com>' }}
author: {{ 'pulpbot <pulp-infra@redhat.com>' }}
branch: {{ "${{ github.event.inputs.release }}" }}-changelog
base: master
title: 'Building changelog for {{ "${{ github.event.inputs.release }}" }}'
body: '[noissue]'
commit-message: |
Building changelog for {{ "${{ github.event.inputs.release }}" }}
[noissue]
delete-branch: true
@@ -0,0 +1,51 @@
{% include 'header.j2' %}

import argparse
import os
import textwrap

from git import Repo


helper = textwrap.dedent(
"""\
Stage the changelog for a release on master branch.

Example:
$ python .github/workflows/scripts/stage-changelog-for-master.py 3.4.0

"""
)

parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter, description=helper)

parser.add_argument(
"release_version",
type=str,
help="The version string for the release.",
)

args = parser.parse_args()

release_version_arg = args.release_version

release_path = os.path.dirname(os.path.abspath(__file__))
plugin_path = release_path.split("/.github")[0]

print(f"\n\nRepo path: {plugin_path}")
repo = Repo(plugin_path)

changelog_commit = None
# Look for a commit with the requested release version
for commit in repo.iter_commits():
if f"Building changelog for {release_version_arg}\n" in commit.message:
changelog_commit = commit
break

if not changelog_commit:
raise RuntimeError("Changelog commit for {release_version_arg} was not found.")

git = repo.git
git.checkout("origin/master")
git.cherry_pick(changelog_commit.hexsha)
git.reset("origin/master")

0 comments on commit 48beb08

Please sign in to comment.