Skip to content

Commit 4adf48e

Browse files
onuryilmazLicense Bot
andauthored
chore(ci): switch to goreleaser (#46)
Co-authored-by: License Bot <license_bot@github.com>
1 parent 370ff5e commit 4adf48e

4 files changed

Lines changed: 72 additions & 174 deletions

File tree

.github/workflows/release.yaml

Lines changed: 14 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -9,95 +9,26 @@ permissions:
99
contents: write
1010

1111
jobs:
12-
build-and-release:
13-
name: Build and attach binaries
12+
goreleaser:
1413
runs-on: ubuntu-latest
15-
16-
strategy:
17-
fail-fast: false
18-
matrix:
19-
include:
20-
- goos: linux
21-
goarch: amd64
22-
- goos: linux
23-
goarch: arm64
24-
- goos: darwin
25-
goarch: amd64
26-
- goos: darwin
27-
goarch: arm64
28-
- goos: windows
29-
goarch: amd64
30-
- goos: windows
31-
goarch: arm64
32-
3314
steps:
34-
- name: Check out repository
35-
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
3619

3720
- name: Set up Go
38-
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6
21+
uses: actions/setup-go@v5
3922
with:
40-
go-version: "1.25.x"
41-
42-
- name: Verify build
43-
run: |
44-
go version
45-
go mod download
46-
go build ./...
47-
48-
- name: Build binary
49-
env:
50-
CGO_ENABLED: "0"
51-
GOOS: ${{ matrix.goos }}
52-
GOARCH: ${{ matrix.goarch }}
53-
run: |
54-
BIN_NAME=cloudctl
55-
OUT_DIR=dist
56-
mkdir -p "${OUT_DIR}"
57-
if [ "${GOOS}" = "windows" ]; then
58-
OUT_BIN="${OUT_DIR}/${BIN_NAME}_${GOOS}_${GOARCH}.exe"
59-
else
60-
OUT_BIN="${OUT_DIR}/${BIN_NAME}_${GOOS}_${GOARCH}"
61-
fi
62-
echo "Building ${OUT_BIN}"
63-
go build -trimpath -ldflags="-s -w" -o "${OUT_BIN}" .
64-
# Mark executable on unix
65-
if [ "${GOOS}" != "windows" ]; then
66-
chmod +x "${OUT_BIN}"
67-
fi
68-
echo "OUT_BIN=${OUT_BIN}" >> $GITHUB_ENV
69-
70-
- name: Package artifact
71-
run: |
72-
set -euo pipefail
73-
BIN_NAME=cloudctl
74-
OUT_DIR=dist
75-
ARCHIVE_DIR=pkg
76-
mkdir -p "${ARCHIVE_DIR}"
77-
78-
FILE_BASE="${BIN_NAME}_${{ matrix.goos }}_${{ matrix.goarch }}"
79-
if [ "${{ matrix.goos }}" = "windows" ]; then
80-
BIN_PATH="${OUT_DIR}/${FILE_BASE}.exe"
81-
ARCHIVE_PATH="${ARCHIVE_DIR}/${FILE_BASE}.zip"
82-
(cd "${OUT_DIR}" && zip -9 "../${ARCHIVE_PATH}" "${FILE_BASE}.exe")
83-
else
84-
BIN_PATH="${OUT_DIR}/${FILE_BASE}"
85-
ARCHIVE_PATH="${ARCHIVE_DIR}/${FILE_BASE}.tar.gz"
86-
(cd "${OUT_DIR}" && tar -czf "../${ARCHIVE_PATH}" "${FILE_BASE}")
87-
fi
88-
89-
echo "ARCHIVE_PATH=${ARCHIVE_PATH}" >> $GITHUB_ENV
90-
echo "BIN_PATH=${BIN_PATH}" >> $GITHUB_ENV
23+
go-version: "1.25"
9124

92-
- name: Upload artifact to release
93-
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2
25+
- name: Run GoReleaser
26+
uses: goreleaser/goreleaser-action@v6
9427
with:
95-
tag_name: ${{ github.ref_name }}
96-
files: |
97-
${{ env.ARCHIVE_PATH }}
98-
${{ env.BIN_PATH }}
28+
# either 'goreleaser' (default) or 'goreleaser-pro'
29+
distribution: goreleaser
30+
# 'latest', 'v1.4.4' or a SemVer constraint
31+
version: "~> v2"
32+
args: release --clean
9933
env:
10034
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101-
draft: false
102-
prerelease: ${{ contains(github.ref_name, '-rc') || contains(github.ref_name, '-beta') || contains(github.ref_name, '-alpha') }}
103-
continue-on-error: true

.goreleaser.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# .goreleaser.yaml
5+
version: 2
6+
7+
before:
8+
hooks:
9+
- go mod tidy
10+
11+
builds:
12+
- env:
13+
- CGO_ENABLED=0
14+
goos:
15+
- linux
16+
- darwin
17+
- windows
18+
goarch:
19+
- amd64
20+
- arm64
21+
ldflags:
22+
- -s -w
23+
- -X github.com/cloudoperators/cloudctl/cmd.Version={{.Version}}
24+
- -X github.com/cloudoperators/cloudctl/cmd.GitCommit={{.Commit}}
25+
- -X github.com/cloudoperators/cloudctl/cmd.BuildDate={{.Date}}
26+
main: .
27+
binary: cloudctl
28+
29+
archives:
30+
- formats:
31+
- tar.gz
32+
# use zip for windows archives
33+
format_overrides:
34+
- goos: windows
35+
formats:
36+
- zip
37+
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"
38+
39+
checksum:
40+
split: true
41+
42+
snapshot:
43+
version_template: "{{ incpatch .Version }}-next"
44+
45+
changelog:
46+
sort: asc
47+
filters:
48+
exclude:
49+
- '^docs:'
50+
- '^test:'

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ require (
5050
github.com/go-openapi/swag/typeutils v0.25.4 // indirect
5151
github.com/go-openapi/swag/yamlutils v0.25.4 // indirect
5252
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
53-
github.com/gogo/protobuf v1.3.2 // indirect
5453
github.com/google/gnostic-models v0.7.1 // indirect
5554
github.com/google/go-cmp v0.7.0 // indirect
5655
github.com/google/uuid v1.6.0 // indirect

0 commit comments

Comments
 (0)