From bea0230dd494bd054edcfd7987dd32affc418152 Mon Sep 17 00:00:00 2001 From: "sevastian.zhukov" Date: Thu, 5 Jan 2023 17:05:25 +0700 Subject: [PATCH 1/6] Assemble changelog only by the script executing --- .github/workflows/assemble_changelog.yml | 31 --------------- changelog/README.md | 10 ++--- scripts/changelog/assemble_changelog.py | 50 ++++++++++-------------- 3 files changed, 24 insertions(+), 67 deletions(-) delete mode 100644 .github/workflows/assemble_changelog.yml diff --git a/.github/workflows/assemble_changelog.yml b/.github/workflows/assemble_changelog.yml deleted file mode 100644 index 352de2221b9..00000000000 --- a/.github/workflows/assemble_changelog.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Assemble changelog -on: - push: - branches: - - main - - release-v** -jobs: - process: - permissions: - pull-requests: write - contents: write - runs-on: ubuntu-20.04 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - steps: - - uses: actions/checkout@v3 - with: - ref: ${{github.head_ref}} - - - name: setup python - uses: actions/setup-python@v4 - with: - python-version: '3.7.7' - - - name: install python packages - run: | - python3 -m pip install requests GitPython - - - name: execute py script - run: | - python3 scripts/changelog/assemble_changelog.py diff --git a/changelog/README.md b/changelog/README.md index 1b621760894..fd0952cf56b 100644 --- a/changelog/README.md +++ b/changelog/README.md @@ -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 @@ -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 diff --git a/scripts/changelog/assemble_changelog.py b/scripts/changelog/assemble_changelog.py index 587c1014050..bdef7a9a3e1 100644 --- a/scripts/changelog/assemble_changelog.py +++ b/scripts/changelog/assemble_changelog.py @@ -1,7 +1,6 @@ +import argparse import os -import git - def get_changes(path): changes = '' @@ -25,36 +24,27 @@ def get_changes(path): return changes.strip() -bugfixes = get_changes('changelog/unreleased/bugfixes/') -features = get_changes('changelog/unreleased/features/') -issues = get_changes('changelog/unreleased/issues/') -other = get_changes('changelog/unreleased/other/') - -changelog = '#### 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() +parser = argparse.ArgumentParser(description='Assemble changelog') +parser.add_argument('--auto', action='store_true', help='To assemble android auto changelog') +args = parser.parse_args() -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() +if args.auto: + auto_bugfixes = get_changes('libnavui-androidauto/changelog/unreleased/bugfixes/') + auto_features = get_changes('libnavui-androidauto/changelog/unreleased/features/') -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 = '#### Features\n' + auto_features + '\n\n' + \ - '#### Bug fixes and improvements\n' + auto_bugfixes + print(auto_changelog) +else: + bugfixes = get_changes('changelog/unreleased/bugfixes/') + features = get_changes('changelog/unreleased/features/') + issues = get_changes('changelog/unreleased/issues/') + other = get_changes('changelog/unreleased/other/') -auto_old_changelog = open('libnavui-androidauto/changelog/unreleased/CHANGELOG.md', 'r').read() + changelog = '#### Features\n' + features + '\n\n' + \ + '#### Bug fixes and improvements\n' + bugfixes + '\n\n' + \ + '#### Known issues :warning:\n' + issues + '\n\n' + \ + '#### Other changes\n' + other -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() + print(changelog) From 63ef9692dc171cfe1982ee085409eb09dc33e5dd Mon Sep 17 00:00:00 2001 From: "sevastian.zhukov" Date: Thu, 5 Jan 2023 21:53:13 +0700 Subject: [PATCH 2/6] create and update changelog in pr comment --- .github/workflows/assemble_changelog.yml | 30 ++++++++++++ scripts/changelog/assemble_changelog.py | 59 ++++++++++++++++-------- 2 files changed, 69 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/assemble_changelog.yml diff --git a/.github/workflows/assemble_changelog.yml b/.github/workflows/assemble_changelog.yml new file mode 100644 index 00000000000..8d94b800c54 --- /dev/null +++ b/.github/workflows/assemble_changelog.yml @@ -0,0 +1,30 @@ +name: Assemble changelog +on: + 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 + with: + ref: ${{github.head_ref}} + + - name: setup python + uses: actions/setup-python@v4 + with: + python-version: '3.7.7' + + - name: install python packages + run: | + python3 -m pip install requests GitPython + + - name: execute py script + run: | + python3 scripts/changelog/assemble_changelog.py diff --git a/scripts/changelog/assemble_changelog.py b/scripts/changelog/assemble_changelog.py index bdef7a9a3e1..794d8fe10c7 100644 --- a/scripts/changelog/assemble_changelog.py +++ b/scripts/changelog/assemble_changelog.py @@ -1,6 +1,10 @@ -import argparse import os +import requests + +pr_number = os.environ['PR_NUMBER'] +token = os.environ['GITHUB_TOKEN'] + def get_changes(path): changes = '' @@ -24,27 +28,42 @@ def get_changes(path): return changes.strip() -parser = argparse.ArgumentParser(description='Assemble changelog') -parser.add_argument('--auto', action='store_true', help='To assemble android auto changelog') -args = parser.parse_args() +bugfixes = get_changes('changelog/unreleased/bugfixes/') +features = get_changes('changelog/unreleased/features/') +issues = get_changes('changelog/unreleased/issues/') +other = get_changes('changelog/unreleased/other/') + +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 + +auto_bugfixes = get_changes('libnavui-androidauto/changelog/unreleased/bugfixes/') +auto_features = get_changes('libnavui-androidauto/changelog/unreleased/features/') + +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() -if args.auto: - 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 +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'] - print(auto_changelog) -else: - bugfixes = get_changes('changelog/unreleased/bugfixes/') - features = get_changes('changelog/unreleased/features/') - issues = get_changes('changelog/unreleased/issues/') - other = get_changes('changelog/unreleased/other/') + 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) - changelog = '#### Features\n' + features + '\n\n' + \ - '#### Bug fixes and improvements\n' + bugfixes + '\n\n' + \ - '#### Known issues :warning:\n' + issues + '\n\n' + \ - '#### Other changes\n' + other - print(changelog) +update_comment('# Changelog', changelog) +update_comment('# Android Auto Changelog', auto_changelog) From 978f125dcb9c2cceded128c7bd2ac0646443ebfe Mon Sep 17 00:00:00 2001 From: "sevastian.zhukov" Date: Thu, 5 Jan 2023 22:22:26 +0700 Subject: [PATCH 3/6] update readme --- changelog/README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/changelog/README.md b/changelog/README.md index fd0952cf56b..969f30a8eb9 100644 --- a/changelog/README.md +++ b/changelog/README.md @@ -26,10 +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. -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: +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) @@ -45,11 +45,12 @@ This script will collect all the files in the `changelog/unreleased` directory a Some other changes ``` -To view the changelog for the android auto project, run the command `python3 scripts/changelog/assemble_changelog.py --auto`. +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: -* assemble the changelog by the script `python3 scripts/changelog/assemble_changelog.py` +* assemble the changelog * add information about dependencies and compile changelog like: ``` ## Mapbox Navigation SDK 1.1.1 - 13 December, 2022 From aa6f7e81045cd0980985d0db1a7085bd6ea562d8 Mon Sep 17 00:00:00 2001 From: "sevastian.zhukov" Date: Thu, 5 Jan 2023 22:33:25 +0700 Subject: [PATCH 4/6] simple run script --- .github/workflows/assemble_changelog.yml | 2 +- scripts/changelog/assemble_changelog.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/assemble_changelog.yml b/.github/workflows/assemble_changelog.yml index 8d94b800c54..9debb8cb50d 100644 --- a/.github/workflows/assemble_changelog.yml +++ b/.github/workflows/assemble_changelog.yml @@ -27,4 +27,4 @@ jobs: - name: execute py script run: | - python3 scripts/changelog/assemble_changelog.py + ./scripts/changelog/assemble_changelog.py diff --git a/scripts/changelog/assemble_changelog.py b/scripts/changelog/assemble_changelog.py index 794d8fe10c7..9957778cad8 100644 --- a/scripts/changelog/assemble_changelog.py +++ b/scripts/changelog/assemble_changelog.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + import os import requests From 328208705ab22b91933be20cee4da465240b93bb Mon Sep 17 00:00:00 2001 From: "sevastian.zhukov" Date: Thu, 5 Jan 2023 22:34:36 +0700 Subject: [PATCH 5/6] Revert "simple run script" This reverts commit aa6f7e81045cd0980985d0db1a7085bd6ea562d8. --- .github/workflows/assemble_changelog.yml | 2 +- scripts/changelog/assemble_changelog.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/assemble_changelog.yml b/.github/workflows/assemble_changelog.yml index 9debb8cb50d..8d94b800c54 100644 --- a/.github/workflows/assemble_changelog.yml +++ b/.github/workflows/assemble_changelog.yml @@ -27,4 +27,4 @@ jobs: - name: execute py script run: | - ./scripts/changelog/assemble_changelog.py + python3 scripts/changelog/assemble_changelog.py diff --git a/scripts/changelog/assemble_changelog.py b/scripts/changelog/assemble_changelog.py index 9957778cad8..794d8fe10c7 100644 --- a/scripts/changelog/assemble_changelog.py +++ b/scripts/changelog/assemble_changelog.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python3 - import os import requests From aef3ed128ff0517b592565e28d656610d5181048 Mon Sep 17 00:00:00 2001 From: "sevastian.zhukov" Date: Fri, 6 Jan 2023 17:33:36 +0700 Subject: [PATCH 6/6] collapsable changelog comment --- scripts/changelog/assemble_changelog.py | 35 +++++++++++-------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/scripts/changelog/assemble_changelog.py b/scripts/changelog/assemble_changelog.py index 794d8fe10c7..d99c8ca904f 100644 --- a/scripts/changelog/assemble_changelog.py +++ b/scripts/changelog/assemble_changelog.py @@ -33,8 +33,7 @@ def get_changes(path): issues = get_changes('changelog/unreleased/issues/') other = get_changes('changelog/unreleased/other/') -changelog = '# Changelog\n' + \ - '#### Features\n' + features + '\n\n' + \ +changelog = '#### Features\n' + features + '\n\n' + \ '#### Bug fixes and improvements\n' + bugfixes + '\n\n' + \ '#### Known issues :warning:\n' + issues + '\n\n' + \ '#### Other changes\n' + other @@ -42,28 +41,26 @@ def get_changes(path): auto_bugfixes = get_changes('libnavui-androidauto/changelog/unreleased/bugfixes/') auto_features = get_changes('libnavui-androidauto/changelog/unreleased/features/') -auto_changelog = '# Android Auto Changelog\n' + \ - '#### Features\n' + auto_features + '\n\n' + \ +auto_changelog = '#### 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() +full_changelog = '
\nChangelog\n\n' + \ + changelog + '
\n' + \ + '
\nAndroid Auto Changelog\n\n' + \ + auto_changelog + '
' -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'] +comment_with_changelog_id = None +for comment in comments: + if comment['body'].startswith('
\nChangelog\n'): + 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) - - -update_comment('# Changelog', changelog) -update_comment('# Android Auto Changelog', auto_changelog) +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)