-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #422 from Holzhaus/changelog-updater
Changelog Auto-Updater
- Loading branch information
Showing
6 changed files
with
126 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: Changelog | ||
|
||
on: | ||
repository_dispatch: | ||
types: update-changelog | ||
|
||
jobs: | ||
update-changelog: | ||
name: Update Changelog | ||
# This job fetches the `CHANGELOG.md` from the corresponding branch in the | ||
# mixxxdj/mixxx repository and uses it to update the `version_history.rst` | ||
# file. If the file was changed, the change is committed and a | ||
# rebuild/redeployment of the manual is triggered. | ||
# | ||
# This job is not run on changes to the manual repo. Instead, it's | ||
# triggered by a repository dispatch hook that gets triggered by a | ||
# corresponding workflow in the mixxxdj/mixxx repository whenever the | ||
# CHANGELOG.md is changed. | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Event Information | ||
run: echo "Event '${{ github.event.action }}' received from '${{ github.event.client_payload.repository }}'" | ||
- name: Check out repository | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.event.client_payload.branch }} | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.9 | ||
- name: Install Python dependencies | ||
run: pip install -r requirements-changelog.txt | ||
- name: Update Changelog | ||
run: tools/update_changelog.py -b "${{ github.event.client_payload.branch }}" | ||
- name: Check if changes any changes were made | ||
run: echo "GIT_DIRTY=$(git diff --quiet ; printf "%d" "$?")" >> "${GITHUB_ENV}" | ||
- uses: EndBug/add-and-commit@v7 | ||
if: env.GIT_DIRTY != null && env.GIT_DIRTY != '0' | ||
with: | ||
branch: ${{ github.event.client_payload.branch }} | ||
add: "source/chapters/appendix/version_history.rst" | ||
message: "appendix/version_history: Update changelog for ${{ github.event.client_payload.branch }} branch" | ||
author_name: mixxxbot | ||
author_email: bot@mixxx.org | ||
push: true | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Trigger Rebuild | ||
uses: peter-evans/repository-dispatch@v1 | ||
if: env.GIT_DIRTY != null && env.GIT_DIRTY != '0' && env.MIXXXBOT_TOKEN != null | ||
with: | ||
token: ${{ env.MIXXXBOT_TOKEN }} | ||
event-type: rebuild | ||
env: | ||
MIXXXBOT_TOKEN: ${{ secrets.MIXXXBOT_CHANGELOG_AUTOUPDATER_PAT }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
m2r2 | ||
requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
source/chapters/appendix/version_history.rst → source/chapters/appendix/changelog.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env python3 | ||
import argparse | ||
import os | ||
|
||
import m2r2 | ||
import requests | ||
|
||
|
||
TEMPLATE = """ | ||
.. This is a generated file. Do not edit it manually, because it is updated | ||
automatically via tools/update_changelog.py. | ||
.. include:: /shortcuts.rstext | ||
.. _appendix-changelog: | ||
{content} | ||
.. seealso:: For an overview of previous versions, `take a look | ||
<https://launchpad.net/mixxx/+series>`_ at the timeline. | ||
""" | ||
|
||
|
||
def fetch_changelog(branch): | ||
""" Fetch CHANGELOG.md from branch of mixxxdj/mixxx repository. """ | ||
r = requests.get( | ||
"https://raw.githubusercontent.com/mixxxdj/mixxx/" | ||
f"{branch}/CHANGELOG.md" | ||
) | ||
r.raise_for_status() | ||
return r.text | ||
|
||
|
||
def changelog_to_rst(changelog): | ||
""" Convert changelog to RST format used by sphinx. """ | ||
return TEMPLATE.lstrip().format(content=m2r2.convert(changelog)) | ||
|
||
|
||
def main(argv=None): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-b", "--branch", required=True) | ||
args = parser.parse_args(argv) | ||
|
||
# Fetch changelog and convert to RST | ||
changelog = fetch_changelog(args.branch) | ||
changelog = changelog_to_rst(changelog) | ||
|
||
# Write changelog to changelog.rst file | ||
path = os.path.join( | ||
os.path.dirname(os.path.abspath(__file__)), | ||
"../source/chapters/appendix/changelog.rst", | ||
) | ||
with open(path, mode="w") as fp: | ||
fp.write(changelog) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |