-
Notifications
You must be signed in to change notification settings - Fork 2
129 lines (121 loc) · 4.55 KB
/
release.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
name: Release
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'
# Releases need permissions to read and write the repository contents.
# GitHub considers creating releases and uploading assets as writing contents.
permissions:
contents: write
jobs:
release-notes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Generate Release Notes
run: |
sed -n -e "1{/# /d;}" -e "2{/^$/d;}" -e "/# $(git describe --abbrev=0 --exclude="$(git describe --abbrev=0 --match='v*.*.*' --tags)" --match='v*.*.*' --tags | tr -d v)/q;p" CHANGELOG.md > release-notes.md
RELEASE_NOTES=$(cat release-notes.md)
if [ -z "$PREVIOUS_CHANGELOG" ]
then
echo "Release notes file is empty."
exit 1
fi
- uses: actions/upload-artifact@v3
with:
name: release-notes
path: release-notes.md
retention-days: 1
release:
needs: [ release-notes ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
- name: Import GPG Key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v5
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
- name: Release Notes Download
id: release-notes-download
uses: actions/download-artifact@v3
with:
name: release-notes
path: /tmp
- name: goreleaser release (with release notes)
uses: goreleaser/goreleaser-action@v4
with:
args: release --release-notes ${{ steps.release-notes-download.outputs.download-path }}/release-notes.md --rm-dist --timeout 3h
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
highest-version-tag:
needs: [ release ]
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.highest-version-tag.outputs.tag }}
steps:
- uses: actions/checkout@v3
with:
# Allow tag to be fetched when ref is a commit
fetch-depth: 0
- name: Output highest version tag
id: highest-version-tag
run: |
HIGHEST=$(git tag | sort -V | tail -1)
echo "tag=$HIGHEST" >> "$GITHUB_OUTPUT"
changelog-newversion:
needs: [ release, highest-version-tag ]
# write new changelog header only if release tag is the $HIGHEST i.e. exists on main
# and not a backport release branch (e.g. release/3.x). This results in
# manually updating the CHANGELOG header if releasing from the non-default branch.
# TODO: find a more deterministic way to determine release branch from tag commit
if: github.ref_name == "${{ needs.highest-version-tag.outputs.tag }}"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: main
token: ${{ secrets.UPDATE_CHANGELOG_TOKEN }}
- name: Update Changelog Header
run: |
CHANGELOG_FILE_NAME="CHANGELOG.md"
PREVIOUS_RELEASE_TAG=${{ github.ref_name }}
# Add Release Date
RELEASE_DATE=`date +%B' '%e', '%Y`
sed -i -e "1 s/Unreleased/$RELEASE_DATE/" $CHANGELOG_FILE_NAME
# Prepend next release line
echo Previous release is: $PREVIOUS_RELEASE_TAG
NEW_RELEASE_LINE=$(echo $PREVIOUS_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
- run: |
git config --local user.email ${{ secrets.CHANGELOGBOT_EMAIL }}
git config --local user.name ${{ secrets.CHANGELOGBOT_NAME }}
git add CHANGELOG.md
git commit -m "Update CHANGELOG.md after ${{ github.ref_name }}"
git push
upload-tag-before-post-publish:
needs: [ release ]
runs-on: ubuntu-latest
steps:
- name: Save Release Tag
run: echo ${{ github.ref_name }} > release-tag.data
- uses: actions/upload-artifact@v2
with:
name: release-tag
path: release-tag.data
retention-days: 1