Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
7 changes: 3 additions & 4 deletions .github/workflows/assemble_changelog.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
name: Assemble changelog
on:
push:
branches:
- main
- release-v**
pull_request:
types: [ opened, synchronize ]
jobs:
process:
permissions:
pull-requests: write
contents: write
runs-on: ubuntu-20.04
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
Expand Down
11 changes: 5 additions & 6 deletions changelog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ If you have implemented several features or bugfixes you should describe all of
You can choose any name for your changelog files because the GitHub action will rename files in
`changelog/unreleased/features` and `changelog/unreleased/bugfixes` directories to `${PR_NUMBER}.md` when you open a PR.

Every push to the main or release branch Assemble changelog GitHub action will be executed:

* collect all files from `changelog/unreleased`
* assemble the changelog like:
For every PR the script will generate and update a comment with a changelog for the current branch in the following format:

```
# Changelog
#### Features
- Feature 1 [#1234](https://github.com/mapbox/mapbox-navigation-android/pull/1234)
- Feature 2 [#2345](https://github.com/mapbox/mapbox-navigation-android/pull/2345)
Expand All @@ -47,11 +45,12 @@ Every push to the main or release branch Assemble changelog GitHub action will b
Some other changes
```

* write the changelog to the `changelog/unreleased/CHANGELOG.md` file
The comment will be updated with every change.
Also, a comment with a changelog will be generated and updated for the android auto project too.

Every release the release train app will:

* get changelog from `changelog/unreleased/CHANGELOG.md` file
* assemble the changelog
* add information about dependencies and compile changelog like:
```
## Mapbox Navigation SDK 1.1.1 - 13 December, 2022
Expand Down
49 changes: 29 additions & 20 deletions scripts/changelog/assemble_changelog.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import os

import git
import requests

pr_number = os.environ['PR_NUMBER']
token = os.environ['GITHUB_TOKEN']


def get_changes(path):
Expand Down Expand Up @@ -30,31 +33,37 @@ def get_changes(path):
issues = get_changes('changelog/unreleased/issues/')
other = get_changes('changelog/unreleased/other/')

changelog = '#### Features\n' + features + '\n\n' + \
changelog = '# Changelog\n' + \
'#### Features\n' + features + '\n\n' + \
'#### Bug fixes and improvements\n' + bugfixes + '\n\n' + \
'#### Known issues :warning:\n' + issues + '\n\n' + \
'#### Other changes\n' + other

old_changelog = open('changelog/unreleased/CHANGELOG.md', 'r').read()

if changelog != old_changelog:
open('changelog/unreleased/CHANGELOG.md', 'w').write(changelog)
repository = git.Repo('.')
repository.git.add('changelog/unreleased')
repository.index.commit('Assemble changelog file [skip ci]')
repository.remotes.origin.push().raise_if_error()

auto_bugfixes = get_changes('libnavui-androidauto/changelog/unreleased/bugfixes/')
auto_features = get_changes('libnavui-androidauto/changelog/unreleased/features/')

auto_changelog = '#### Features\n' + auto_features + '\n\n' + \
'#### Bug fixes and improvements\n' + auto_bugfixes
auto_changelog = '# Android Auto Changelog\n' + \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope of this PR and it's your file but I would try to generalize something here for the default changelog and the android auto one. So that it's easier to:

  1. Keep track of what changelogs are supported;
  2. Make changes in all places at once.

I see a list of objects describing the changelog file instead of having variable like a, b, c, ..., auto_a, auto_b, auto_c, ... . The objects would have different paths, changelog file names, maybe something else.
Just a refactoring idea.

'#### Features\n' + auto_features + '\n\n' + \
'#### Bug fixes and improvements\n' + auto_bugfixes

pr_comments_url = 'https://api.github.com/repos/mapbox/mapbox-navigation-android/issues/' + pr_number + '/comments'
headers = {"Authorization": "Bearer " + token}
comments = requests.get(pr_comments_url, headers=headers).json()


def update_comment(title, content):
comment_with_changelog_id = None
for comment in comments:
if comment['body'].startswith(title):
comment_with_changelog_id = comment['id']

if comment_with_changelog_id:
comments_url = 'https://api.github.com/repos/mapbox/mapbox-navigation-android/issues/comments/'
comment_url = comments_url + str(comment_with_changelog_id)
requests.patch(comment_url, json={'body': content}, headers=headers)
else:
requests.post(pr_comments_url, json={'body': content}, headers=headers)

auto_old_changelog = open('libnavui-androidauto/changelog/unreleased/CHANGELOG.md', 'r').read()

if auto_changelog != auto_old_changelog:
open('libnavui-androidauto/changelog/unreleased/CHANGELOG.md', 'w').write(auto_changelog)
repository = git.Repo('.')
repository.git.add('libnavui-androidauto/changelog/unreleased')
repository.index.commit('Assemble auto changelog file [skip ci]')
repository.remotes.origin.push().raise_if_error()
update_comment('# Changelog', changelog)
update_comment('# Android Auto Changelog', auto_changelog)