Skip to content

feat: add PR Docker build and test workflow (#54) #1

feat: add PR Docker build and test workflow (#54)

feat: add PR Docker build and test workflow (#54) #1

# Build otel-distro-builder standalone binaries (PyInstaller) per platform.
# On push tag v*, builds binaries and uploads them to the existing release.
# Platforms: linux/amd64, linux/arm64 (arm runner), darwin/arm64, darwin/amd64, windows/amd64.
# If ubuntu-24.04-arm is not available for your plan, remove the linux/arm64 matrix entry.
name: Build CLI Binaries
on:
push:
tags:
- "v*"
permissions:
contents: read
jobs:
build-binary:
strategy:
fail-fast: false
matrix:
include:
- runner: ubuntu-latest
os: linux
arch: amd64
- runner: ubuntu-24.04-arm
os: linux
arch: arm64
- runner: macos-14
os: darwin
arch: arm64
- runner: macos-13
os: darwin
arch: amd64
- runner: windows-latest
os: windows
arch: amd64
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
pip install pyinstaller
- name: Build binary (Unix)
if: matrix.os != 'windows'
run: |
pyinstaller --clean --noconfirm otel-distro-builder.spec
VERSION=${GITHUB_REF#refs/tags/}
mkdir -p release
cp dist/otel-distro-builder release/otel-distro-builder-${{ matrix.os }}-${{ matrix.arch }}
chmod +x release/otel-distro-builder-${{ matrix.os }}-${{ matrix.arch }}
tar -czvf "otel-distro-builder-${VERSION}-${{ matrix.os }}-${{ matrix.arch }}.tar.gz" -C release "otel-distro-builder-${{ matrix.os }}-${{ matrix.arch }}"
- name: Build binary (Windows)
if: matrix.os == 'windows'
shell: pwsh
run: |
pyinstaller --clean --noconfirm otel-distro-builder.spec
$Version = $env:GITHUB_REF -replace '^refs/tags/', ''
New-Item -ItemType Directory -Force -Path release
Copy-Item dist\otel-distro-builder.exe release\otel-distro-builder-${{ matrix.os }}-${{ matrix.arch }}.exe
Compress-Archive -Path release\otel-distro-builder-${{ matrix.os }}-${{ matrix.arch }}.exe -DestinationPath "otel-distro-builder-${Version}-${{ matrix.os }}-${{ matrix.arch }}.zip"
- name: Test standalone binary (Unix)
if: matrix.os != 'windows'
run: |
BIN="release/otel-distro-builder-${{ matrix.os }}-${{ matrix.arch }}"
"$BIN" --help
"$BIN" --version
"$BIN" --from-config builder/tests/configs/otelcol/simple.yaml --generate-only --output-manifest /tmp/gen.yaml
test -s /tmp/gen.yaml
- name: Test standalone binary (Windows)
if: matrix.os == 'windows'
shell: pwsh
run: |
$BIN = "release\otel-distro-builder-${{ matrix.os }}-${{ matrix.arch }}.exe"
& $BIN --help
& $BIN --version
& $BIN --from-config builder\tests\configs\otelcol\simple.yaml --generate-only --output-manifest $env:TEMP\gen.yaml
if (-not (Test-Path $env:TEMP\gen.yaml)) { throw "Manifest not generated" }
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: binary-${{ matrix.os }}-${{ matrix.arch }}
path: "otel-distro-builder-*.${{ matrix.os == 'windows' && 'zip' || 'tar.gz' }}"
test-standalone-no-python:
# Prove the binary works with neither Python nor Go on PATH.
runs-on: ubuntu-latest
needs: build-binary
steps:
- uses: actions/checkout@v4
- name: Download linux/amd64 binary
uses: actions/download-artifact@v4
with:
name: binary-linux-amd64
- name: Extract and run binary (no Python or Go on PATH)
run: |
tar -xzf otel-distro-builder-*.tar.gz
BIN=$(find . -maxdepth 1 -type f -name 'otel-distro-builder-*' ! -name '*.tar.gz' | head -1)
chmod +x "$BIN"
# Build a PATH with Go directories removed
NO_GO_PATH=$(echo "$PATH" | tr ':' '\n' | while read -r d; do [ -x "$d/go" ] || printf '%s:' "$d"; done | sed 's/:$//')
echo "Verifying Go is not on cleaned PATH..."
PATH="$NO_GO_PATH" command -v go && { echo "FAIL: Go still on PATH"; exit 1; } || true
PATH="$NO_GO_PATH" "$BIN" --help
PATH="$NO_GO_PATH" "$BIN" --version
PATH="$NO_GO_PATH" "$BIN" --from-config builder/tests/configs/otelcol/simple.yaml --generate-only --output-manifest /tmp/out.yaml
test -s /tmp/out.yaml
echo "Standalone binary works with no Python or Go at runtime."
upload-to-release:
needs: [build-binary, test-standalone-no-python]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download all binary artifacts
uses: actions/download-artifact@v4
with:
path: release-binaries
merge-multiple: true
- name: Add binaries to Release
uses: softprops/action-gh-release@v2
with:
files: |
release-binaries/*.tar.gz
release-binaries/*.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}