Skip to content
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

Changelog Auto-Updater #422

Merged
merged 6 commits into from
Sep 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 7 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ on:
branches:
- "main"
- "[0-9]+.[0-9]+"
repository_dispatch:
types: rebuild

jobs:
build-html:
name: HTML
runs-on: ubuntu-latest
if: github.event_name == 'push'
if: github.event_name == 'push' || github.event_name == 'repository_dispatch'
steps:
- uses: actions/checkout@v2
with:
Expand Down Expand Up @@ -62,7 +64,7 @@ jobs:
- name: Install Python dependencies
run: pip install --upgrade -r requirements.txt
- name: Set up SSH Agent
if: github.event_name == 'push' && env.SSH_PRIVATE_KEY != null
if: (github.event_name == 'push' || github.event_name == 'repository_dispatch') && env.SSH_PRIVATE_KEY != null
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
SSH_PRIVATE_KEY: ${{ secrets.DOWNLOADS_HOSTGATOR_DOT_MIXXX_DOT_ORG_KEY }}
Expand All @@ -74,15 +76,15 @@ jobs:
ssh-keyscan "${SSH_HOST}" >> "${HOME}/.ssh/known_hosts"
echo "SSH_AUTH_SOCK=${SSH_AUTH_SOCK}" >> "${GITHUB_ENV}"
- name: Build PDF manual
if: github.event_name != 'push' || env.SSH_AUTH_SOCK == null
if: (github.event_name != 'push' || github.event_name != 'repository_dispatch') && env.SSH_AUTH_SOCK == null
run: |
sphinx-build -b latex -q -j $(nproc) -Dlatex_engine=xelatex source build
make -C build LATEXMKOPTS="-f -interaction=nonstopmode -pdf -xelatex" all-pdf
- name: Build PDF manual in all languages
if: github.event_name == 'push' && env.SSH_AUTH_SOCK != null
if: (github.event_name == 'push' || github.event_name == 'repository_dispatch') && env.SSH_AUTH_SOCK != null
run: sh build_pdf.sh
- name: Deploy PDF manuals to download server
if: github.event_name == 'push' && env.SSH_AUTH_SOCK != null
if: (github.event_name == 'push' || github.event_name == 'repository_dispatch') && env.SSH_AUTH_SOCK != null
run: rsync --verbose --recursive --checksum --times --delay-updates "build/pdf/" "${SSH_USER}@${SSH_HOST}:${DESTDIR}/"
env:
DESTDIR: public_html/downloads/manual
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/changelog.yml
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 }}
2 changes: 2 additions & 0 deletions requirements-changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
m2r2
requests
2 changes: 1 addition & 1 deletion source/chapters/appendix.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Appendix
appendix/commandline_dev_tools
appendix/mixxx_controls
appendix/additional_resources
appendix/version_history
appendix/changelog
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.. include:: /shortcuts.rstext

.. _appendix-version-history:
.. _appendix-changelog:

Version History
===============
Changelog
=========

2.3.0
-----
Expand Down
58 changes: 58 additions & 0 deletions tools/update_changelog.py
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()