Skip to content
Closed
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
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
10 changes: 4 additions & 6 deletions changelog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ 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:
To view the changelog for the current branch, run the command `python3 scripts/changelog/assemble_changelog.py`.
This script will collect all the files in the `changelog/unreleased` directory and generate a changelog in the following format:

```
#### Features
Expand All @@ -47,11 +45,11 @@ 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
To view the changelog for the android auto project, run the command `python3 scripts/changelog/assemble_changelog.py --auto`.

Every release the release train app will:

* get changelog from `changelog/unreleased/CHANGELOG.md` file
* assemble the changelog by the script `python3 scripts/changelog/assemble_changelog.py`
* 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' + \
'#### 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)