forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (127 loc) · 4.35 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
name: Generate changelog
on:
workflow_call:
inputs:
version:
type: string
required: true
description: 'Target release version (semver, git tag, branch or commit)'
target:
required: true
type: string
description: 'The base branch that these changes are being merged into'
dry_run:
required: false
default: false
type: boolean
latest:
required: false
default: false
type: boolean
secrets:
GRAFANA_DELIVERY_BOT_APP_ID:
required: true
GRAFANA_DELIVERY_BOT_APP_PEM:
required: true
workflow_dispatch:
inputs:
version:
type: string
required: true
description: 'Target release version (semver, git tag, branch or commit)'
target:
required: true
type: string
description: 'The base branch that these changes are being merged into'
dry_run:
required: false
default: false
type: boolean
description: 'Dry run mode'
latest:
required: false
default: false
type: boolean
description: 'Generate changelog for the latest release'
permissions:
contents: write
pull-requests: write
jobs:
main:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: "Generate token"
id: generate_token
uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92
with:
app_id: ${{ secrets.GRAFANA_DELIVERY_BOT_APP_ID }}
private_key: ${{ secrets.GRAFANA_DELIVERY_BOT_APP_PEM }}
- name: "Checkout Grafana repo"
uses: "actions/checkout@v4"
with:
ref: main
sparse-checkout: |
.github/workflows
CHANGELOG.md
fetch-depth: 0
fetch-tags: true
- name: "Configure git user"
run: |
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local --add --bool push.autoSetupRemote true
- name: "Create branch"
run: git checkout -b "changelog/${{ github.run_id }}/${{ inputs.version }}"
- name: "Generate changelog"
id: changelog
uses: ./.github/workflows/actions/changelog
with:
github_token: ${{ steps.generate_token.outputs.token }}
target: v${{ inputs.version }}
output_file: changelog_items.md
- name: "Patch CHANGELOG.md"
run: |
# Prepare CHANGELOG.md content with version delimiters
(
echo
echo "# ${{ inputs.version}} ($(date '+%F'))"
echo
cat changelog_items.md
) > CHANGELOG.part
# Check if a version exists in the changelog
if grep -q "<!-- ${{ inputs.version}} START" CHANGELOG.md ; then
# Replace the content between START and END delimiters
echo "Version ${{ inputs.version }} is found in the CHANGELOG.md, patching contents..."
sed -i -e '/${{ inputs.version }} START/,/${{ inputs.version }} END/{//!d;}' \
-e '/${{ inputs.version }} START/r CHANGELOG.part' CHANGELOG.md
else
# Prepend changelog part to the main changelog file
echo "Version ${{ inputs.version }} not found in the CHANGELOG.md"
(
echo "<!-- ${{ inputs.version }} START -->"
cat CHANGELOG.part
echo "<!-- ${{ inputs.version }} END -->"
cat CHANGELOG.md
) > CHANGELOG.tmp
mv CHANGELOG.tmp CHANGELOG.md
fi
git diff CHANGELOG.md
git add CHANGELOG.md
- name: "Commit changelog changes"
run: git commit --allow-empty -m "Update changelog" CHANGELOG.md
- name: "git push"
if: ${{ inputs.dry_run }} != true
run: git push
- name: "Create changelog PR"
run: >
gh pr create \
--dry-run=${{ inputs.dry_run }} \
--label "no-backport" \
--label "no-changelog" \
-B "${{ inputs.target }}" \
--title "Release: update changelog for ${{ inputs.version }}" \
--body "Changelog changes for release ${{ inputs.version }}"
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}