Skip to content

Commit 0e6f95a

Browse files
ci(publish): goreleaser action (#261)
1 parent 7dd13dd commit 0e6f95a

File tree

4 files changed

+127
-13
lines changed

4 files changed

+127
-13
lines changed

.github/workflows/publish.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Publish
2+
on:
3+
push:
4+
tags:
5+
- 'v*.*.*'
6+
jobs:
7+
publish_release:
8+
name: Release
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout head
12+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
13+
with:
14+
fetch-depth: 0
15+
- name: Get tag version
16+
id: git
17+
run: echo "tag_version=$(make version)" >> "$GITHUB_OUTPUT"
18+
- name: Get release notes
19+
id: release_notes
20+
run: make release-notes > .release_notes
21+
- name: Run goreleaser-action
22+
uses: goreleaser/goreleaser-action@336e29918d653399e599bfca99fadc1d7ffbc9f7 # v4.3.0
23+
with:
24+
version: latest
25+
args: release --clean --release-notes=.release_notes
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yaml

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Make sure to check the documentation at https://goreleaser.com
2+
builds:
3+
- skip: true
4+
5+
changelog:
6+
# Set this to true if you don't want any changelog at all.
7+
#
8+
# Warning: this will also ignore any changelog files passed via `--release-notes`,
9+
# and will render an empty changelog.
10+
#
11+
# This may result in an empty release notes on GitHub/GitLab/Gitea.
12+
#
13+
# Templates: allowed
14+
skip: false
15+
sort: asc
16+
filters:
17+
18+
# Commit messages matching the regexp listed here will be removed from
19+
# the changelog
20+
exclude:
21+
- '^chore(docs)'
22+
- '^ci'
23+
24+
release:
25+
# Repo in which the release will be created.
26+
# Default is extracted from the origin remote URL or empty if its private hosted.
27+
github:
28+
owner: UpCloudLtd
29+
name: upcloud-go-api
30+
31+
# If set to true, will not auto-publish the release.
32+
# Available only for GitHub and Gitea.
33+
#
34+
# Default: false
35+
draft: true
36+
37+
# Whether to remove existing draft releases with the same name before creating
38+
# a new one.
39+
# Only effective if `draft` is set to true.
40+
# Available only for GitHub.
41+
#
42+
# Default: false
43+
# Since: v1.11
44+
replace_existing_draft: true
45+
46+
# If set to auto, will mark the release as not ready for production
47+
# in case there is an indicator for this in the tag e.g. v1.0.0-rc1
48+
# If set to true, will mark the release as not ready for production.
49+
# Default is false.
50+
prerelease: false
51+
52+
# What to do with the release notes in case there the release already exists.
53+
#
54+
# Valid options are:
55+
# - `keep-existing`: keep the existing notes
56+
# - `append`: append the current release notes to the existing notes
57+
# - `prepend`: prepend the current release notes to the existing notes
58+
# - `replace`: replace existing notes
59+
#
60+
# Default is `keep-existing`.
61+
mode: keep-existing
62+
63+
# You can change the name of the release.
64+
#
65+
# Default: '{{.Tag}}' ('{{.PrefixedTag}}' on Pro)
66+
# Templates: allowed
67+
name_template: "{{.Tag}}"

Makefile

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
.PHONY: test
1+
VERSION ?= $(shell git describe --tags --always --dirty --match=v* 2> /dev/null || \
2+
cat $(CURDIR)/.version 2> /dev/null || echo v0)
3+
4+
.PHONY: test
25
test: check-test-env
36
go test ./... -parallel 8
47

@@ -13,3 +16,17 @@ endif
1316
ifndef UPCLOUD_GO_SDK_TEST_PASSWORD
1417
$(error UPCLOUD_GO_SDK_TEST_PASSWORD is undefined)
1518
endif
19+
20+
.PHONY: version
21+
version:
22+
@echo $(VERSION)
23+
24+
.PHONY: release-notes
25+
release-notes: CHANGELOG_HEADER = ^\#\# \[
26+
release-notes: CHANGELOG_VERSION = $(subst v,,$(VERSION))
27+
release-notes:
28+
@awk \
29+
'/${CHANGELOG_HEADER}${CHANGELOG_VERSION}/ { flag = 1; next } \
30+
/${CHANGELOG_HEADER}/ { if ( flag ) { exit; } } \
31+
flag { if ( n ) { print prev; } n++; prev = $$0 }' \
32+
CHANGELOG.md

RELEASING.md

+15-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
# Releasing
22

33
1. Merge all your changes to the stable branch
4-
1. If releasing a new major version, ensure that package name has been updated, e.g. if new version is `v6` package name in go.mod and every import should be `github.com/UpCloudLtd/upcloud-go-api/v6`
5-
1. Update CHANGELOG.md
6-
1. Add new heading with the correct version e.g. `## [v2.3.5]`
7-
1. Update links at the bottom of the page
8-
1. Leave “Unreleased” section at the top empty
9-
1. Update `Version` in [upcloud/client/client.go](./upcloud/client/client.go)
10-
1. Visit the repo [GitHub releases-page](https://github.com/UpCloudLtd/upcloud-go-api/releases) and draft a new release
11-
1. Tag the release `vX.Y.Z` (e.g. `v2.3.5`)
12-
1. Select the stable branch
13-
1. Title the release “vX.Y.Z”
14-
1. In the description of the release, paste the changes from CHANGELOG.md for this version release
15-
1. Publish the release when you are ready
4+
2. If releasing a new major version, ensure that package name has been updated, e.g. if new version is `v6` package name in go.mod and every import should be `github.com/UpCloudLtd/upcloud-go-api/v6`
5+
3. Update CHANGELOG.md
6+
1. Add new heading with the correct version e.g. `## [6.7.0]`
7+
2. Update links at the bottom of the page
8+
3. Leave `## Unreleased` section at the top empty
9+
4. Update `Version` in [upcloud/client/client.go](./upcloud/client/client.go)
10+
5. Test GoReleaser config with `goreleaser check`
11+
6. Tag a commit with the version you want to release e.g. `v6.7.0`
12+
7. Push the tag & commit to GitHub
13+
- GitHub action automatically
14+
- sets the version based on the tag
15+
- creates a draft release to GitHub
16+
- populates the release notes from `CHANGELOG.md` with `make release-notes`
17+
8. Verify that [release notes](https://github.com/UpCloudLtd/upcloud-go-api/releases) are in line with `CHANGELOG.MD`
18+
9. Publish the drafted release

0 commit comments

Comments
 (0)