Skip to content

Commit 562ee06

Browse files
committed
add actions to check for changelogs (changie)
1 parent cef066f commit 562ee06

File tree

2 files changed

+164
-0
lines changed

2 files changed

+164
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
name: "create changelog"
3+
4+
on:
5+
issue_comment:
6+
types: [created]
7+
8+
permissions:
9+
pull-requests: write
10+
contents: write
11+
packages: write
12+
13+
jobs:
14+
create-changelog:
15+
runs-on: ubuntu-latest
16+
if: ${{ startsWith(github.event.comment.body, '/changie') && github.event.issue.pull_request }}
17+
steps:
18+
- name: Like comment
19+
uses: actions/github-script@v7
20+
with:
21+
script: |
22+
const {owner, repo} = context.issue
23+
github.rest.reactions.createForIssueComment({
24+
owner,
25+
repo,
26+
comment_id: context.payload.comment.id,
27+
content: "+1",
28+
});
29+
30+
- uses: actions/github-script@v7
31+
id: get-pr
32+
with:
33+
script: |
34+
const request = {
35+
owner: context.repo.owner,
36+
repo: context.repo.repo,
37+
pull_number: context.issue.number
38+
}
39+
core.info(`Getting PR #${request.pull_number} from ${request.owner}/${request.repo}`)
40+
try {
41+
const result = await github.rest.pulls.get(request)
42+
return result.data
43+
} catch (err) {
44+
core.setFailed(`Request failed with error ${err}`)
45+
}
46+
47+
- name: Setup outputs
48+
id: setup
49+
run: |
50+
KIND=$(echo $COMMENT | cut -d " " -f2)
51+
BODY=$(echo $COMMENT | cut -d " " -f3-)
52+
echo "Creating change of kind: $KIND and body: $BODY"
53+
echo "kind=$KIND" >> $GITHUB_OUTPUT
54+
echo "body=$BODY" >> $GITHUB_OUTPUT
55+
env:
56+
COMMENT: ${{ github.event.comment.body }}
57+
58+
- uses: actions/checkout@v4
59+
with:
60+
persist-credentials: false
61+
fetch-depth: 0
62+
ref: ${{ fromJSON(steps.get-pr.outputs.result).head.ref }}
63+
64+
- name: Configure git repository
65+
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
66+
67+
- name: New changie changes
68+
uses: miniscruff/[email protected]
69+
with:
70+
version: latest
71+
args: >
72+
new
73+
--kind="${{env.KIND}}"
74+
--body="${{env.BODY}}"
75+
--custom Issue="${{env.ISSUE}}"
76+
env:
77+
KIND: ${{ steps.setup.outputs.kind }}
78+
BODY: ${{ steps.setup.outputs.body }}
79+
ISSUE: ${{ github.event.issue.number }}
80+
81+
- name: Commit changes
82+
run: |
83+
git config --local user.email "${{ github.actor }}@users.noreply.github.com"
84+
git config --local user.name "${{ github.actor }}"
85+
git add .changes/unreleased
86+
git commit -m '${{ steps.setup.outputs.body }}'
87+
- uses: actions/create-github-app-token@v2
88+
id: app-token
89+
with:
90+
app-id: ${{ vars.ACTIONS_APP_ID }}
91+
private-key: ${{ secrets.ACTIONS_APP_PRIVATE_KEY }}
92+
owner: ${{ github.repository_owner }}
93+
- name: Push changes
94+
uses: ad-m/[email protected]
95+
with:
96+
github_token: ${{ steps.app-token.outputs.token }}
97+
branch: ${{ fromJSON(steps.get-pr.outputs.result).head.ref }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
name: "check changelog"
3+
4+
on:
5+
pull_request:
6+
types:
7+
# On by default if you specify no types.
8+
- "opened"
9+
- "reopened"
10+
- "synchronize"
11+
# For `skip-label` only.
12+
- "labeled"
13+
- "unlabeled"
14+
env:
15+
PR_COMMENT: |-
16+
# Missing a changelog file.
17+
18+
To create a new changelog file, write a comment in the PR
19+
using the `/changie` command: `/changie <kind> <change description>`
20+
21+
Supported kind are:
22+
23+
* Added
24+
* Changed
25+
* Deprecated
26+
* Removed
27+
* Fixed
28+
* Security
29+
* Enhanced
30+
31+
Examples:
32+
33+
* `/changie Added new FAQ question`
34+
* `/changie Fixed typo in a blog post`
35+
* `/changie Removed outdated section`
36+
* `/changie Changed website layout`
37+
38+
> Note: If no changelog is needed on this PR, label it with
39+
`skip changelog` to bypass this check.
40+
41+
jobs:
42+
check-changelog:
43+
runs-on: ubuntu-latest
44+
if: "!contains(github.event.pull_request.labels.*.name, 'skip changelog')"
45+
steps:
46+
- name: "Clone repository"
47+
uses: actions/checkout@v4
48+
with:
49+
lfs: true
50+
fetch-depth: 0
51+
- name: Get changed files in the docs folder
52+
id: changelogs
53+
uses: tj-actions/changed-files@v46
54+
with:
55+
files: |
56+
.changes/unreleased/**.yaml
57+
CHANGELOG.md
58+
59+
- name: Missing Changelog PR notification
60+
if: "steps.changelogs.outputs.any_changed == 'false'"
61+
uses: actions-cool/maintain-one-comment@v3
62+
with:
63+
body: ${{ env.PR_COMMENT }}
64+
65+
- name: Fail as the changelog is missing
66+
if: steps.changelogs.outputs.any_changed == 'false'
67+
run: exit 1

0 commit comments

Comments
 (0)