-
Notifications
You must be signed in to change notification settings - Fork 0
200 lines (191 loc) · 6.35 KB
/
new-release.yaml
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
name: TagRelease
on:
workflow_dispatch:
inputs:
tag:
description: 'Tag version number (Eg: v0.1.0)'
required: true
type: string
permissions:
contents: write
packages: write
jobs:
# * Step 0: Pre-Check
pre-check:
runs-on: ubuntu-latest
outputs:
TAG_NAME: ${{ steps.set-tag.outputs.TAG_NAME }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.CHANGELOG_PAT }}
- name: Check if tag is valid
run : |
# Check if the tag start with 'v', if not, add it
if [[ ! ${{ github.event.inputs.tag }} =~ ^v.* ]]; then
echo "Error tag format is invalid. The format is vx.x.x" >> "$GITHUB_OUTPUT"
exit 1
fi
- name: Construct Tag for Pre-Release
id: set-tag
run: |
# Construct the tag name
echo "TAG_NAME=${{ github.event.inputs.tag }}" >> "$GITHUB_OUTPUT"
# * Step 1: Check if everything is ok
tag-already-exist:
needs: [pre-check]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.CHANGELOG_PAT }}
- name: Check if tag not already exists
run: |
if git rev-parse ${{ needs.pre-check.outputs.TAG_NAME }} >/dev/null 2>&1; then
echo "Tag ${{ needs.pre-check.outputs.TAG_NAME }} already exists" >> "$GITHUB_OUTPUT"
exit 1
fi
golangci-lint:
needs: [pre-check]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.CHANGELOG_PAT }}
ref: ${{ github.ref }}
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- run: go mod download
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
testsunit:
needs: [pre-check]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.CHANGELOG_PAT }}
ref: ${{ github.ref }}
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- run: go mod download
- name: Run Go unit tests
run: |
go test $(go list ./... | grep -v /internal/registry)
# * Step 2: Create a new tag
tag:
needs: [golangci-lint, pre-check, tag-already-exist, testsunit]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.CHANGELOG_PAT }}
- uses: rickstaa/action-create-tag@v1
id: "tag_create"
with:
tag: ${{ needs.pre-check.outputs.TAG_NAME }}
tag_exists_error: true
message: "Release ${{ needs.pre-check.outputs.TAG_NAME }}"
release-notes:
needs: [tag, pre-check]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ needs.pre-check.outputs.TAG_NAME }}
- name: Generate Release Notes
run: |
echo "" > release-notes.txt
export PREV_TAG=$(git tag --list 'v*' --sort=-version:refname | grep -E "v[0-9]+\.[0-9]+\.[0-9]+$" | head -n 2 | tail -n 1)
export PREV_VERSION=${PREV_TAG//v}
sed -n -e "1{/# /d;}" -e "2{/^$/d;}" -e "/# $PREV_VERSION/q;p" CHANGELOG.md >> release-notes.txt
- uses: actions/upload-artifact@v4
with:
name: release-notes
path: release-notes.txt
retention-days: 1
release-app:
runs-on: ubuntu-latest
needs: [release-notes, pre-check]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ needs.pre-check.outputs.TAG_NAME }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: release-notes-download
name: Release Notes Download
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: release-notes
path: /tmp
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
if: success()
with:
distribution: goreleaser
version: ~> v2
args: release --clean -f .goreleaser.yaml --release-notes=${{ steps.release-notes-download.outputs.download-path }}/release-notes.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
trigger-doc-update:
needs: [release-app, pre-check]
runs-on: ubuntu-latest
steps:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v3
with:
event-type: update-doc
changelog-newversion:
needs: [release-app, pre-check]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.CHANGELOG_PAT }}
fetch-depth: 0
ref: main
- name: Update Changelog Header
run: |
CHANGELOG_FILE_NAME="CHANGELOG.md"
RELEASE_TAG=${{ needs.pre-check.outputs.TAG_NAME }}
# PREVIOUS_RELEASE_TAG=${{ github.ref_name }}
# Add Release Date
RELEASE_DATE=`date +%B' '%e', '%Y`
sed -i -e "1 s/.*Unreleased.*/## ${RELEASE_TAG#v} ($RELEASE_DATE)/" $CHANGELOG_FILE_NAME
# Prepend next release line
echo Release is: $RELEASE_TAG
NEW_RELEASE_LINE=$(echo $RELEASE_TAG | awk -F. '{
$1 = substr($1,2)
$2 += 1
printf("%s.%01d.0\n\n", $1, $2);
}')
echo New minor version is: v$NEW_RELEASE_LINE
echo -e "## $NEW_RELEASE_LINE (Unreleased)\n$(cat $CHANGELOG_FILE_NAME)" > $CHANGELOG_FILE_NAME
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "chore: Update CHANGELOG.md after ${{ github.ref_name }}"
commit_options: '--no-verify --signoff'
file_pattern: CHANGELOG.md
commit_user_name: github-actions[bot]
commit_user_email: github-actions[bot]@users.noreply.github.com
commit_author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>