Skip to content

chore(): test and release (#29) #1

chore(): test and release (#29)

chore(): test and release (#29) #1

Workflow file for this run

name: Release binaries
on:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
build-and-release:
name: Build and attach binaries
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@v4
- name: Set up Go
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}" ./cmd
- 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
- name: Create GitHub Release (if not exists)
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
draft: false
prerelease: ${{ contains(github.ref_name, '-rc') || contains(github.ref_name, '-beta') || contains(github.ref_name, '-alpha') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
- name: Upload artifact to release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
files: ${{ env.ARCHIVE_PATH }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}