-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (116 loc) · 4.81 KB
/
changelog.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
name: update changelog
on:
release:
types: [released]
workflow_call:
secrets:
GPG_BOT:
required: true
description: bot gpg token
GPG_PASSPHRASE:
required: true
description: bot gpg passphrase
GPG_FINGERPRINT:
required: true
description: bot gpg fingerprint
BOT_TOKEN:
required: true
description: bot token
jobs:
changelog:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.release.target_commitish }}
- name: Check file existence
id: check_files
uses: andstor/file-existence-action@v2
with:
files: "changelog.md"
- uses: actions/setup-go@v5
id: artifacts-golang
with:
go-version: '>=1.21.0'
- name: Install first-changelog
id: artifacts-tools-install
if: steps.check_files.outputs.files_exists != 'true'
run: go install github.com/bavix/first-changelog@latest
- name: Install ghmd
run: go install github.com/bavix/ghmd@latest
- name: Init changelog
id: artifacts-display-all
if: steps.check_files.outputs.files_exists != 'true'
run: |
~/go/bin/first-changelog "${{ github.repository }}" > changelog.md
- name: Fix changelog
run: cat changelog.md | ~/go/bin/ghmd | tee changelog.md
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_BOT }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
fingerprint: ${{ secrets.GPG_FINGERPRINT }}
git_config_global: true
git_user_signingkey: true
git_commit_gpgsign: true
git_committer_name: Github bot
git_committer_email: [email protected]
- name: Check if branch and release match
if: ${{ steps.check_files.outputs.files_exists == 'true' && github.event.release.target_commitish != 'main' && github.event.release.target_commitish != 'master' && github.event.release.target_commitish != 'latest' }}
id: guard
run: |
NUMERIC_VERSION="${RELEASE_TAG_NAME#v}"
MAJOR_VERSION="${NUMERIC_VERSION%%.*}"
BRANCH_MAJOR_VERSION="${BRANCH%%.*}"
echo "MAJOR_VERSION=$(echo $MAJOR_VERSION)" >> $GITHUB_OUTPUT;
echo "BRANCH_MAJOR_VERSION=$(echo $BRANCH_MAJOR_VERSION)" >> $GITHUB_OUTPUT;
if [ "$MAJOR_VERSION" != "$BRANCH_MAJOR_VERSION" ]; then
echo "Mismatched versions! Aborting."
VERSION_MISMATCH='true';
else
echo "Versions match! Proceeding."
VERSION_MISMATCH='false';
fi
echo "VERSION_MISMATCH=$(echo $VERSION_MISMATCH)" >> $GITHUB_OUTPUT;
env:
BRANCH: ${{ github.event.release.target_commitish }}
RELEASE_TAG_NAME: ${{ github.event.release.tag_name }}
- name: Fail if branch and release tag do not match
if: ${{ steps.check_files.outputs.files_exists == 'true' && steps.guard.outputs.VERSION_MISMATCH == 'true' }}
uses: actions/github-script@v7
with:
script: |
core.setFailed('Workflow failed. Release version does not match with selected target branch. Changelog not updated automatically.')
- name: Extract release date from git tag
id: release_date
if: steps.check_files.outputs.files_exists == 'true'
run: |
# Get UNIX timestamp from git-tag
TIMESTAMP_OF_RELEASE_COMMIT=$(git log -1 --date=unix --format=%ad '${{ github.event.release.tag_name }}');
# Convert timestamp to UTC date in Y-m-d format
FORMATED_DATE=$(date -u -d @$TIMESTAMP_OF_RELEASE_COMMIT +%Y-%m-%d)
# Make date available to other steps
echo "date=$(echo $FORMATED_DATE)" >> $GITHUB_OUTPUT;
- name: Update changelog.md
uses: stefanzweifel/changelog-updater-action@v1
if: steps.check_files.outputs.files_exists == 'true'
with:
release-date: ${{ steps.release_date.outputs.date }}
release-notes: ${{ github.event.release.body }}
latest-version: ${{ github.event.release.tag_name }}
compare-url-target-revision: ${{ github.event.release.target_commitish }}
parse-github-usernames: true
path-to-changelog: changelog.md
- name: Commit updated changelog.md
uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: ${{ github.event.release.target_commitish }}
commit_message: Update changelog.md
file_pattern: changelog.md
commit_user_name: Github bot
commit_user_email: [email protected]
commit_author: Github bot <[email protected]>
commit_options: '-S'