98 lines
2.6 KiB
YAML
98 lines
2.6 KiB
YAML
when:
|
|
- event: tag
|
|
|
|
steps:
|
|
- name: validate-release
|
|
image: golang:1.26.5
|
|
commands:
|
|
- |
|
|
set -eu
|
|
|
|
version="$CI_COMMIT_TAG"
|
|
release_note="docs/releases/$version.md"
|
|
|
|
if ! printf '%s\n' "$version" |
|
|
grep -Eq '^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$'
|
|
then
|
|
printf '%s\n' "invalid release tag: $version" >&2
|
|
exit 1
|
|
fi
|
|
test -s "$release_note"
|
|
test -z "$(git ls-files go.work go.work.sum)"
|
|
test ! -e vendor
|
|
if grep -Eq '^[[:space:]]*replace([[:space:]]|\()' go.mod
|
|
then
|
|
printf '%s\n' 'go.mod contains a replacement' >&2
|
|
exit 1
|
|
fi
|
|
|
|
GOWORK=off go test -count=1 ./...
|
|
GOWORK=off go test -race -count=1 ./...
|
|
GOWORK=off go vet ./...
|
|
GOWORK=off go build ./...
|
|
GOWORK=off go mod tidy -diff
|
|
|
|
unformatted=$(
|
|
git ls-files '*.go' |
|
|
while IFS= read -r go_file
|
|
do
|
|
gofmt -l "$go_file"
|
|
done
|
|
)
|
|
test -z "$unformatted"
|
|
git diff --check
|
|
|
|
- name: build-release-assets
|
|
image: golang:1.26.5
|
|
depends_on:
|
|
- validate-release
|
|
commands:
|
|
- |
|
|
set -eu
|
|
|
|
version="$CI_COMMIT_TAG"
|
|
dist="dist"
|
|
pkg="gitea.maximumdirect.net/eric/weatherreporter/cmd/weatherreporter"
|
|
|
|
rm -rf "$dist"
|
|
mkdir -p "$dist"
|
|
|
|
build_binary() {
|
|
goos="$1"
|
|
goarch="$2"
|
|
suffix="$3"
|
|
output="$dist/weatherreporter-$version-$goos-$goarch$suffix"
|
|
|
|
CGO_ENABLED=0 GOOS="$goos" GOARCH="$goarch" \
|
|
go build -trimpath -ldflags "-s -w -X gitea.maximumdirect.net/eric/weatherreporter/internal/buildinfo.Version=$version" \
|
|
-o "$output" "$pkg"
|
|
}
|
|
|
|
build_binary linux amd64 ""
|
|
build_binary linux arm64 ""
|
|
build_binary darwin amd64 ""
|
|
build_binary darwin arm64 ""
|
|
build_binary windows amd64 ".exe"
|
|
build_binary windows arm64 ".exe"
|
|
|
|
host_binary="$dist/weatherreporter-$version-$(go env GOOS)-$(go env GOARCH)"
|
|
test "$("$host_binary" --version)" = "weatherreporter $version"
|
|
|
|
- name: publish-release
|
|
image: woodpeckerci/plugin-release:0.3.1
|
|
depends_on:
|
|
- build-release-assets
|
|
settings:
|
|
api_key:
|
|
from_secret: GITEA_RELEASE_TOKEN
|
|
files:
|
|
- dist/weatherreporter-*
|
|
title: Weatherreporter ${CI_COMMIT_TAG}
|
|
note: docs/releases/${CI_COMMIT_TAG}.md
|
|
checksum: sha256
|
|
checksum-file: SHA256SUMS
|
|
checksum-flatten: true
|
|
file-exists: skip
|
|
overwrite: false
|
|
prerelease: false
|