-
Notifications
You must be signed in to change notification settings - Fork 51
88 lines (75 loc) · 3.13 KB
/
Copy pathupdate-changelog.yml
File metadata and controls
88 lines (75 loc) · 3.13 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
name: Update Changelog
on:
push:
tags:
- 'v*'
permissions:
contents: write
pull-requests: write
jobs:
tag-check:
runs-on: ubuntu-latest
steps:
- name: Validate stable release tag
id: check-tag
run: |
set -euo pipefail
echo "Tag validation"
[[ "${GITHUB_REF_NAME}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] \
|| { echo "Tag '${GITHUB_REF_NAME}' doesn't match expected format"; exit 1; }
update-changelog:
needs: tag-check
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: main
fetch-depth: 0
- name: Find previous release tag
id: prev-tag
run: |
git fetch --tags --force
CURRENT_TAG="${{ github.ref_name }}"
PREV_TAG=$(git tag -l 'v*' | grep -v -E '(prerelease|test|hotfix)' | sort -V | grep -B1 "^${CURRENT_TAG}$" | head -1)
if [ -z "$PREV_TAG" ]; then
PREV_TAG=$(git tag -l 'v*' | grep -v -E '(prerelease|test|hotfix)' | sort -V | tail -1)
fi
echo "Auto-detected previous tag: $PREV_TAG"
echo "prev_tag=$PREV_TAG" >> "$GITHUB_OUTPUT"
- name: Check if there are commits between tags
id: check-commits
run: |
COUNT=$(git rev-list --count "${{ steps.prev-tag.outputs.prev_tag }}..${{ github.ref_name }}" || echo "0")
echo "commit_count=$COUNT" >> "$GITHUB_OUTPUT"
echo "Found $COUNT commit(s) between ${{ steps.prev-tag.outputs.prev_tag }} and ${{ github.ref_name }}"
- name: Version without leading v
run: echo "RELEASE_VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV"
- name: Generate changelog
if: steps.check-commits.outputs.commit_count != '0'
uses: orhun/git-cliff-action@f50e11560dce63f7c33227798f90b924471a88b5 # v4.8.0
id: git-cliff
with:
config: cliff.toml
args: --verbose ${{ steps.prev-tag.outputs.prev_tag }}..${{ github.ref_name }} --tag ${{ env.RELEASE_VERSION }} --prepend CHANGELOG.md
- name: Create PR with changelog
if: steps.check-commits.outputs.commit_count != '0'
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: changelog-${{ github.ref_name }}
base: main
title: "OCM-00000 | chore: add changelog for ${{ github.ref_name }}"
body: |
## Changelog for ${{ github.ref_name }}
Auto-generated changelog entry for release ${{ github.ref_name }}.
**Release tag**: `${{ github.ref_name }}`
**Previous tag**: `${{ steps.prev-tag.outputs.prev_tag }}`
Auto-generated by GitHub Actions.
commit-message: |
OCM-00000 | chore: add changelog for ${{ github.ref_name }}
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
labels: changelog
delete-branch: true
add-paths: "CHANGELOG.md"
sign-commits: true