-
Notifications
You must be signed in to change notification settings - Fork 1
174 lines (149 loc) · 6.32 KB
/
publish_release_draft.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: Publish draft release when release branch is merged
on:
pull_request:
types:
- closed
branches:
- main
- support/*
jobs:
publish_release:
if: ${{ github.event.pull_request.merged }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
with:
fetch-depth: 0
- name: Get repository name
id: repo-name
uses: tiller1010/get-repo-name-action@master
with:
with-owner: 'true'
- name: Get release id
id: get_release_id
run: |
TOKEN="${{ secrets.GITHUB_TOKEN }}"
REPO="${{ steps.repo-name.outputs.repository-name }}"
RELEASEID=$(curl -H "Accept: application/vnd.github+json" -H "Authorization: token $TOKEN" https://api.github.com/repos/$REPO/releases)
RELEASEID=$(echo "$RELEASEID" | grep \"id\" | head -n 1 | sed -re "s/[a-z]*//g;s/[-|,|:|'\"]//g;s/\s//g")
echo "release_id=$RELEASEID" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Payload info
id: payload_info
uses: tiller1010/payload-info-action@master
continue-on-error: true
# START HOTFIX RELEASE RE-DRAFT
- name: Check if releasing a hotfix
id: is_hotfix_branch
continue-on-error: true
run: |
PRBRANCH="${{ steps.payload_info.outputs.branch }}"
FILTEREDBRANCHNAME=$(echo "$PRBRANCH" | grep "hotfix")
echo "filtered_pr_branch_name=$FILTEREDBRANCHNAME" >> $GITHUB_OUTPUT
- name: Get hotfix Tag from branch name
id: get_hotfix_tag
if: steps.is_hotfix_branch.outputs.filtered_pr_branch_name != ''
run: |
HOTFIXBRANCH="${{ steps.payload_info.outputs.branch }}"
RELEASETAG=$(echo "$HOTFIXBRANCH" | sed -re "s/(\* )?hotfix\///;s/(\w+)\/.*/\1/g")
echo "release_tag=$RELEASETAG" >> $GITHUB_OUTPUT
- name: Get Last Tag created on this branch
id: last_tag
if: steps.is_hotfix_branch.outputs.filtered_pr_branch_name != ''
run: |
LASTTAG=$(git describe --tags | sed -re "s/-.+//")
echo "last_tag_on_branch=$LASTTAG" >> $GITHUB_OUTPUT
# Re-Draft Release with hotfix tag
# "release-drafter" works by checking the changes of merged pull requests.
# For support or main branch hotfixes, there is only one merged hotfix PR, which is only now available,
# so we need to re-draft the release with the recently merged PR for release notes.
- name: Draft Release with hotfix tag
id: update_release_draft_with_hotfix_branch
if: steps.is_hotfix_branch.outputs.filtered_pr_branch_name != ''
uses: tiller1010/release-drafter@master
with:
tag: ${{ steps.get_hotfix_tag.outputs.release_tag }}
last_tag: ${{ steps.last_tag.outputs.last_tag_on_branch }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# END HOTFIX RELEASE RE-DRAFT
- name: Publish release
uses: eregon/publish-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ steps.get_release_id.outputs.release_id }}
# START CHANGELOG PORTION
- name: Check if releasing for a support branch
id: is_support_branch
continue-on-error: true
run: |
FILTEREDBRANCHNAME=$(git branch | grep "\* support")
echo "filtered_branch_name=$FILTEREDBRANCHNAME" >> $GITHUB_OUTPUT
- name: Generate Changelog
id: changelog
if: steps.is_support_branch.outputs.filtered_branch_name == ''
uses: tiller1010/tag-changelog@main
with:
token: ${{ secrets.GITHUB_TOKEN }}
exclude_types: other,doc,chore
config_file: .github/tag-changelog-config.js
- name: Output Changelog
id: output_changelog
if: steps.is_support_branch.outputs.filtered_branch_name == ''
run: TAGCONTENT="${{ steps.changelog.outputs.changelog }}";CHANGELOG=$(cat CHANGELOG.md);CHANGELOG=$(echo "$CHANGELOG" | sed -e "s/# Changelog//");echo -e "# Changelog\n\n$TAGCONTENT$CHANGELOG" > CHANGELOG.md
- name: Create Pull Request
id: create_pr
if: steps.is_support_branch.outputs.filtered_branch_name == ''
uses: peter-evans/create-pull-request@v4
with:
title: Auto-Update CHANGELOG.md
commit-message: Updated CHANGELOG.md
labels: automerge
- name: Approve PR
if: steps.is_support_branch.outputs.filtered_branch_name == ''
uses: hmarr/auto-approve-action@v3
with:
review-message: Auto approved automated PR
pull-request-number: ${{ steps.create_pr.outputs.pull-request-number }}
github-token: ${{ secrets.SOME_USERS_PAT }}
- name: Auto merge
if: steps.is_support_branch.outputs.filtered_branch_name == ''
uses: pascalgn/automerge-action@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PULL_REQUEST: ${{ steps.create_pr.outputs.pull-request-number }}
MERGE_DELETE_BRANCH: true
- name: Post Changelog Checkout
if: steps.is_support_branch.outputs.filtered_branch_name == ''
uses: actions/checkout@master
with:
ref: main
# END CHANGELOG PORTION
# Merge support changes into develop so they can be included in the next release
- name: Merge support -> develop
if: steps.is_support_branch.outputs.filtered_branch_name != ''
uses: devmasx/merge-branch@master
with:
type: now
target_branch: develop
github_token: ${{ secrets.GITHUB_TOKEN }}
message: Merged support into develop
# Merge main changes into develop
- name: Merge main -> develop
if: steps.is_support_branch.outputs.filtered_branch_name == ''
uses: devmasx/merge-branch@master
with:
type: now
from_branch: main
target_branch: develop
github_token: ${{ secrets.GITHUB_TOKEN }}
message: Merged main into develop
# Remove the release or hotfix branch after publishing
- name: Remove PR branch
uses: dawidd6/action-delete-branch@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branches: ${{ steps.payload_info.outputs.branch }}