Skip to content

Add separate github workflow for azl3 raw image build #9

Add separate github workflow for azl3 raw image build

Add separate github workflow for azl3 raw image build #9

name: Unit and Coverage
on:
pull_request:
branches: [ main ] # Gate PRs into main
push:
branches: [ main ] # also run on direct pushes
workflow_dispatch: # Manual runs
inputs:
ref:
description: "Branch or SHA to test (e.g. feature/x or a1b2c3)"
required: false
cov_threshold:
description: "Override threshold (percent) for this manual run only"
required: false
concurrency:
group: earthly-tests-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
run-earthly-tests:
name: Run earthly +test (coverage gate)
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
# Use input ref if provided; else PR head SHA; else current SHA
ref: ${{ inputs.ref != '' && inputs.ref || (github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha) }}
- name: Setup Earthly
uses: earthly/actions/setup-earthly@v1
with:
version: "latest"
- name: Show Earthly version
run: earthly --version
- name: Resolve coverage threshold
id: threshold
env:
MANUAL_COV: ${{ inputs.cov_threshold }}
run: |
set -euo pipefail
# Default threshold (matches script default)
DEFAULT="12.3"
# Use manual override if provided, otherwise use default
if [[ -n "${MANUAL_COV:-}" ]]; then
HEAD_VAL="${MANUAL_COV}"
echo "Using manual threshold override: ${HEAD_VAL}%"
else
HEAD_VAL="$DEFAULT"
echo "Using default threshold: ${HEAD_VAL}%"
fi
# Set environment variables for subsequent steps
echo "COV_THRESHOLD=${HEAD_VAL}" >> "$GITHUB_ENV"
echo "PRINT_TS=${GITHUB_RUN_ID}" >> "$GITHUB_ENV"
echo "FAIL_ON_NO_TESTS=false" >> "$GITHUB_ENV"
echo "Resolved threshold: ${HEAD_VAL}%"
echo "Build ID: ${GITHUB_RUN_ID}"
# Run standard tests with coverage
- name: Run Earthly +test with coverage threshold
run: |
earthly +test --COV_THRESHOLD="${COV_THRESHOLD}" --PRINT_TS="${PRINT_TS}" --FAIL_ON_NO_TESTS="${FAIL_ON_NO_TESTS}"
# Upload main coverage artifacts (always generated by script)
- name: Upload main coverage artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-reports
path: |
coverage.out
coverage_total.txt
coverage_packages.txt
test_raw.log
# Upload detailed per-directory artifacts for debugging
- name: Upload per-directory coverage artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: per-directory-coverage
path: |
*_coverage.out
*_test.log
overall_coverage.out
combined_coverage.out
overall_test.log
overall_test_with_failures.log
if-no-files-found: ignore
# Legacy individual uploads for backward compatibility
- name: Upload coverage.out (legacy)
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage.out
path: coverage.out
if-no-files-found: warn
- name: Upload coverage_total.txt (legacy)
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage_total.txt
path: coverage_total.txt
if-no-files-found: warn
- name: Upload coverage_packages.txt (legacy)
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage_packages.txt
path: coverage_packages.txt
if-no-files-found: warn
- name: Upload test_raw.log (legacy)
if: always()
uses: actions/upload-artifact@v4
with:
name: test_raw.log
path: test_raw.log
if-no-files-found: warn
- name: Publish coverage summary
if: always()
run: |
{
echo "## Coverage Summary"
if [[ -f coverage_total.txt ]]; then
echo ""
echo '```'
cat coverage_total.txt
echo '```'
fi
if [[ -f coverage_packages.txt ]]; then
echo ""
echo "Packages by coverage (lowest first):"
echo '```'
head -n 50 coverage_packages.txt || true
echo '```'
fi
echo ""
echo "**Threshold used:** ${COV_THRESHOLD}%"
echo "**Build ID:** ${PRINT_TS}"
echo "**Test method:** Per-directory coverage with script-based execution"
# Add directory-level summary if available
if [[ -f coverage_total.txt ]] && grep -q "| Directory" coverage_total.txt; then
echo ""
echo "### Directory Test Results"
echo '```'
grep -A 100 "| Directory" coverage_total.txt | head -n 50 || true
echo '```'
fi
} >> "$GITHUB_STEP_SUMMARY"
# Debug job for troubleshooting (runs on manual trigger with failures)
run-earthly-tests-debug:
name: Run earthly +test-debug (enhanced debugging)
runs-on: ubuntu-latest
timeout-minutes: 45
if: failure() && github.event_name == 'workflow_dispatch'
needs: run-earthly-tests
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
ref: ${{ inputs.ref != '' && inputs.ref || (github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha) }}
- name: Setup Earthly
uses: earthly/actions/setup-earthly@v1
with:
version: "latest"
- name: Run Earthly +test-debug with enhanced output
env:
COV_THRESHOLD: ${{ inputs.cov_threshold || '12.3' }}
PRINT_TS: ${{ github.run_id }}
FAIL_ON_NO_TESTS: "false"
run: |
earthly +test-debug --COV_THRESHOLD="${COV_THRESHOLD}" --PRINT_TS="${PRINT_TS}" --FAIL_ON_NO_TESTS="${FAIL_ON_NO_TESTS}"
- name: Upload all debug artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: debug-coverage-artifacts
path: |
coverage.out
coverage_total.txt
coverage_packages.txt
test_raw.log
*_coverage.out
*_test.log
overall_coverage.out
combined_coverage.out
overall_test.log
overall_test_with_failures.log
if-no-files-found: ignore
- name: Show debug summary
if: always()
run: |
echo "=== Debug Coverage Analysis ==="
echo "Files generated:"
ls -la *.out *.txt *.log || true
echo ""
echo "Directory structure:"
find . -name "*coverage*" -o -name "*test*.log" | head -20 || true