Skip to content

Commit

Permalink
Assemble changelog only in PRs comments (#6783)
Browse files Browse the repository at this point in the history
(cherry picked from commit 671b157)
  • Loading branch information
SevaZhukov committed Jan 10, 2023
1 parent f6b0874 commit dc30f35
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
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
42 changes: 24 additions & 18 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 @@ -35,26 +38,29 @@ def get_changes(path):
'#### 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
'#### 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()

full_changelog = '<details>\n<summary>Changelog</summary>\n\n' + \
changelog + '</details>\n' + \
'<details>\n<summary>Android Auto Changelog</summary>\n\n' + \
auto_changelog + '</details>'

auto_old_changelog = open('libnavui-androidauto/changelog/unreleased/CHANGELOG.md', 'r').read()
comment_with_changelog_id = None
for comment in comments:
if comment['body'].startswith('<details>\n<summary>Changelog</summary>\n'):
comment_with_changelog_id = comment['id']

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()
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': full_changelog}, headers=headers)
else:
requests.post(pr_comments_url, json={'body': full_changelog}, headers=headers)

0 comments on commit dc30f35

Please sign in to comment.