Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 14 additions & 83 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,95 +9,26 @@ permissions:
contents: write

jobs:
build-and-release:
name: Build and attach binaries
goreleaser:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64
- goos: windows
goarch: amd64
- goos: windows
goarch: arm64

steps:
- name: Check out repository
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6
uses: actions/setup-go@v5
with:
go-version: "1.25.x"

- name: Verify build
run: |
go version
go mod download
go build ./...

- name: Build binary
env:
CGO_ENABLED: "0"
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
BIN_NAME=cloudctl
OUT_DIR=dist
mkdir -p "${OUT_DIR}"
if [ "${GOOS}" = "windows" ]; then
OUT_BIN="${OUT_DIR}/${BIN_NAME}_${GOOS}_${GOARCH}.exe"
else
OUT_BIN="${OUT_DIR}/${BIN_NAME}_${GOOS}_${GOARCH}"
fi
echo "Building ${OUT_BIN}"
go build -trimpath -ldflags="-s -w" -o "${OUT_BIN}" .
# Mark executable on unix
if [ "${GOOS}" != "windows" ]; then
chmod +x "${OUT_BIN}"
fi
echo "OUT_BIN=${OUT_BIN}" >> $GITHUB_ENV

- name: Package artifact
run: |
set -euo pipefail
BIN_NAME=cloudctl
OUT_DIR=dist
ARCHIVE_DIR=pkg
mkdir -p "${ARCHIVE_DIR}"

FILE_BASE="${BIN_NAME}_${{ matrix.goos }}_${{ matrix.goarch }}"
if [ "${{ matrix.goos }}" = "windows" ]; then
BIN_PATH="${OUT_DIR}/${FILE_BASE}.exe"
ARCHIVE_PATH="${ARCHIVE_DIR}/${FILE_BASE}.zip"
(cd "${OUT_DIR}" && zip -9 "../${ARCHIVE_PATH}" "${FILE_BASE}.exe")
else
BIN_PATH="${OUT_DIR}/${FILE_BASE}"
ARCHIVE_PATH="${ARCHIVE_DIR}/${FILE_BASE}.tar.gz"
(cd "${OUT_DIR}" && tar -czf "../${ARCHIVE_PATH}" "${FILE_BASE}")
fi

echo "ARCHIVE_PATH=${ARCHIVE_PATH}" >> $GITHUB_ENV
echo "BIN_PATH=${BIN_PATH}" >> $GITHUB_ENV
go-version: "1.25"

- name: Upload artifact to release
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
tag_name: ${{ github.ref_name }}
files: |
${{ env.ARCHIVE_PATH }}
${{ env.BIN_PATH }}
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
# 'latest', 'v1.4.4' or a SemVer constraint
version: "~> v2"
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
draft: false
prerelease: ${{ contains(github.ref_name, '-rc') || contains(github.ref_name, '-beta') || contains(github.ref_name, '-alpha') }}
continue-on-error: true
50 changes: 50 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors
# SPDX-License-Identifier: Apache-2.0

# .goreleaser.yaml
version: 2

before:
hooks:
- go mod tidy

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm64
ldflags:
- -s -w
- -X github.com/cloudoperators/cloudctl/cmd.Version={{.Version}}
- -X github.com/cloudoperators/cloudctl/cmd.GitCommit={{.Commit}}
- -X github.com/cloudoperators/cloudctl/cmd.BuildDate={{.Date}}
main: .
binary: cloudctl

archives:
- formats:
- tar.gz
# use zip for windows archives
format_overrides:
- goos: windows
formats:
- zip
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"

checksum:
split: true

snapshot:
version_template: "{{ incpatch .Version }}-next"

changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ require (
github.com/go-openapi/swag/typeutils v0.25.4 // indirect
github.com/go-openapi/swag/yamlutils v0.25.4 // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/gnostic-models v0.7.1 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/uuid v1.6.0 // indirect
Expand Down
Loading