forked from fossasia/scrum_helper
-
Notifications
You must be signed in to change notification settings - Fork 0
117 lines (99 loc) · 3.97 KB
/
Copy pathrelease-drafter.yml
File metadata and controls
117 lines (99 loc) · 3.97 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
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
name: Release Drafter
on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- master
pull_request:
types: [opened, reopened, synchronize]
permissions:
contents: write
jobs:
update_release_draft:
permissions:
# write permission is required to create a github release
contents: write
# write permission is required for autolabeler
pull-requests: write
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- name: Draft Release
id: release_drafter
uses: release-drafter/release-drafter@v6
with:
config-name: release-drafter.yml
publish: false
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Debug release-drafter outputs
run: |
echo "release-drafter.tag_name='${{ steps.release_drafter.outputs.tag_name }}"
echo "release-drafter.body:""
echo "${{ steps.release_drafter.outputs.body }}"
- name: Create / prepend CHANGELOG entry
if: steps.release_drafter.outputs.tag_name != ''
run: |
TAG="${{ steps.release_drafter.outputs.tag_name }}"
BODY="${{ steps.release_drafter.outputs.body }}"
DATE="$(date +%F)"
printf "## %s - %s\n\n%s\n\n---\n\n" "$TAG" "$DATE" "$BODY" > /tmp/new_changelog.md
if [ -f CHANGELOG.md ]; then
cat CHANGELOG.md >> /tmp/new_changelog.md
fi
mv /tmp/new_changelog.md CHANGELOG.md
git status --porcelain
- name: Commit CHANGELOG, create & push tag
if: steps.release_drafter.outputs.tag_name != ''
env:
TAG: ${{ steps.release_drafter.outputs.tag_name }}
GIT_AUTHOR_NAME: "github-actions[bot]"
GIT_AUTHOR_EMAIL: "github-actions[bot]@users.noreply.github.com"
run: |
git config user.name "$GIT_AUTHOR_NAME"
git config user.email "$GIT_AUTHOR_EMAIL"
git add CHANGELOG.md || true
if git diff --cached --quiet; then
echo "No CHANGELOG.md changes to commit"
else
git commit -m "docs(changelog): update for ${TAG}"
git push origin HEAD:master
fi
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag ${TAG} already exists locally"
else
git tag -a "${TAG}" -m "Release ${TAG}"
fi
git push origin "refs/tags/${TAG}" || echo "Tag push failed or tag already exists remotely"
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Ensure correct branch is checked out (only on PR)
if: github.event_name == 'pull_request'
run: |
echo "Checking out PR source branch: ${{ github.head_ref }}"
git fetch origin ${{ github.head_ref }}
git checkout ${{ github.head_ref }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Update Changelog
run: |
VERSION="${{ steps.release_drafter.outputs.tag_name }}"
BODY="${{ steps.release_drafter.outputs.body }}"
# Create a new changelog entry file
echo -e "## ${VERSION} ($(date +'%Y-%m-%d'))\n\n${BODY}\n\n" > new_changelog_entry.md
# Prepend the new entry to the existing CHANGELOG.md
if [ -f CHANGELOG.md ]; then
cat CHANGELOG.md >> new_changelog_entry.md
fi
mv new_changelog_entry.md CHANGELOG.md
# Commits the updated CHANGELOG.md and creates a tag for the new version
- name: Commit and Push Changelog
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: 'docs: Update CHANGELOG.md for ${{ steps.release_drafter.outputs.tag_name }}'
file_pattern: 'CHANGELOG.md'
tagging_message: ${{ steps.release_drafter.outputs.tag_name }}