-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (80 loc) · 3.26 KB
/
update-changelog.yml
File metadata and controls
92 lines (80 loc) · 3.26 KB
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
name: update changelog
on:
workflow_call:
inputs:
branch:
description: 'Target branch'
default: ${{ github.event.release.target_commitish }}
type: string
version:
description: 'Released version'
default: ${{ github.event.release.tag_name }}
type: string
notes:
description: 'Release notes'
default: ${{ github.event.release.body }}
type: string
jobs:
update:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# Fetch entire history of repository to ensure release date can be
# extracted from commit of the given tag.
fetch-depth: 0
# Checkout target branch of this release. Ensures that the CHANGELOG
# is not out of date.
ref: ${{ inputs.branch }}
- name: Check if branch and release match
if: ${{ inputs.branch != 'main' && inputs.branch != 'master' }}
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: ${{ inputs.branch }}
RELEASE_TAG_NAME: ${{ inputs.version }}
- name: Fail if branch and release tag do not match
if: ${{ 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
run: |
# Get UNIX timestamp from git-tag
TIMESTAMP_OF_RELEASE_COMMIT=$(git log -1 --date=unix --format=%ad '${{ inputs.version }}');
# 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
uses: stefanzweifel/changelog-updater-action@v1
with:
# Pass extracted release date, release notes and version to the Action.
release-date: ${{ steps.release_date.outputs.date }}
release-notes: ${{ inputs.notes }}
latest-version: ${{ inputs.version }}
compare-url-target-revision: ${{ inputs.branch }}
parse-github-usernames: true
- name: Commit updated CHANGELOG
uses: stefanzweifel/git-auto-commit-action@v5
with:
# Push updated CHANGELOG to release target branch.
branch: ${{ inputs.branch }}
commit_message: Update CHANGELOG
file_pattern: CHANGELOG.md