概要
GitHub
でプロジェクトを管理、デプロイする場合、Release note
の機能を活用します。

しかし、GitHub
ではないところで、このRelease note
を活用することができないので、CHANGELOG.md
ファイルを作って別で管理する場合もあります。
今回のブログポストではGitHub Actions
のchangelog-updater Action
を使ってGitHub
のRelease note
に作成された内容を自動でCHANGELOG.md
ファイルをコピーする方法について説明します。
ブログシリーズ
このブログはシリーズで作成しております。下記のリンクを参考して他のブログポストも確認してみてください。
- [GitHub Actions] Pull requestのタイトル検査
- [GitHub Actions] Release Drafterを使ってGitHubのRelease noteの自動化をする
- [GitHub Actions] Pull requestのラベル検査
- [GitHub Actions] Changelogファイルの自動アップデート
changelog-updater Action
changelog-updater Action
はGitHub
の最後のRelease note
をCHANGELOG.md
ファイルにコピーしてくれるGitHub Actions
です。
changelog-updater Action
を使うため.github/workflows/update-changelog.yml
ファイルを作って次のように修正します。
name: Update Changelog
on:
release:
types:
- released
jobs:
update:
name: Update Changelog
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/[email protected]
with:
ref: $
- name: Update Changelog
uses: stefanzweifel/[email protected]
with:
latest-version: $
release-notes: $
- name: Commit updated Changelog
uses: stefanzweifel/[email protected]
with:
branch: $
commit_message: 'docs: Update changelog'
file_pattern: CHANGELOG.md
このように作成すると、Release note
がリリースされると、リリースされた内容をCHANGELOG.md
ファイルにコピーするようになります。もちろん、git
で管理するファイルを修正するのでcommit_message
を使ってcommit
をします。
CHANGELOG.mdファイル
changelog-update Action
を使ってCHANGELOG.md
ファイルをアップデートするためには、CHANGELOG.md
が存在しなければなりません。CHANGELOG.md
ファイルを作って下記のように修正します。
# Changelog
changelog-update Action
を使ってCHANGELOG.md
ファイルをアップデートするためには、CHANGELOG.md
ファイルが存在しなければならないし、一つ以上のheading
が存在しなければならないです。
このブログポストでは# Changelog
をつい書いました。
この後、Release note
がreleased
されると、CHANGELOG.md
ファイルが下記のようにアップデートされることが確認できます。

Release Drafter
GitHub
でRelease note
を自動化するためにはGitHub Actions
の中で1つであるRelease Drafter
を使えます。Release Drafter
を使う方法については下記のリンクを参考してください。
Release Drafter
と一緒に使う場合は注意点があります。詳しい内容は下記のリンクを参考してください。
私の場合は次のようにGit Tag
が追加された時、Release note
の内容をCHANGELOG.md
ファイルにコピーした後、Release note
をデプロイしてます。
name: Release
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
jobs:
release:
permissions:
contents: write
pull-requests: write
id-token: write
runs-on: ubuntu-latest
steps:
- name: Get semantic version
id: semver
run: echo "::set-output name=version::${GITHUB_REF#refs/tags/v}"
- uses: actions/[email protected]
with:
ref: v$
- uses: release-drafter/[email protected]
id: target_release_notes
with:
tag: $
name: $
version: $
env:
GITHUB_TOKEN: $
- name: Update Changelog
uses: stefanzweifel/[email protected]
with:
latest-version: $
release-notes: $
- name: Commit updated Changelog
uses: stefanzweifel/[email protected]
with:
commit_message: 'docs: Update changelog'
file_pattern: CHANGELOG.md
branch: main
- uses: dart-lang/[email protected]
- name: Install dependencies
run: dart pub get
- name: Update version
run: dart run bull pub_version --version=$
- name: Commit updated pubspec
uses: stefanzweifel/[email protected]
with:
commit_message: 'chore: Update version for release'
file_pattern: pubspec.yaml
branch: main
- name: Update Git tag
run: |
git tag $ -f
git push origin $ -f
- uses: release-drafter/[email protected]
with:
tag: $
name: $
version: $
publish: true
env:
GITHUB_TOKEN: $
- name: Publish
run: dart pub publish --force
このコードではFlutter
パッケージをデプロイするGitHub Actions
が含まれてます。なので、この部分が要らない場合、次のコードを自分の状況に合わせて修正して使えばいいと思います。
name: Release
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
jobs:
release:
permissions:
contents: write
pull-requests: write
id-token: write
runs-on: ubuntu-latest
steps:
- name: Get semantic version
id: semver
run: echo "::set-output name=version::${GITHUB_REF#refs/tags/v}"
- uses: actions/[email protected]
with:
ref: v$
- uses: release-drafter/[email protected]
id: target_release_notes
with:
tag: $
name: $
version: $
env:
GITHUB_TOKEN: $
- name: Update Changelog
uses: stefanzweifel/[email protected]
with:
latest-version: $
release-notes: $
- name: Commit updated Changelog
uses: stefanzweifel/[email protected]
with:
commit_message: 'docs: Update changelog'
file_pattern: CHANGELOG.md
branch: main
...
- name: Commit updated pubspec
uses: stefanzweifel/[email protected]
with:
commit_message: 'chore: Update version for release'
file_pattern: pubspec.yaml
branch: main
- name: Update Git tag
run: |
git tag $ -f
git push origin $ -f
- uses: release-drafter/[email protected]
with:
tag: $
name: $
version: $
publish: true
env:
GITHUB_TOKEN: $
...
もし、Flutter
パッケージを作成してデプロイする方法について知りたい方は下記のリンクを参考してください。
完了
これでGitHub Actions
のchangelog-updater Action
を使ってGitHub
のRelease note
に作成された内容をCHANGELOG.md
ファイルに自動でコピーする方法について見てみました。GitHub
のRelease note
も使ってCHANGELOG.md
ファイルも使う場合は、changelog-updater Action
を使って自動化してみてください。
私のブログが役に立ちましたか?下にコメントを残してください。それは私にとって大きな大きな力になります!
アプリ広報
Deku
が開発したアプリを使ってみてください。Deku
が開発したアプリはFlutterで開発されています。興味がある方はアプリをダウンロードしてアプリを使ってくれると本当に助かります。