Skip to content

Commit 3cd8d3e

Browse files
committed
[changelog] Add Keep a Changelog automation (#28)
1 parent bb8eb14 commit 3cd8d3e

44 files changed

Lines changed: 2507 additions & 33 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Bootstrap Changelog Automation
2+
3+
on:
4+
workflow_call:
5+
workflow_dispatch:
6+
push:
7+
branches: ["main"]
8+
9+
permissions:
10+
contents: write
11+
12+
concurrency:
13+
group: changelog-bootstrap-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
changelog-bootstrap:
18+
name: Bootstrap Changelog Assets
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v6
24+
with:
25+
token: ${{ github.token }}
26+
fetch-depth: 0
27+
28+
- name: Cache Composer dependencies
29+
uses: actions/cache@v5
30+
with:
31+
path: /tmp/composer-cache
32+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
33+
restore-keys: |
34+
${{ runner.os }}-composer-
35+
36+
- name: Install dependencies
37+
uses: php-actions/composer@v6
38+
env:
39+
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ github.token }}"} }'
40+
COMPOSER_CACHE_DIR: /tmp/composer-cache
41+
with:
42+
php_version: '8.3'
43+
command: 'install'
44+
args: '--prefer-dist --no-progress --no-interaction --no-scripts'
45+
46+
- name: Bootstrap changelog assets
47+
run: vendor/bin/dev-tools changelog:init
48+
49+
- name: Commit changelog assets
50+
uses: EndBug/add-and-commit@v10
51+
with:
52+
add: CHANGELOG.md .keep-a-changelog.ini
53+
message: "Bootstrap changelog automation"
54+
default_author: github_actions
55+
pull: "--rebase --autostash"
56+
push: true

.github/workflows/release.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Sync Release Notes from CHANGELOG
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
tag-name:
7+
type: string
8+
required: false
9+
release:
10+
types: [published]
11+
12+
permissions:
13+
contents: write
14+
15+
jobs:
16+
release-notes:
17+
name: Promote CHANGELOG and Sync Release Notes
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout main branch
22+
uses: actions/checkout@v6
23+
with:
24+
ref: main
25+
token: ${{ github.token }}
26+
fetch-depth: 0
27+
28+
- name: Cache Composer dependencies
29+
uses: actions/cache@v5
30+
with:
31+
path: /tmp/composer-cache
32+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
33+
restore-keys: |
34+
${{ runner.os }}-composer-
35+
36+
- name: Install dependencies
37+
uses: php-actions/composer@v6
38+
env:
39+
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ github.token }}"} }'
40+
COMPOSER_CACHE_DIR: /tmp/composer-cache
41+
with:
42+
php_version: '8.3'
43+
command: 'install'
44+
args: '--prefer-dist --no-progress --no-interaction --no-scripts'
45+
46+
- name: Resolve release metadata
47+
id: release
48+
run: |
49+
TAG="${INPUT_TAG_NAME:-${EVENT_TAG_NAME:-${GITHUB_REF_NAME}}}"
50+
VERSION="${TAG#v}"
51+
DATE_VALUE="${EVENT_PUBLISHED_AT%%T*}"
52+
53+
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
54+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
55+
echo "date=${DATE_VALUE:-$(date +%F)}" >> "$GITHUB_OUTPUT"
56+
env:
57+
INPUT_TAG_NAME: ${{ inputs.tag-name }}
58+
EVENT_TAG_NAME: ${{ github.event.release.tag_name }}
59+
EVENT_PUBLISHED_AT: ${{ github.event.release.published_at }}
60+
61+
- name: Promote unreleased changelog entry
62+
run: |
63+
VERSION="${{ steps.release.outputs.version }}"
64+
DATE_VALUE="${{ steps.release.outputs.date }}"
65+
66+
if grep -q "^## ${VERSION} - " CHANGELOG.md; then
67+
echo "Release ${VERSION} already exists in CHANGELOG.md."
68+
elif grep -q "^## Unreleased - " CHANGELOG.md; then
69+
vendor/bin/keep-a-changelog unreleased:promote "${VERSION}" --date="${DATE_VALUE}" --no-interaction
70+
else
71+
echo "No Unreleased section found; skipping promotion."
72+
fi
73+
74+
- name: Ensure the next Unreleased section exists
75+
run: |
76+
if ! grep -q "^## Unreleased - " CHANGELOG.md; then
77+
vendor/bin/keep-a-changelog unreleased:create --no-interaction
78+
fi
79+
80+
- name: Commit CHANGELOG updates
81+
uses: EndBug/add-and-commit@v10
82+
with:
83+
add: CHANGELOG.md
84+
message: "Sync changelog for ${{ steps.release.outputs.tag }}"
85+
default_author: github_actions
86+
pull: "--rebase --autostash"
87+
push: true
88+
89+
- name: Export release notes from CHANGELOG
90+
run: vendor/bin/keep-a-changelog version:show "${{ steps.release.outputs.version }}" > release-notes.md
91+
92+
- name: Update GitHub release notes
93+
run: gh release edit "${TAG}" --notes-file release-notes.md
94+
env:
95+
GH_TOKEN: ${{ github.token }}
96+
TAG: ${{ steps.release.outputs.tag }}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Require Changelog Entry
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
base-ref:
7+
type: string
8+
required: false
9+
default: main
10+
pull_request:
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
require-changelog:
17+
name: Require Changelog Update
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v6
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Cache Composer dependencies
27+
uses: actions/cache@v5
28+
with:
29+
path: /tmp/composer-cache
30+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
31+
restore-keys: |
32+
${{ runner.os }}-composer-
33+
34+
- name: Install dependencies
35+
uses: php-actions/composer@v6
36+
env:
37+
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ github.token }}"} }'
38+
COMPOSER_CACHE_DIR: /tmp/composer-cache
39+
with:
40+
php_version: '8.3'
41+
command: 'install'
42+
args: '--prefer-dist --no-progress --no-interaction --no-scripts'
43+
44+
- name: Resolve base reference
45+
id: base_ref
46+
run: echo "value=${INPUT_BASE_REF:-${GITHUB_BASE_REF:-main}}" >> "$GITHUB_OUTPUT"
47+
env:
48+
INPUT_BASE_REF: ${{ inputs.base-ref }}
49+
50+
- name: Fetch base reference
51+
run: git fetch origin "${BASE_REF}" --depth=1
52+
env:
53+
BASE_REF: ${{ steps.base_ref.outputs.value }}
54+
55+
- name: Verify unreleased changelog entries
56+
run: vendor/bin/dev-tools changelog:check --against="refs/remotes/origin/${BASE_REF}"
57+
env:
58+
BASE_REF: ${{ steps.base_ref.outputs.value }}

.keep-a-changelog.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[defaults]
2+
changelog_file = CHANGELOG.md
3+
provider = github
4+
remote = origin
5+
6+
[providers]
7+
github[class] = Phly\KeepAChangelog\Provider\GitHub

0 commit comments

Comments
 (0)