Skip to content

Build and Release

Build and Release #24

Workflow file for this run

name: Build and Release
on:
release:
types: [created]
permissions:
contents: write # allow uploading assets to the Release page
jobs:
build:
runs-on: ubuntu-22.04
steps:
# 1 — Checkout
- name: Checkout code
uses: actions/checkout@v4
# 2 — Switch off the flaky Azure mirror (keeps the earlier fix in place)
- name: Use Canonical mirror instead of Azure
run: |
sudo sed -i \
's|http://azure\.archive\.ubuntu\.com/ubuntu|http://archive.ubuntu.com/ubuntu|g' \
/etc/apt/sources.list
sudo apt-get update -qq
# 3 — Extract version tag from the Release event
- name: Get release tag
id: get_tag
run: echo "TAG=${GITHUB_REF#refs/tags/}" >>"$GITHUB_OUTPUT"
# 4 — Fast Go installer
- name: Setup Go (fast)
uses: WillAbides/setup-go-faster@v1.14.0
with:
go-version: '1.21.x'
# 5 — Enable arm64 and add the *correct* repositories
- name: Configure apt for ARM64 and install cross‑toolchains & PAM headers
run: |
# a) enable the architecture
sudo dpkg --add-architecture arm64
#
# b) LIMIT every existing entry to amd64 so APT never
# asks security.ubuntu.com (or archive.ubuntu.com) for arm64.
#
sudo sed -Ei 's/^deb\s+/deb [arch=amd64] /' /etc/apt/sources.list
#
# c) add ports.ubuntu.com for arm64, including the *-security* pocket
#
cat <<'EOF' | sudo tee /etc/apt/sources.list.d/arm64-ports.list
deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy main restricted universe multiverse
deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy-updates main restricted universe multiverse
deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy-backports main restricted universe multiverse
deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy-security main restricted universe multiverse
EOF
# d) refresh indexes (with retries) and install the tool‑chain
for i in 1 2 3; do sudo apt-get update -qq && break || sleep 5; done
for i in 1 2 3; do \
sudo apt-get install -y --no-install-recommends \
build-essential \
gcc-aarch64-linux-gnu \
libpam0g-dev \
libpam0g-dev:arm64 \
&& break || sleep 5; \
done
echo "Verifying installations:"
dpkg -l gcc-aarch64-linux-gnu libpam0g-dev:arm64
# 6 — Cache Go modules & build cache
- name: Cache Go modules
uses: actions/cache@v4
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
# 7 — Build linux/amd64
- name: Build linux/amd64
run: |
mkdir -p dist
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 \
go build -ldflags "-s -w" \
-o dist/clab-api-server-linux-amd64 ./cmd/server
# 8 — Build linux/arm64 (cross‑compile)
- name: Build linux/arm64
env:
CC: aarch64-linux-gnu-gcc
PKG_CONFIG_PATH: /usr/lib/aarch64-linux-gnu/pkgconfig
run: |
CGO_ENABLED=1 GOOS=linux GOARCH=arm64 \
go build -ldflags "-s -w" \
-o dist/clab-api-server-linux-arm64 ./cmd/server
# 9 — Make binaries executable
- name: Set execute bits
run: chmod +x dist/clab-api-server-linux-*
# 10 — Upload binaries to the GitHub Release page
- name: Upload Release Assets
uses: softprops/action-gh-release@v1
with:
files: |
dist/clab-api-server-linux-amd64
dist/clab-api-server-linux-arm64
# 11 — Also keep them as CI artifacts (optional)
- name: Upload binaries as artifact
uses: actions/upload-artifact@v4
with:
name: clab-api-server-${{ steps.get_tag.outputs.TAG }}
path: dist/
retention-days: 7