Skip to content

🧪 crane validate offline mode : Automate test for malformed… #126

🧪 crane validate offline mode : Automate test for malformed…

🧪 crane validate offline mode : Automate test for malformed… #126

name: Build Crane Binaries
on:
push:
branches:
- main
tags:
- "*"
schedule:
- cron: "17 3 * * *"
workflow_dispatch:
permissions:
contents: read
jobs:
build:
name: Build ${{ matrix.goos }}/${{ matrix.goarch }}
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
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go 1.25
uses: actions/setup-go@v6
with:
go-version: "1.25"
- name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: "0"
BUILD_VERSION: ${{ github.ref_type == 'tag' && github.ref_name || format('main-{0}', github.sha) }}
BUILD_COMMIT: ${{ github.sha }}
run: |
mkdir -p dist
ext=""
if [ "$GOOS" = "windows" ]; then
ext=".exe"
fi
binary="crane_${GOOS}_${GOARCH}${ext}"
go build -trimpath \
-ldflags "-X github.com/konveyor/crane/internal/buildinfo.Version=${BUILD_VERSION} -X github.com/konveyor/crane/internal/buildinfo.BuildCommit=${BUILD_COMMIT}" \
-o "dist/${binary}" .
# Validate version injection for each built artifact.
if ! strings "dist/${binary}" | grep -Fq "${BUILD_VERSION}"; then
echo "Injected version ${BUILD_VERSION} not found in ${binary}"
exit 1
fi
(
cd dist
sha256sum "${binary}" > "${binary}.sha256"
)
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: crane-${{ matrix.goos }}-${{ matrix.goarch }}
path: |
dist/crane_${{ matrix.goos }}_${{ matrix.goarch }}*
retention-days: 30
release:
name: Draft release for tag
if: startsWith(github.ref, 'refs/tags/')
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download binary artifacts
uses: actions/download-artifact@v4
with:
pattern: crane-*
merge-multiple: true
path: release-assets
- name: Create combined checksums manifest
shell: bash
run: |
cd release-assets
: > checksums.txt
for binary in crane_*; do
if [ -f "$binary" ] && [[ "$binary" != *.sha256 ]]; then
sha256sum "$binary" >> checksums.txt
fi
done
- name: Keep only binaries and combined checksums file
run: rm -f release-assets/*.sha256
- name: Create draft GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
draft: true
generate_release_notes: true
files: |
release-assets/crane_*
release-assets/checksums.txt