Skip to content

Add timeout option and env var to the OADP CLI tool #172

Add timeout option and env var to the OADP CLI tool

Add timeout option and env var to the OADP CLI tool #172

name: Cross-Architecture Build Test
on:
push:
branches: [ oadp-dev ]
pull_request:
branches: [ oadp-dev ]
workflow_dispatch:
jobs:
# Build all architectures in one place
build-all:
name: Build All Architectures
runs-on: ubuntu-latest
outputs:
suffix: ${{ steps.version.outputs.suffix }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: false
- name: Clean Go environment
run: |
echo "Cleaning Go environment for reliable build..."
go clean -cache -modcache -i -r || true
echo "Go environment cleaned"
- name: Determine version
id: version
run: |
if [[ "${{ github.ref_type }}" == "tag" ]]; then
echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
echo "suffix=${{ github.ref_name }}_" >> $GITHUB_OUTPUT
echo "Building with version: ${{ github.ref_name }}"
else
echo "version=" >> $GITHUB_OUTPUT
echo "suffix=" >> $GITHUB_OUTPUT
echo "Building without version (non-tag build)"
fi
- name: Build all architectures using make
run: |
set -e
echo "Building all architectures..."
if ! make release-build VERSION="${{ steps.version.outputs.version }}"; then
echo "❌ Build failed"
exit 1
fi
echo "✅ All builds completed"
- name: List generated binaries
run: |
set -e
echo "Generated binaries:"
ls -la kubectl-oadp_* || {
echo "❌ No binaries found"
exit 1
}
echo ""
echo "File details:"
file kubectl-oadp_* || echo "⚠️ File command not available"
- name: Upload Linux binaries
uses: actions/upload-artifact@v4
with:
name: linux-binaries
path: |
kubectl-oadp_${{ steps.version.outputs.suffix }}linux_amd64
kubectl-oadp_${{ steps.version.outputs.suffix }}linux_arm64
- name: Upload macOS binaries
uses: actions/upload-artifact@v4
with:
name: macos-binaries
path: |
kubectl-oadp_${{ steps.version.outputs.suffix }}darwin_amd64
kubectl-oadp_${{ steps.version.outputs.suffix }}darwin_arm64
- name: Upload Windows binaries
uses: actions/upload-artifact@v4
with:
name: windows-binaries
path: |
kubectl-oadp_${{ steps.version.outputs.suffix }}windows_amd64.exe
kubectl-oadp_${{ steps.version.outputs.suffix }}windows_arm64.exe
- name: Run host tests
run: |
set -e
echo "Running tests on build host..."
if ! make test; then
echo "❌ Host tests failed"
exit 1
fi
echo "✅ Host tests passed"
# Test Linux binaries on native Linux runners
test-linux:
name: Test Linux
needs: build-all
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
arch: amd64
binary: kubectl-oadp_${{ needs.build-all.outputs.suffix }}linux_amd64
- os: ubuntu-24.04-arm
arch: arm64
binary: kubectl-oadp_${{ needs.build-all.outputs.suffix }}linux_arm64
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code (for tests)
uses: actions/checkout@v4
- name: Set up Go (for running tests)
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: false
- name: Download Linux binaries
uses: actions/download-artifact@v4
with:
name: linux-binaries
- name: Verify architecture match
run: |
set -e
echo "Expected architecture: ${{ matrix.arch }}"
echo "Runner architecture: $(uname -m)"
echo "Go architecture: $(go env GOARCH)"
- name: Test binary execution
run: |
set -e
if [ ! -f "${{ matrix.binary }}" ]; then
echo "❌ Binary not found: ${{ matrix.binary }}"
exit 1
fi
chmod +x ${{ matrix.binary }} || {
echo "❌ Failed to make binary executable"
exit 1
}
echo "Testing ${{ matrix.binary }} on $(uname -m)..."
if ! ./${{ matrix.binary }} --help; then
echo "❌ Binary execution failed"
exit 1
fi
echo "✅ Binary execution successful"
- name: Install and test as kubectl plugin
run: |
set -e
mkdir -p /tmp/bin || {
echo "❌ Failed to create temp directory"
exit 1
}
cp ${{ matrix.binary }} /tmp/bin/kubectl-oadp || {
echo "❌ Failed to copy binary"
exit 1
}
chmod +x /tmp/bin/kubectl-oadp || {
echo "❌ Failed to make plugin executable"
exit 1
}
export PATH="/tmp/bin:$PATH"
echo "Testing kubectl plugin functionality..."
if ! kubectl-oadp --help; then
echo "❌ Plugin help failed"
exit 1
fi
if ! kubectl-oadp version --help; then
echo "❌ Plugin version help failed"
exit 1
fi
if ! kubectl-oadp nonadmin --help; then
echo "❌ Plugin nonadmin help failed"
exit 1
fi
echo "✅ kubectl plugin tests passed"
- name: Run test suite
run: |
set -e
echo "Running full test suite..."
if ! make test; then
echo "❌ Test suite failed"
exit 1
fi
echo "✅ Test suite passed"
# Test macOS binaries on native macOS runners
test-macos:
name: Test macOS
needs: build-all
strategy:
fail-fast: false
matrix:
include:
- os: macos-15-intel # Intel
arch: amd64
binary: kubectl-oadp_${{ needs.build-all.outputs.suffix }}darwin_amd64
- os: macos-latest # Apple Silicon
arch: arm64
binary: kubectl-oadp_${{ needs.build-all.outputs.suffix }}darwin_arm64
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code (for tests)
uses: actions/checkout@v4
- name: Set up Go (for running tests)
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: false
- name: Download macOS binaries
uses: actions/download-artifact@v4
with:
name: macos-binaries
- name: Verify architecture match
run: |
set -e
echo "Expected architecture: ${{ matrix.arch }}"
echo "Runner architecture: $(uname -m)"
echo "Go architecture: $(go env GOARCH)"
- name: Test binary execution
run: |
set -e
if [ ! -f "${{ matrix.binary }}" ]; then
echo "❌ Binary not found: ${{ matrix.binary }}"
exit 1
fi
chmod +x ${{ matrix.binary }} || {
echo "❌ Failed to make binary executable"
exit 1
}
echo "Testing ${{ matrix.binary }} on $(uname -m)..."
if ! ./${{ matrix.binary }} --help; then
echo "❌ Binary execution failed"
exit 1
fi
echo "✅ Binary execution successful"
- name: Install and test as kubectl plugin
run: |
set -e
mkdir -p /tmp/bin || {
echo "❌ Failed to create temp directory"
exit 1
}
cp ${{ matrix.binary }} /tmp/bin/kubectl-oadp || {
echo "❌ Failed to copy binary"
exit 1
}
chmod +x /tmp/bin/kubectl-oadp || {
echo "❌ Failed to make plugin executable"
exit 1
}
export PATH="/tmp/bin:$PATH"
echo "Testing kubectl plugin functionality..."
if ! kubectl-oadp --help; then
echo "❌ Plugin help failed"
exit 1
fi
if ! kubectl-oadp version --help; then
echo "❌ Plugin version help failed"
exit 1
fi
if ! kubectl-oadp nonadmin --help; then
echo "❌ Plugin nonadmin help failed"
exit 1
fi
echo "✅ kubectl plugin tests passed"
- name: Run test suite
run: |
set -e
echo "Running full test suite..."
if ! make test; then
echo "❌ Test suite failed"
exit 1
fi
echo "✅ Test suite passed"
# Test Windows binaries on native Windows runners
test-windows:
name: Test Windows
needs: build-all
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest # amd64
arch: amd64
binary: kubectl-oadp_${{ needs.build-all.outputs.suffix }}windows_amd64.exe
- os: windows-11-arm # arm64
arch: arm64
binary: kubectl-oadp_${{ needs.build-all.outputs.suffix }}windows_arm64.exe
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code (for tests)
uses: actions/checkout@v4
- name: Set up Go (for running tests)
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: false
- name: Download Windows binaries
uses: actions/download-artifact@v4
with:
name: windows-binaries
- name: Verify runner architecture matches binary
run: |
$ErrorActionPreference = "Stop"
echo "Expected architecture: ${{ matrix.arch }}"
echo "Runner OS: ${{ matrix.os }}"
echo "Testing binary: ${{ matrix.binary }}"
if (-not (Test-Path ${{ matrix.binary }})) {
echo "❌ Binary not found: ${{ matrix.binary }}"
exit 1
}
echo "✅ Binary found: ${{ matrix.binary }}"
- name: Test binary execution (native)
run: |
$ErrorActionPreference = "Stop"
echo "Testing ${{ matrix.binary }} on native ${{ matrix.arch }} runner..."
try {
.\${{ matrix.binary }} --help
echo "✅ Binary execution successful on ${{ matrix.arch }}"
} catch {
echo "❌ Binary execution failed: $_"
exit 1
}
- name: Install and test as kubectl plugin
run: |
$ErrorActionPreference = "Stop"
try {
New-Item -ItemType Directory -Path C:\tmp\bin -Force | Out-Null
Copy-Item ${{ matrix.binary }} C:\tmp\bin\kubectl-oadp.exe -Force
$env:PATH = "C:\tmp\bin;" + $env:PATH
echo "Testing kubectl plugin functionality on ${{ matrix.arch }}..."
kubectl-oadp --help
kubectl-oadp version --help
kubectl-oadp nonadmin --help
echo "✅ kubectl plugin tests passed on ${{ matrix.arch }}"
} catch {
echo "❌ Plugin test failed: $_"
exit 1
}
- name: Run test suite
run: |
$ErrorActionPreference = "Stop"
echo "Running full test suite..."
try {
make test
echo "✅ Test suite passed"
} catch {
echo "❌ Test suite failed: $_"
exit 1
}
# Summary
test-summary:
name: Test Summary
runs-on: ubuntu-latest
needs: [build-all, test-linux, test-macos, test-windows]
if: always()
steps:
- name: Check all results
run: |
set -e
echo "=== Cross-Architecture Build & Test Summary ==="
echo ""
# Track overall success
overall_success=true
if [ "${{ needs.build-all.result }}" = "success" ]; then
echo "✅ Multi-arch build: PASSED"
else
echo "❌ Multi-arch build: FAILED"
overall_success=false
fi
if [ "${{ needs.test-linux.result }}" = "success" ]; then
echo "✅ Linux tests (amd64 + arm64): PASSED"
else
echo "❌ Linux tests: FAILED"
overall_success=false
fi
if [ "${{ needs.test-macos.result }}" = "success" ]; then
echo "✅ macOS tests (Intel + Apple Silicon): PASSED"
else
echo "❌ macOS tests: FAILED"
overall_success=false
fi
if [ "${{ needs.test-windows.result }}" = "success" ]; then
echo "✅ Windows tests (amd64 + arm64 native): PASSED"
else
echo "❌ Windows tests: FAILED"
overall_success=false
fi
echo ""
if [ "$overall_success" = "true" ]; then
echo "🎉 All cross-architecture builds and tests successful!"
echo " Validated: Linux (amd64/arm64 native), macOS (Intel/Apple Silicon native), Windows (amd64/arm64 native)"
exit 0
else
echo "💥 Some builds or tests failed - check the logs above"
exit 1
fi