Skip to content

Commit d61f928

Browse files
authored
update release workflows (#7)
1 parent dfd4541 commit d61f928

File tree

2 files changed

+231
-180
lines changed

2 files changed

+231
-180
lines changed

.github/workflows/zz_generated.create_release.yaml

Lines changed: 77 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
# DO NOT EDIT. Generated with:
22
#
3-
# devctl gen workflows
3+
# devctl@5.12.0
44
#
55
name: Create Release
66
on:
77
push:
88
branches:
99
- 'legacy'
10+
- 'main'
1011
- 'master'
1112
- 'release-v*.*.x'
1213
# "!" negates previous positive patterns so it has to be at the end.
1314
- '!release-v*.x.x'
1415
jobs:
1516
debug_info:
1617
name: Debug info
17-
runs-on: ubuntu-18.04
18+
runs-on: ubuntu-20.04
1819
steps:
1920
- name: Print github context JSON
2021
run: |
@@ -23,7 +24,7 @@ jobs:
2324
EOF
2425
gather_facts:
2526
name: Gather facts
26-
runs-on: ubuntu-18.04
27+
runs-on: ubuntu-20.04
2728
outputs:
2829
project_go_path: ${{ steps.get_project_go_path.outputs.path }}
2930
ref_version: ${{ steps.ref_version.outputs.refversion }}
@@ -32,24 +33,27 @@ jobs:
3233
- name: Get version
3334
id: get_version
3435
run: |
35-
title="$(echo "${{ github.event.head_commit.message }}" | head -n 1 -)"
36+
title="$(cat <<- 'COMMIT_MESSAGE_END' | head -n 1 -
37+
${{ github.event.head_commit.message }}
38+
COMMIT_MESSAGE_END
39+
)"
3640
# Matches strings like:
3741
#
38-
# - "release v1.2.3"
39-
# - "release v1.2.3-r4"
40-
# - "release v1.2.3 (#56)"
41-
# - "release v1.2.3-r4 (#56)"
42+
# - "Release v1.2.3"
43+
# - "Release v1.2.3-r4"
44+
# - "Release v1.2.3 (#56)"
45+
# - "Release v1.2.3-r4 (#56)"
4246
#
4347
# And outputs version part (1.2.3).
44-
if echo $title | grep -qE '^release v[0-9]+\.[0-9]+\.[0-9]+([.-][^ .-][^ ]*)?( \(#[0-9]+\))?$' ; then
45-
version=$(echo $title | cut -d ' ' -f 2)
48+
if echo "${title}" | grep -iqE '^Release v[0-9]+\.[0-9]+\.[0-9]+([.-][^ .-][^ ]*)?( \(#[0-9]+\))?$' ; then
49+
version=$(echo "${title}" | cut -d ' ' -f 2)
4650
fi
4751
version="${version#v}" # Strip "v" prefix.
48-
echo "version=\"$version\""
49-
echo "::set-output name=version::${version}"
52+
echo "version=\"${version}\""
53+
echo "version=${version}" >> $GITHUB_OUTPUT
5054
- name: Checkout code
5155
if: ${{ steps.get_version.outputs.version != '' }}
52-
uses: actions/checkout@v2
56+
uses: actions/checkout@v3
5357
- name: Get project.go path
5458
id: get_project_go_path
5559
if: ${{ steps.get_version.outputs.version != '' }}
@@ -59,81 +63,47 @@ jobs:
5963
path=''
6064
fi
6165
echo "path=\"$path\""
62-
echo "::set-output name=path::${path}"
66+
echo "path=${path}" >> $GITHUB_OUTPUT
6367
- name: Check if reference version
6468
id: ref_version
6569
run: |
66-
title="$(echo "${{ github.event.head_commit.message }}" | head -n 1 -)"
67-
if echo $title | grep -qE '^release v[0-9]+\.[0-9]+\.[0-9]+([.-][^ .-][^ ]*)?( \(#[0-9]+\))?$' ; then
68-
version=$(echo $title | cut -d ' ' -f 2)
70+
title="$(cat <<- 'COMMIT_MESSAGE_END' | head -n 1 -
71+
${{ github.event.head_commit.message }}
72+
COMMIT_MESSAGE_END
73+
)"
74+
if echo "${title}" | grep -qE '^release v[0-9]+\.[0-9]+\.[0-9]+([.-][^ .-][^ ]*)?( \(#[0-9]+\))?$' ; then
75+
version=$(echo "${title}" | cut -d ' ' -f 2)
6976
fi
70-
version=$(echo $title | cut -d ' ' -f 2)
77+
version=$(echo "${title}" | cut -d ' ' -f 2)
7178
version="${version#v}" # Strip "v" prefix.
7279
refversion=false
7380
if [[ "${version}" =~ ^[0-9]+.[0-9]+.[0-9]+-[0-9]+$ ]]; then
7481
refversion=true
7582
fi
76-
echo "refversion =\"$refversion\""
77-
echo "::set-output name=refversion::$refversion"
78-
install_semver:
79-
name: Install semver
80-
runs-on: ubuntu-18.04
81-
env:
82-
BINARY: "semver"
83-
URL: "https://raw.githubusercontent.com/fsaintjacques/semver-tool/3.0.0/src/semver"
84-
steps:
85-
- name: Key
86-
id: key
87-
run: |
88-
cache_dir="/opt/cache"
89-
cache_key="install-${BINARY}-${URL}"
90-
echo "::set-output name=binary::${BINARY}"
91-
echo "::set-output name=cache_dir::${cache_dir}"
92-
echo "::set-output name=cache_key::${cache_key}"
93-
echo "::set-output name=url::${URL}"
94-
- name: Cache
95-
id: cache
96-
uses: actions/cache@v1
97-
with:
98-
key: "${{ steps.key.outputs.cache_key }}"
99-
path: "${{ steps.key.outputs.cache_dir }}"
100-
- name: Download
101-
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
102-
run: |
103-
# TODO check hash
104-
binary="${{ steps.key.outputs.binary }}"
105-
cache_dir="${{ steps.key.outputs.cache_dir }}"
106-
url="${{ steps.key.outputs.url }}"
107-
mkdir $cache_dir
108-
curl -fsSLo $cache_dir/$binary $url
109-
chmod +x $cache_dir/$binary
110-
- name: Smoke test
111-
run: |
112-
${{ steps.key.outputs.cache_dir }}/${{ steps.key.outputs.binary }} --version
113-
- name: Upload artifact
114-
uses: actions/upload-artifact@v1
115-
with:
116-
name: "${{ steps.key.outputs.binary }}"
117-
path: "${{ steps.key.outputs.cache_dir }}/${{ steps.key.outputs.binary }}"
83+
echo "refversion =\"${refversion}\""
84+
echo "refversion=${refversion}" >> $GITHUB_OUTPUT
11885
update_project_go:
11986
name: Update project.go
120-
runs-on: ubuntu-18.04
87+
runs-on: ubuntu-20.04
12188
if: ${{ needs.gather_facts.outputs.version != '' && needs.gather_facts.outputs.project_go_path != '' && needs.gather_facts.outputs.ref_version != 'true' }}
12289
needs:
12390
- gather_facts
124-
- install_semver
12591
steps:
126-
- name: Download semver artifact to /opt/bin
127-
uses: actions/download-artifact@v2
92+
- name: Install architect
93+
uses: giantswarm/[email protected]
12894
with:
129-
name: semver
130-
path: /opt/bin
131-
- name: Prepare /opt/bin
132-
run: |
133-
chmod +x /opt/bin/*
134-
echo "::add-path::/opt/bin"
95+
binary: "architect"
96+
version: "6.1.0"
97+
- name: Install semver
98+
uses: giantswarm/[email protected]
99+
with:
100+
binary: "semver"
101+
version: "3.2.0"
102+
download_url: "https://github.com/fsaintjacques/${binary}-tool/archive/${version}.tar.gz"
103+
tarball_binary_path: "*/src/${binary}"
104+
smoke_test: "${binary} --version"
135105
- name: Checkout code
136-
uses: actions/checkout@v2
106+
uses: actions/checkout@v3
137107
- name: Update project.go
138108
id: update_project_go
139109
env:
@@ -144,17 +114,19 @@ jobs:
144114
version="${{ needs.gather_facts.outputs.version }}"
145115
new_version="$(semver bump patch $version)-dev"
146116
echo "version=\"$version\" new_version=\"$new_version\""
147-
echo "::set-output name=new_version::${new_version}"
117+
echo "new_version=${new_version}" >> $GITHUB_OUTPUT
148118
sed -Ei "s/(version[[:space:]]*=[[:space:]]*)\"${version}\"/\1\"${new_version}\"/" $file
149119
if git diff --exit-code $file ; then
150120
echo "error: no changes in \"$file\"" >&2
151121
exit 1
152122
fi
123+
- name: Set up git identity
124+
run: |
125+
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
126+
git config --local user.name "github-actions[bot]"
153127
- name: Commit changes
154128
run: |
155129
file="${{ needs.gather_facts.outputs.project_go_path }}"
156-
git config --local user.email "[email protected]"
157-
git config --local user.name "GitHub Action"
158130
git add $file
159131
git commit -m "Bump version to ${{ steps.update_project_go.outputs.new_version }}"
160132
- name: Push changes
@@ -174,15 +146,15 @@ jobs:
174146
hub pull-request -f -m "${{ env.title }}" -b ${{ env.base }} -h ${{ env.branch }} -r ${{ github.actor }}
175147
create_release:
176148
name: Create release
177-
runs-on: ubuntu-18.04
149+
runs-on: ubuntu-20.04
178150
needs:
179151
- gather_facts
180152
if: ${{ needs.gather_facts.outputs.version }}
181153
outputs:
182154
upload_url: ${{ steps.create_gh_release.outputs.upload_url }}
183155
steps:
184156
- name: Checkout code
185-
uses: actions/checkout@v2
157+
uses: actions/checkout@v3
186158
with:
187159
ref: ${{ github.sha }}
188160
- name: Ensure correct version in project.go
@@ -191,10 +163,19 @@ jobs:
191163
file="${{ needs.gather_facts.outputs.project_go_path }}"
192164
version="${{ needs.gather_facts.outputs.version }}"
193165
grep -qE "version[[:space:]]*=[[:space:]]*\"$version\"" $file
166+
- name: Get Changelog Entry
167+
id: changelog_reader
168+
uses: mindsers/changelog-reader-action@v2
169+
with:
170+
version: ${{ needs.gather_facts.outputs.version }}
171+
path: ./CHANGELOG.md
172+
- name: Set up git identity
173+
run: |
174+
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
175+
git config --local user.name "github-actions[bot]"
194176
- name: Create tag
195177
run: |
196178
version="${{ needs.gather_facts.outputs.version }}"
197-
git config --local user.name "github-actions"
198179
git tag "v$version" ${{ github.sha }}
199180
- name: Push tag
200181
env:
@@ -207,36 +188,42 @@ jobs:
207188
env:
208189
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
209190
with:
191+
body: ${{ steps.changelog_reader.outputs.changes }}
210192
tag_name: "v${{ needs.gather_facts.outputs.version }}"
211193
release_name: "v${{ needs.gather_facts.outputs.version }}"
194+
212195
create-release-branch:
213196
name: Create release branch
214-
runs-on: ubuntu-18.04
197+
runs-on: ubuntu-20.04
215198
needs:
216199
- gather_facts
217-
- install_semver
218200
if: ${{ needs.gather_facts.outputs.version }}
219201
steps:
220-
- name: Download semver artifact to /opt/bin
221-
uses: actions/download-artifact@v2
202+
- name: Install semver
203+
uses: giantswarm/[email protected]
222204
with:
223-
name: semver
224-
path: /opt/bin
225-
- name: Prepare /opt/bin
226-
run: |
227-
chmod +x /opt/bin/*
228-
echo "::add-path::/opt/bin"
229-
- uses: actions/checkout@v2
230-
name: Check out the repository
205+
binary: "semver"
206+
version: "3.0.0"
207+
download_url: "https://github.com/fsaintjacques/${binary}-tool/archive/${version}.tar.gz"
208+
tarball_binary_path: "*/src/${binary}"
209+
smoke_test: "${binary} --version"
210+
- name: Check out the repository
211+
uses: actions/checkout@v3
231212
with:
232213
fetch-depth: 0 # Clone the whole history, not just the most recent commit.
233214
- name: Fetch all tags and branches
234215
run: "git fetch --all"
235216
- name: Create long-lived release branch
236217
run: |
237218
current_version="${{ needs.gather_facts.outputs.version }}"
238-
parent_version="$(git describe --tags --abbrev=0 HEAD^)"
219+
parent_version="$(git describe --tags --abbrev=0 HEAD^ || true)"
239220
parent_version="${parent_version#v}" # Strip "v" prefix.
221+
222+
if [[ -z "$parent_version" ]] ; then
223+
echo "Unable to find a parent tag version. No branch to create."
224+
exit 0
225+
fi
226+
240227
echo "current_version=$current_version parent_version=$parent_version"
241228
242229
current_major=$(semver get major $current_version)

0 commit comments

Comments
 (0)