Skip to content

Add cloudamqp version command (#18) #7

Add cloudamqp version command (#18)

Add cloudamqp version command (#18) #7

Workflow file for this run

name: Build Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
jobs:
build:
name: Build Cross-Platform Binaries
runs-on: ubuntu-latest
strategy:
matrix:
include:
- goos: linux
goarch: amd64
name: linux-amd64
- goos: linux
goarch: arm64
name: linux-arm64
- goos: darwin
goarch: amd64
name: darwin-amd64
- goos: darwin
goarch: arm64
name: darwin-arm64
- goos: windows
goarch: amd64
name: windows-amd64
ext: .exe
- goos: windows
goarch: arm64
name: windows-arm64
ext: .exe
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23'
- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-1.23-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-1.23-
- name: Download dependencies
run: go mod download
- name: Extract version information
id: version
run: |
# Extract version from tag (remove 'v' prefix if present)
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
VERSION="${GITHUB_REF#refs/tags/}"
else
VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "dev")
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Get build date in UTC
BUILD_DATE=$(date -u +"%Y-%m-%d")
echo "build_date=$BUILD_DATE" >> $GITHUB_OUTPUT
# Get short commit hash
GIT_COMMIT=$(git rev-parse --short HEAD)
echo "git_commit=$GIT_COMMIT" >> $GITHUB_OUTPUT
echo "Building version: $VERSION (commit: $GIT_COMMIT, date: $BUILD_DATE)"
- name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
go build -a -installsuffix cgo \
-ldflags="-w -s -X cloudamqp-cli/cmd.Version=${{ steps.version.outputs.version }} -X cloudamqp-cli/cmd.BuildDate=${{ steps.version.outputs.build_date }} -X cloudamqp-cli/cmd.GitCommit=${{ steps.version.outputs.git_commit }}" \
-o cloudamqp-${{ matrix.name }}${{ matrix.ext }} .
- name: Verify version (Linux/macOS only)
if: matrix.goos != 'windows'
run: |
chmod +x cloudamqp-${{ matrix.name }}${{ matrix.ext }}
./cloudamqp-${{ matrix.name }}${{ matrix.ext }} version || echo "Version verification skipped for cross-compiled binary"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: cloudamqp-${{ matrix.name }}
path: cloudamqp-${{ matrix.name }}${{ matrix.ext }}
retention-days: 30
package:
name: Create Release Archive
runs-on: ubuntu-latest
needs: build
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Create release archives
run: |
mkdir -p release
for dir in artifacts/*/; do
artifact_name=$(basename "$dir")
binary_name=$(ls "$dir")
# Create archive based on platform
if [[ $artifact_name == *"windows"* ]]; then
cd "$dir" && zip "../../release/${artifact_name}.zip" "$binary_name" && cd - > /dev/null
else
cd "$dir" && tar -czf "../../release/${artifact_name}.tar.gz" "$binary_name" && cd - > /dev/null
fi
done
# List created archives
ls -la release/
- name: Upload release archives
uses: actions/upload-artifact@v4
with:
name: release-archives
path: release/
retention-days: 90
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: release/*
draft: false
prerelease: false
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}