Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: build-release-binaries workflow #3484

Closed
wants to merge 12 commits into from
11 changes: 11 additions & 0 deletions .github/actions/setup-go/action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
name: Setup go

outputs:
go-version:
description: "The Go version that was set up"
value: ${{ steps.setup-go.outputs.go-version }}

runs:
using: 'composite'
steps:
- name: Setup go
id: setup-go
uses: actions/setup-go@v4
with:
go-version: '1.23'

- name: Verify setup
shell: bash
run: |
echo "Go version: $(go version)"
102 changes: 102 additions & 0 deletions .github/workflows/build-release-binaries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Build and Release Binaries

on:
workflow_run:
workflows: ["Publish Release"]
types:
- completed

jobs:
build-binaries:
# Only run if the triggering workflow succeeded and it was triggered by a tag
if: >
github.event.workflow_run.conclusion == 'success' &&
startsWith(github.event.workflow_run.head_branch, 'refs/tags/v')
runs-on: ubuntu-24.04
name: Build Cross-Platform Binaries
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: ./.github/actions/setup-go
id: setup-go

- name: Get app/version.Version from the code
if: github.ref_type == 'branch'
run: |
VERSION=$(grep 'var version' app/version/version.go | cut -d'"' -f2)
echo "APP_VERSION=$VERSION" >> $GITHUB_ENV
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV

- name: Set version from git tag
if: github.ref_type == 'tag'
run: |
echo "APP_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
echo "RELEASE_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
echo "GO_BUILD_FLAG=-ldflags=-X github.com/obolnetwork/charon/app/version.version=${{ github.ref_name }}" >> $GITHUB_ENV

- name: Set build flags for branch
if: github.ref_type == 'branch'
run: |
echo "GO_BUILD_FLAG=-ldflags=-X github.com/obolnetwork/charon/app/version.version=${{ env.APP_VERSION }}" >> $GITHUB_ENV

- name: Install cross-compilation dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential gcc-aarch64-linux-gnu

- name: Build x86_64 binary
run: |
mkdir -p dist
docker run --rm --platform linux/amd64 \
-v $(pwd):/workspace -w /workspace \
golang:${{ steps.setup-go.outputs.go-version }}-bookworm \
bash -c "apt-get update && apt-get install -y build-essential && \
env CGO_ENABLED=1 GOOS=linux GOARCH=amd64 \
go build -tags='netgo osusergo' ${{ env.GO_BUILD_FLAG }} \
-o dist/charon-${{ env.RELEASE_VERSION }}-linux-amd64"

- name: Build ARM64 binary
run: |
docker run --rm --platform linux/amd64 \
-v $(pwd):/workspace -w /workspace \
golang:${{ steps.setup-go.outputs.go-version }}-bookworm \
bash -c "apt-get update && apt-get install -y gcc-aarch64-linux-gnu && \
env CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc \
go build -tags='netgo osusergo' ${{ env.GO_BUILD_FLAG }} \
-o dist/charon-${{ env.RELEASE_VERSION }}-linux-arm64"

- name: Create release archives
run: |
cd dist
tar czf charon-${{ env.RELEASE_VERSION }}-linux-amd64.tar.gz charon-${{ env.RELEASE_VERSION }}-linux-amd64
tar czf charon-${{ env.RELEASE_VERSION }}-linux-arm64.tar.gz charon-${{ env.RELEASE_VERSION }}-linux-arm64
echo "# Linux AMD64 (x86_64)" > checksums.txt
sha256sum charon-${{ env.RELEASE_VERSION }}-linux-amd64.tar.gz >> checksums.txt
echo -e "\n# Linux ARM64 (aarch64)" >> checksums.txt
sha256sum charon-${{ env.RELEASE_VERSION }}-linux-arm64.tar.gz >> checksums.txt

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: charon-${{ env.RELEASE_VERSION }}-binaries
path: |
dist/charon-${{ env.RELEASE_VERSION }}-linux-amd64
dist/charon-${{ env.RELEASE_VERSION }}-linux-arm64
dist/charon-${{ env.RELEASE_VERSION }}-linux-amd64.tar.gz
dist/charon-${{ env.RELEASE_VERSION }}-linux-arm64.tar.gz
dist/checksums.txt

- name: Attach to GitHub Release
if: github.event.workflow_run.conclusion == 'success'
uses: softprops/action-gh-release@v1
with:
files: |
dist/charon-${{ env.RELEASE_VERSION }}-linux-amd64.tar.gz
dist/charon-${{ env.RELEASE_VERSION }}-linux-arm64.tar.gz
dist/checksums.txt
draft: true
tag_name: ${{ github.event.workflow_run.head_branch }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31 changes: 31 additions & 0 deletions build-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
set -e

# Create dist directory if it doesn't exist
mkdir -p dist

# Build for linux/amd64
echo "Building for linux/amd64..."
Copy link
Collaborator

@pinebit pinebit Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know for sure we don't need a build for Mac ARM? (I see this becomes very common in OSS)

docker run --rm --platform linux/amd64 \
-v $(pwd):/workspace -w /workspace \
--platform linux/amd64 \
golang:1.23.4-bookworm \
bash -c "apt-get update && apt-get install -y build-essential && \
env CGO_ENABLED=1 GOOS=linux GOARCH=amd64 \
go build -tags='netgo osusergo' -o dist/charon-linux-amd64"

# Build for linux/arm64
echo "Building for linux/arm64..."
docker run --rm --platform linux/amd64 \
-v $(pwd):/workspace -w /workspace \
--platform linux/amd64 \
golang:1.23.4-bookworm \
bash -c "apt-get update && apt-get install -y gcc-aarch64-linux-gnu && \
env CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc \
go build -tags='netgo osusergo' -o dist/charon-linux-arm64"

# Create archives
cd dist
for binary in charon-*; do
tar czf "${binary}.tar.gz" "$binary"
done
Loading