Repository navigation
Clear custom-linter findings in pkg/cli logs and audit files #36317
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CGO | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - '**/*.go' | |
| - 'cmd/**' | |
| - 'pkg/**' | |
| - 'scripts/**' | |
| - 'go.mod' | |
| - 'go.sum' | |
| - 'Makefile' | |
| - 'actions/setup/sh/**' | |
| - '.github/workflows/ci.yml' | |
| - '.github/workflows/cgo.yml' | |
| - '.github/workflows/requirements-pageindex.txt' | |
| - '.github/workflows/shared/pageindex.md' | |
| - '.github/workflows/CWI.yml' | |
| - '.github/workflows/license-check.yml' | |
| - '.github/aw/releases.json' | |
| - '.github/aw/releases.schema.json' | |
| - '.github/aw/compat.json' | |
| - '.github/aw/compat.schema.json' | |
| - '.github/ci/**' | |
| - '.github/workflows/ci-front-door-researcher.*' | |
| - 'install-gh-aw.sh' | |
| pull_request: | |
| types: [opened, synchronize, reopened, ready_for_review] | |
| paths: | |
| - '**/*.go' | |
| - 'cmd/**' | |
| - 'pkg/**' | |
| - 'scripts/**' | |
| - 'go.mod' | |
| - 'go.sum' | |
| - 'Makefile' | |
| - 'actions/setup/sh/**' | |
| - '.github/workflows/ci.yml' | |
| - '.github/workflows/cgo.yml' | |
| - '.github/workflows/requirements-pageindex.txt' | |
| - '.github/workflows/shared/pageindex.md' | |
| - '.github/workflows/CWI.yml' | |
| - '.github/workflows/license-check.yml' | |
| - '.github/aw/releases.json' | |
| - '.github/aw/releases.schema.json' | |
| - '.github/aw/compat.json' | |
| - '.github/aw/compat.schema.json' | |
| - '.github/ci/**' | |
| - '.github/workflows/ci-front-door-researcher.*' | |
| - 'install-gh-aw.sh' | |
| schedule: | |
| # Independent full-suite control: never use the Decision API on scheduled runs. | |
| - cron: '23 4 * * 1' | |
| workflow_dispatch: | |
| jobs: | |
| test-pageindex-workflow: | |
| name: PageIndex hash-locked install and tests | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| persist-credentials: false | |
| - name: Set up uv | |
| # zizmor: ignore[github_action_from_unverified_creator_used] | |
| uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 | |
| with: | |
| version: "0.13.7" | |
| enable-cache: false | |
| - name: Verify locked install and run PageIndex workflow tests | |
| run: make test-pageindex-workflow | |
| checkout-cache: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| permissions: | |
| contents: read | |
| outputs: | |
| dependencies-changed: ${{ steps.dependencies.outputs.changed }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| # Keep the PR merge commit and its base parent for incremental linting. | |
| fetch-depth: 2 | |
| persist-credentials: false | |
| - name: Check Go dependency changes | |
| id: dependencies | |
| shell: bash | |
| run: | | |
| if git diff --quiet HEAD^ HEAD -- go.mod go.sum; then | |
| echo "changed=false" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Verify CGO/CJS workflow purity | |
| run: bash scripts/check-cgo-cjs-workflow-purity.sh | |
| - name: Test workflow timing summaries | |
| run: node --test scripts/workflow-timing.test.cjs | |
| - name: Cache repository checkout | |
| uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: . | |
| # Keep reservations and cleanup isolated from other runs of this commit. | |
| key: checkout-cgo-${{ github.run_id }}-${{ github.sha }} | |
| front-door-decision: | |
| if: github.event_name == 'pull_request' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| permissions: | |
| contents: read | |
| copilot-requests: write | |
| outputs: | |
| suite_ids: ${{ steps.validated.outputs.suite_ids }} | |
| metrics: ${{ steps.front-door.outputs.metrics }} | |
| steps: | |
| - name: Checkout trusted selector | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.event.pull_request.base.sha }} | |
| path: trusted | |
| fetch-depth: 1 | |
| persist-credentials: false | |
| sparse-checkout-cone-mode: false | |
| sparse-checkout: | | |
| /scripts/ci-front-door.cjs | |
| /scripts/ci-front-door-diff.cjs | |
| /actions/setup/js/decisions_client.cjs | |
| /.github/ci/suite-catalog.json | |
| /.github/ci/decision-prompt.txt | |
| - name: Select CI suites with GitHub Decisions | |
| # Never bootstrap a missing trusted selector from PR-controlled code. | |
| if: hashFiles('trusted/scripts/ci-front-door.cjs') != '' | |
| id: front-door | |
| continue-on-error: true | |
| working-directory: trusted | |
| env: | |
| CI_DECISION_TOKEN: ${{ github.token }} | |
| # Compare immutable event SHAs without checking out PR-controlled files. | |
| CI_DIFF_TOKEN: ${{ github.token }} | |
| CI_DIFF_BASE_SHA: ${{ github.event.pull_request.base.sha }} | |
| CI_DIFF_HEAD_SHA: ${{ github.sha }} | |
| run: node scripts/ci-front-door.cjs | |
| - name: Validate suite outputs | |
| id: validated | |
| env: | |
| SELECTOR_OUTCOME: ${{ steps.front-door.outcome }} | |
| RAW_SUITE_IDS: ${{ steps.front-door.outputs.suite_ids }} | |
| run: | | |
| node <<'NODE' | |
| const fs = require('node:fs'); | |
| const known = ['front-door-conformance', 'verify-integration-build', 'test', 'test-slow', 'canary-go', 'impacted-go-tests', 'native-javascript-tests', 'build', 'build-wasm', 'validate-yaml', 'check-validator-sizes', 'lint-go-format', 'lint-go-golangci', 'lint-go-govulncheck', 'lint-go-custom', 'lint-error-messages', 'actions-build', 'fuzz', 'security', 'security-scan', 'mcp-server-compile-test', 'cross-platform-build', 'alpine-container-test', 'safe-outputs-conformance']; | |
| const dependencies = {test: ['verify-integration-build'], 'test-slow': ['verify-integration-build'], 'canary-go': ['test', 'test-slow'], security: ['build'], 'security-scan': ['build'], 'cross-platform-build': ['build']}; | |
| let suiteIds = ''; | |
| try { | |
| const ids = JSON.parse(process.env.RAW_SUITE_IDS); | |
| if (process.env.SELECTOR_OUTCOME === 'success' && Array.isArray(ids) && | |
| ids.includes('test') && ids.length <= known.length && new Set(ids).size === ids.length && | |
| ids.every(id => known.includes(id) && (dependencies[id] || []).every(dependency => ids.includes(dependency)))) { | |
| suiteIds = JSON.stringify(ids); | |
| } | |
| } catch (error) { | |
| if (!(error instanceof SyntaxError)) throw error; | |
| } | |
| if (!suiteIds) process.stderr.write('CI Front Door outputs unavailable or invalid; running all suites.\n'); | |
| fs.appendFileSync(process.env.GITHUB_OUTPUT, `suite_ids=${suiteIds}\n`); | |
| NODE | |
| front-door-conformance: | |
| needs: [front-door-decision] | |
| if: always() && !cancelled() && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'front-door-conformance')) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| fetch-depth: 2 | |
| persist-credentials: false | |
| - name: Test CI Front Door conformance | |
| run: | | |
| node --test scripts/ci-front-door.test.cjs | |
| node --test scripts/ci-front-door-researcher.test.cjs | |
| node --test scripts/ci-front-door-workflow.test.cjs | |
| node --test scripts/go-unit-suite.test.cjs | |
| verify-integration-build: | |
| needs: [checkout-cache, front-door-decision] | |
| if: always() && !cancelled() && needs.checkout-cache.result == 'success' && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'verify-integration-build')) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ci-${{ github.ref }}-verify-integration-build | |
| cancel-in-progress: true | |
| steps: | |
| - name: Restore checkout | |
| id: restore-checkout | |
| uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: . | |
| key: checkout-cgo-${{ github.run_id }}-${{ github.sha }} | |
| - name: Checkout on cache miss | |
| if: steps.restore-checkout.outputs.cache-hit != 'true' | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.sha }} | |
| fetch-depth: 2 | |
| persist-credentials: false | |
| - name: Set up Go | |
| id: setup-go | |
| uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v6 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Report Go cache status | |
| run: | | |
| if [ "${{ steps.setup-go.outputs.cache-hit }}" == "true" ]; then | |
| echo "✅ Go cache hit" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "⚠️ Go cache miss" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| - name: Download dependencies with retry | |
| if: steps.setup-go.outputs.cache-hit != 'true' | |
| run: | | |
| set -e | |
| MAX_RETRIES=3 | |
| RETRY_DELAY=5 | |
| for i in $(seq 1 $MAX_RETRIES); do | |
| echo "Attempt $i of $MAX_RETRIES: Downloading Go modules..." | |
| # Use -x for verbose output to see what's being downloaded | |
| if go mod download -x; then | |
| echo "✅ Successfully downloaded Go modules" | |
| break | |
| else | |
| EXIT_CODE=$? | |
| if [ $i -eq $MAX_RETRIES ]; then | |
| echo "❌ Failed to download Go modules after $MAX_RETRIES attempts (exit code: $EXIT_CODE)" | |
| echo "This indicates that proxy.golang.org is unreachable or returning errors" | |
| echo "" | |
| echo "Diagnostic information:" | |
| echo "- GOPROXY: $(go env GOPROXY)" | |
| echo "- GOSUMDB: $(go env GOSUMDB)" | |
| echo "- Network connectivity: checking proxy.golang.org..." | |
| if curl -s -I --connect-timeout 5 https://proxy.golang.org/golang.org/@v/list >/dev/null 2>&1; then | |
| echo " ✓ proxy.golang.org is reachable" | |
| else | |
| echo " ✗ proxy.golang.org is NOT reachable" | |
| fi | |
| exit 1 | |
| fi | |
| echo "⚠️ Download failed, retrying in ${RETRY_DELAY}s..." | |
| sleep $RETRY_DELAY | |
| fi | |
| done | |
| - name: Verify dependencies | |
| run: go mod verify | |
| - name: Verify integration build | |
| run: | | |
| # Compile and link all integration-tagged test binaries without | |
| # executing package test binaries or TestMain side effects. | |
| # Regular unit tests use -tags '!integration', so build errors in | |
| # integration-tagged files (e.g. unused imports) would otherwise | |
| # go undetected until the fuzz job runs on main. | |
| go test -run='^$' -exec=true -tags=integration ./... | |
| test: | |
| name: Fast unit tests (${{ matrix.name }}) | |
| if: always() && !cancelled() && needs.checkout-cache.result == 'success' && needs.verify-integration-build.result == 'success' && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'test')) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| needs: | |
| - checkout-cache | |
| - verify-integration-build | |
| - front-door-decision | |
| permissions: | |
| contents: read | |
| env: | |
| UNIT_TEST_SUITE: fast | |
| UNIT_TEST_TIMEOUT: 3m | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - name: A | |
| pattern: ^TestA | |
| shard: a | |
| - name: B | |
| pattern: ^TestB | |
| shard: b | |
| - name: C | |
| pattern: ^TestC | |
| shard: c | |
| - name: D | |
| pattern: ^TestD | |
| shard: d | |
| - name: E-G | |
| pattern: ^Test[E-G] | |
| shard: e-g | |
| - name: H-J | |
| pattern: ^Test[H-J] | |
| shard: h-j | |
| - name: K-M | |
| pattern: ^Test[K-M] | |
| shard: k-m | |
| - name: N-R | |
| pattern: ^Test[N-R] | |
| shard: n-r | |
| - name: S | |
| pattern: ^TestS | |
| shard: s | |
| - name: T | |
| pattern: ^TestT | |
| shard: t | |
| - name: U-V | |
| pattern: ^Test[U-V] | |
| shard: u-v | |
| - name: W-Z and other | |
| pattern: ^Test([W-Z]|[^A-V]) | |
| shard: w-z | |
| concurrency: | |
| group: ci-${{ github.ref }}-test-${{ matrix.shard }} | |
| cancel-in-progress: true | |
| steps: &unit-test-steps | |
| - name: Restore checkout | |
| id: restore-checkout | |
| uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: . | |
| key: checkout-cgo-${{ github.run_id }}-${{ github.sha }} | |
| - name: Checkout on cache miss | |
| if: steps.restore-checkout.outputs.cache-hit != 'true' | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.sha }} | |
| fetch-depth: 2 | |
| persist-credentials: false | |
| - name: Set up Go | |
| id: setup-go | |
| uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v6 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Report Go cache status | |
| run: | | |
| if [ "${{ steps.setup-go.outputs.cache-hit }}" == "true" ]; then | |
| echo "✅ Go cache hit" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "⚠️ Go cache miss" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| - name: Display Go environment | |
| run: | | |
| echo "Go environment:" | |
| go env | grep -E "GOPROXY|GOSUMDB|GOMODCACHE|GOPRIVATE" | |
| echo "" | |
| echo "Module cache location: $(go env GOMODCACHE)" | |
| - name: Download dependencies with retry | |
| if: steps.setup-go.outputs.cache-hit != 'true' | |
| run: | | |
| set -e | |
| MAX_RETRIES=3 | |
| RETRY_DELAY=5 | |
| for i in $(seq 1 $MAX_RETRIES); do | |
| echo "Attempt $i of $MAX_RETRIES: Downloading Go modules..." | |
| # Use -x for verbose output to see what's being downloaded | |
| if go mod download -x; then | |
| echo "✅ Successfully downloaded Go modules" | |
| break | |
| else | |
| EXIT_CODE=$? | |
| if [ $i -eq $MAX_RETRIES ]; then | |
| echo "❌ Failed to download Go modules after $MAX_RETRIES attempts (exit code: $EXIT_CODE)" | |
| echo "This indicates that proxy.golang.org is unreachable or returning errors" | |
| echo "" | |
| echo "Diagnostic information:" | |
| echo "- GOPROXY: $(go env GOPROXY)" | |
| echo "- GOSUMDB: $(go env GOSUMDB)" | |
| echo "- Network connectivity: checking proxy.golang.org..." | |
| if curl -s -I --connect-timeout 5 https://proxy.golang.org/golang.org/@v/list >/dev/null 2>&1; then | |
| echo " ✓ proxy.golang.org is reachable" | |
| else | |
| echo " ✗ proxy.golang.org is NOT reachable" | |
| fi | |
| exit 1 | |
| fi | |
| echo "⚠️ Download failed, retrying in ${RETRY_DELAY}s..." | |
| sleep $RETRY_DELAY | |
| fi | |
| done | |
| - name: Verify dependencies | |
| run: go mod verify | |
| - name: Pre-flight check - Validate test dependencies | |
| run: | | |
| echo "Validating that test dependencies are available..." | |
| echo "This ensures go test can compile test packages without network access." | |
| echo "" | |
| # List all test dependencies to ensure they're in the cache | |
| # This will fail fast if any dependencies are missing | |
| echo "Checking test dependencies for all packages..." | |
| if go list -test -deps ./... >/dev/null 2>&1; then | |
| echo "✅ All test dependencies are available" | |
| else | |
| echo "❌ Failed to resolve test dependencies" | |
| echo "" | |
| echo "Attempting to show which dependencies are missing:" | |
| go list -test -deps ./... 2>&1 || true | |
| exit 1 | |
| fi | |
| echo "" | |
| echo "Module cache statistics:" | |
| echo "- Cache directory: $(go env GOMODCACHE)" | |
| if [ -d "$(go env GOMODCACHE)" ]; then | |
| echo "- Cache size: $(du -sh $(go env GOMODCACHE) 2>/dev/null | cut -f1 || echo 'unknown')" | |
| echo "- Number of cached modules: $(find $(go env GOMODCACHE) -name "go.mod" 2>/dev/null | wc -l || echo 'unknown')" | |
| fi | |
| - name: Run unit tests with coverage | |
| id: run-unit-tests | |
| env: | |
| TEST_PATTERN: ${{ matrix.pattern }} | |
| run: | | |
| set -o pipefail | |
| if [ "$UNIT_TEST_SUITE" = "fast" ]; then | |
| slow_pattern=$(node scripts/go-unit-suite.cjs) | |
| selection=(-run "$TEST_PATTERN" -skip "$slow_pattern") | |
| elif [ "$UNIT_TEST_SUITE" = "slow" ]; then | |
| slow_pattern=$(node scripts/go-unit-suite.cjs "$TEST_PATTERN") | |
| selection=(-run "$slow_pattern") | |
| else | |
| echo "Unknown unit-test suite: $UNIT_TEST_SUITE" >&2 | |
| exit 1 | |
| fi | |
| # Run tests with JSON output for artifacts, but also show failures | |
| if ! go test -v -parallel=8 -timeout="$UNIT_TEST_TIMEOUT" "${selection[@]}" -tags '!integration' -coverprofile=coverage-${{ matrix.shard }}.out -json ./... > test-result-unit-${{ matrix.shard }}.json; then | |
| cat test-result-unit-${{ matrix.shard }}.json | |
| exit 1 | |
| fi | |
| cat test-result-unit-${{ matrix.shard }}.json | |
| # Generate coverage HTML report | |
| go tool cover -html=coverage-${{ matrix.shard }}.out -o coverage-${{ matrix.shard }}.html | |
| - name: Report test failures | |
| if: failure() && steps.run-unit-tests.outcome == 'failure' | |
| run: | | |
| echo "## 🔍 Unit Test Failure Analysis" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "Analyzing unit test results" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| # Run the failure report script | |
| if ./scripts/report-test-failures.sh test-result-unit-${{ matrix.shard }}.json | tee /tmp/failure-report.txt; then | |
| echo "No failures detected in JSON output (unexpected - tests failed but no failure records found)" >> $GITHUB_STEP_SUMMARY | |
| else | |
| # Script found failures - add to summary | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
| cat /tmp/failure-report.txt >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| # Coverage reports for recent builds only - 7 days is sufficient for debugging recent changes | |
| - name: Upload coverage report | |
| uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 | |
| with: | |
| name: coverage-report-${{ matrix.shard }} | |
| path: coverage-${{ matrix.shard }}.html | |
| retention-days: 7 | |
| - name: Upload unit test results | |
| if: always() # Upload even if tests fail so canary-go can track coverage | |
| uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 | |
| with: | |
| name: test-result-cgo-unit-${{ matrix.shard }} | |
| path: test-result-unit-${{ matrix.shard }}.json | |
| retention-days: 7 | |
| test-slow: | |
| name: Slow unit tests (${{ matrix.name }}) | |
| if: always() && !cancelled() && needs.checkout-cache.result == 'success' && needs.verify-integration-build.result == 'success' && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'test-slow')) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| needs: | |
| - checkout-cache | |
| - verify-integration-build | |
| - front-door-decision | |
| permissions: | |
| contents: read | |
| env: | |
| UNIT_TEST_SUITE: slow | |
| UNIT_TEST_TIMEOUT: 5m | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - name: Repository sweeps | |
| pattern: repository | |
| shard: slow-repository | |
| - name: Azure runtime | |
| pattern: workflow-azure | |
| shard: slow-workflow-azure | |
| - name: Workflow readers | |
| pattern: workflow-readers | |
| shard: slow-workflow-readers | |
| - name: CLI, parser and workqueue | |
| pattern: cli-parser-workqueue | |
| shard: slow-cli-parser-workqueue | |
| concurrency: | |
| group: ci-${{ github.ref }}-test-${{ matrix.shard }} | |
| cancel-in-progress: true | |
| steps: *unit-test-steps | |
| canary-go: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| needs: | |
| - checkout-cache | |
| - test | |
| - test-slow | |
| - front-door-decision | |
| if: always() && !cancelled() && needs.checkout-cache.result == 'success' && needs.test.result == 'success' && needs.test-slow.result == 'success' && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'canary-go')) | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Restore checkout | |
| id: restore-checkout | |
| uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: . | |
| key: checkout-cgo-${{ github.run_id }}-${{ github.sha }} | |
| - name: Checkout on cache miss | |
| if: steps.restore-checkout.outputs.cache-hit != 'true' | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.sha }} | |
| fetch-depth: 2 | |
| persist-credentials: false | |
| - name: List unit tests in codebase | |
| run: | | |
| set -euo pipefail | |
| echo "Extracting unit test function names from source files..." | |
| go test -list='^Test' -tags '!integration' ./... 2>/dev/null | grep '^Test[A-Z]' | grep -v '^TestMain$' | sort -u > all-tests.txt | |
| echo "Found $(wc -l < all-tests.txt) unit tests in codebase" | |
| - name: Download unit test result artifacts | |
| uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 | |
| with: | |
| path: test-results | |
| pattern: test-result-cgo-unit-* | |
| merge-multiple: false | |
| - name: List downloaded artifacts | |
| run: | | |
| set -euo pipefail | |
| echo "Downloaded unit test result artifacts:" | |
| find test-results -type f -name "*.json" | sort | |
| echo "" | |
| echo "Total JSON files: $(find test-results -type f -name \"*.json\" | wc -l)" | |
| - name: Validate pkg/cli and pkg/console tests executed | |
| run: | | |
| set -euo pipefail | |
| for package in pkg/cli pkg/console; do | |
| if ! grep -R -q "\"Action\":\"run\",\"Package\":\"github.com/github/gh-aw/${package}\"" test-results; then | |
| echo "Missing unit test execution records for ${package}" >&2 | |
| exit 1 | |
| fi | |
| done | |
| - name: Extract executed tests from artifacts | |
| run: | | |
| set -euo pipefail | |
| echo "Extracting test names from JSON artifacts..." | |
| ./scripts/extract-executed-tests.sh test-results > executed-tests.txt | |
| echo "Found $(wc -l < executed-tests.txt) executed tests" | |
| - name: Compare test coverage | |
| run: | | |
| ./scripts/compare-test-coverage.sh all-tests.txt executed-tests.txt | |
| - name: Upload test coverage report | |
| if: always() | |
| uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 | |
| with: | |
| name: test-coverage-analysis-cgo | |
| path: | | |
| all-tests.txt | |
| executed-tests.txt | |
| retention-days: 7 | |
| impacted-go-tests: | |
| needs: [checkout-cache, front-door-decision] | |
| if: always() && !cancelled() && needs.checkout-cache.result == 'success' && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'impacted-go-tests')) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ci-${{ github.ref }}-impacted-go-tests | |
| cancel-in-progress: true | |
| steps: | |
| - name: Restore checkout | |
| id: restore-checkout | |
| uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: . | |
| key: checkout-cgo-${{ github.run_id }}-${{ github.sha }} | |
| - name: Checkout on cache miss | |
| if: steps.restore-checkout.outputs.cache-hit != 'true' | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.sha }} | |
| fetch-depth: 2 | |
| persist-credentials: false | |
| - name: Set up Go | |
| uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v6 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Run impacted Go unit tests | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: make test-impacted-go BASE_REF=HEAD^ CI_COVERAGE_SOURCE_BRANCH=main | |
| native-javascript-tests: | |
| name: Native JavaScript and Actions parser tests | |
| needs: [checkout-cache, front-door-decision] | |
| if: always() && !cancelled() && needs.checkout-cache.result == 'success' && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'native-javascript-tests')) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ci-${{ github.ref }}-native-javascript-tests | |
| cancel-in-progress: true | |
| steps: | |
| - name: Restore checkout | |
| id: restore-checkout | |
| uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: . | |
| key: checkout-cgo-${{ github.run_id }}-${{ github.sha }} | |
| - name: Checkout on cache miss | |
| if: steps.restore-checkout.outputs.cache-hit != 'true' | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.sha }} | |
| fetch-depth: 2 | |
| persist-credentials: false | |
| - name: Set up Go | |
| uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v6 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Set up Node.js | |
| uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v6 | |
| with: | |
| node-version: "24" | |
| cache: npm | |
| cache-dependency-path: | | |
| pkg/workflow/taint/javascript/package-lock.json | |
| pkg/workflow/actionslanguageservice/conformance/package-lock.json | |
| - name: Install pinned native JavaScript compiler | |
| run: npm ci --prefix pkg/workflow/taint/javascript --ignore-scripts --no-audit --no-fund | |
| - name: Run native JavaScript analysis regressions | |
| run: | | |
| go test -v -count=1 -timeout=5m ./pkg/workflow/taint | |
| go test -v -count=1 -timeout=5m ./pkg/cli -run '^(TestJavaScriptLint|TestLintInputParseFailuresPreserveOtherAST)' | |
| - name: Install pinned official Actions parsers | |
| run: npm ci --prefix pkg/workflow/actionslanguageservice/conformance --ignore-scripts --no-audit --no-fund | |
| - name: Compare native Go and official Actions parsers | |
| run: make test-actions-parser-conformance | |
| build: | |
| needs: [checkout-cache, front-door-decision] | |
| if: always() && !cancelled() && needs.checkout-cache.result == 'success' && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'build')) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ci-${{ github.ref }}-build | |
| cancel-in-progress: true | |
| steps: | |
| - name: Restore checkout | |
| id: restore-checkout | |
| uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: . | |
| key: checkout-cgo-${{ github.run_id }}-${{ github.sha }} | |
| - name: Checkout on cache miss | |
| if: steps.restore-checkout.outputs.cache-hit != 'true' | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.sha }} | |
| fetch-depth: 2 | |
| persist-credentials: false | |
| - name: Set up Node.js | |
| id: setup-node | |
| uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v6 | |
| with: | |
| node-version: "24" | |
| cache: npm | |
| cache-dependency-path: actions/setup/js/package-lock.json | |
| - name: Report Node cache status | |
| run: | | |
| if [ "${{ steps.setup-node.outputs.cache-hit }}" == "true" ]; then | |
| echo "✅ Node cache hit" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "⚠️ Node cache miss" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| - name: Set up Go | |
| id: setup-go | |
| uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v6 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Report Go cache status | |
| run: | | |
| if [ "${{ steps.setup-go.outputs.cache-hit }}" == "true" ]; then | |
| echo "✅ Go cache hit" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "⚠️ Go cache miss" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| - name: npm ci | |
| run: npm ci | |
| working-directory: ./actions/setup/js | |
| - name: Build code | |
| run: make build | |
| - name: Upload Linux binary | |
| uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 | |
| with: | |
| name: gh-aw-linux-amd64 | |
| path: gh-aw | |
| retention-days: 7 | |
| - name: Report binary download instructions | |
| run: | | |
| RUN_ID="${{ github.run_id }}" | |
| REPO="${{ github.repository }}" | |
| SHA="${{ github.sha }}" | |
| echo "## 📦 gh-aw Binary" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "The \`gh-aw\` Linux (amd64) binary has been uploaded as an artifact." >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### Download with GitHub CLI" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY | |
| echo "gh run download ${RUN_ID} --repo ${REPO} --name gh-aw-linux-amd64" >> $GITHUB_STEP_SUMMARY | |
| echo "chmod +x gh-aw" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### Download with curl" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY | |
| echo "# Requires a GitHub token with actions:read scope" >> $GITHUB_STEP_SUMMARY | |
| echo "ARTIFACT_ID=\$(curl -fsSL -H \"Authorization: Bearer \$GH_TOKEN\" \\" >> $GITHUB_STEP_SUMMARY | |
| echo " \"https://api.github.com/repos/${REPO}/actions/runs/${RUN_ID}/artifacts\" \\" >> $GITHUB_STEP_SUMMARY | |
| echo " | jq -r '.artifacts[] | select(.name==\"gh-aw-linux-amd64\") | .id')" >> $GITHUB_STEP_SUMMARY | |
| echo "curl -fsSL -H \"Authorization: Bearer \$GH_TOKEN\" \\" >> $GITHUB_STEP_SUMMARY | |
| echo " -L \"https://api.github.com/repos/${REPO}/actions/artifacts/\$ARTIFACT_ID/zip\" \\" >> $GITHUB_STEP_SUMMARY | |
| echo " -o gh-aw-linux-amd64.zip" >> $GITHUB_STEP_SUMMARY | |
| echo "unzip gh-aw-linux-amd64.zip && chmod +x gh-aw" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### Recompile workflows with this build" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY | |
| echo "./gh-aw compile --action-mode release --action-tag ${SHA}" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
| - name: Rebuild lock files | |
| run: make recompile | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| build-wasm: | |
| needs: [checkout-cache, front-door-decision] | |
| if: always() && !cancelled() && needs.checkout-cache.result == 'success' && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'build-wasm')) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ci-${{ github.ref }}-build-wasm | |
| cancel-in-progress: true | |
| steps: | |
| - name: Restore checkout | |
| id: restore-checkout | |
| uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: . | |
| key: checkout-cgo-${{ github.run_id }}-${{ github.sha }} | |
| - name: Checkout on cache miss | |
| if: steps.restore-checkout.outputs.cache-hit != 'true' | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.sha }} | |
| fetch-depth: 2 | |
| persist-credentials: false | |
| - name: Set up Go | |
| id: setup-go | |
| uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v6 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Report Go cache status | |
| run: | | |
| if [ "${{ steps.setup-go.outputs.cache-hit }}" == "true" ]; then | |
| echo "✅ Go cache hit" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "⚠️ Go cache miss" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| - name: Download dependencies with retry | |
| if: steps.setup-go.outputs.cache-hit != 'true' | |
| run: | | |
| set -e | |
| MAX_RETRIES=3 | |
| RETRY_DELAY=5 | |
| for i in $(seq 1 $MAX_RETRIES); do | |
| echo "Attempt $i of $MAX_RETRIES: Downloading Go modules..." | |
| # Use -x for verbose output to see what's being downloaded | |
| if go mod download -x; then | |
| echo "✅ Successfully downloaded Go modules" | |
| break | |
| else | |
| EXIT_CODE=$? | |
| if [ $i -eq $MAX_RETRIES ]; then | |
| echo "❌ Failed to download Go modules after $MAX_RETRIES attempts (exit code: $EXIT_CODE)" | |
| echo "This indicates that proxy.golang.org is unreachable or returning errors" | |
| echo "" | |
| echo "Diagnostic information:" | |
| echo "- GOPROXY: $(go env GOPROXY)" | |
| echo "- GOSUMDB: $(go env GOSUMDB)" | |
| echo "- Network connectivity: checking proxy.golang.org..." | |
| if curl -s -I --connect-timeout 5 https://proxy.golang.org/golang.org/@v/list >/dev/null 2>&1; then | |
| echo " ✓ proxy.golang.org is reachable" | |
| else | |
| echo " ✗ proxy.golang.org is NOT reachable" | |
| fi | |
| exit 1 | |
| fi | |
| echo "⚠️ Download failed, retrying in ${RETRY_DELAY}s..." | |
| sleep $RETRY_DELAY | |
| fi | |
| done | |
| - name: Verify dependencies | |
| run: go mod verify | |
| - name: Build WebAssembly binary | |
| run: make build-wasm | |
| - name: Report binary size | |
| run: | | |
| echo "## WebAssembly Build" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| if ls gh-aw.wasm 1>/dev/null 2>&1; then | |
| SIZE=$(stat --format="%s" gh-aw.wasm) | |
| SIZE_MB=$(awk "BEGIN {printf \"%.2f\", $SIZE/1048576}") | |
| echo "✅ Build succeeded" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Binary:** gh-aw.wasm" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Size:** ${SIZE_MB} MB (${SIZE} bytes)" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "❌ No .wasm binary found" >> $GITHUB_STEP_SUMMARY | |
| ls -la *.wasm 2>/dev/null || echo "No wasm files in working directory" >> $GITHUB_STEP_SUMMARY | |
| exit 1 | |
| fi | |
| - name: Run wasm golden tests (Go string API) | |
| run: make test-wasm-golden | |
| - name: Set up Node.js | |
| uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v6 | |
| with: | |
| node-version: '24' | |
| - name: Run wasm binary golden tests (Node.js) | |
| run: node scripts/test-wasm-golden.mjs | |
| validate-yaml: | |
| needs: [checkout-cache, front-door-decision] | |
| if: always() && !cancelled() && needs.checkout-cache.result == 'success' && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'validate-yaml')) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Restore checkout | |
| id: restore-checkout | |
| uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: . | |
| key: checkout-cgo-${{ github.run_id }}-${{ github.sha }} | |
| - name: Checkout on cache miss | |
| if: steps.restore-checkout.outputs.cache-hit != 'true' | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.sha }} | |
| fetch-depth: 2 | |
| persist-credentials: false | |
| - name: Check for ANSI escape sequences in YAML files | |
| run: | | |
| echo "🔍 Scanning YAML workflow files for ANSI escape sequences..." | |
| # Find all YAML files in .github/workflows directory | |
| YAML_FILES=$(find .github/workflows -type f \( -name "*.yml" -o -name "*.yaml" \) | sort) | |
| # Track if any ANSI codes are found | |
| FOUND_ANSI=0 | |
| # Check each file for ANSI escape sequences | |
| for file in $YAML_FILES; do | |
| # Use grep to find ANSI escape sequences (ESC [ ... letter) | |
| # The pattern matches: \x1b followed by [ followed by optional digits/semicolons followed by a letter | |
| if grep -P '\x1b\[[0-9;]*[a-zA-Z]' "$file" > /dev/null 2>&1; then | |
| echo "❌ ERROR: Found ANSI escape sequences in: $file" | |
| echo "" | |
| echo "Lines with ANSI codes:" | |
| grep -n -P '\x1b\[[0-9;]*[a-zA-Z]' "$file" || true | |
| echo "" | |
| FOUND_ANSI=1 | |
| fi | |
| done | |
| if [ $FOUND_ANSI -eq 1 ]; then | |
| echo "" | |
| echo "💡 ANSI escape sequences detected in YAML files!" | |
| echo "" | |
| echo "These are terminal color codes that break YAML parsing." | |
| echo "Common causes:" | |
| echo " - Copy-pasting from colored terminal output" | |
| echo " - Text editors preserving ANSI codes" | |
| echo " - Scripts generating colored output" | |
| echo "" | |
| echo "To fix:" | |
| echo " 1. Remove the ANSI codes from the affected files" | |
| echo " 2. Run 'make recompile' to regenerate workflow files" | |
| echo " 3. Use '--no-color' flags when capturing command output" | |
| echo "" | |
| exit 1 | |
| fi | |
| echo "✅ No ANSI escape sequences found in YAML files" | |
| - name: Check for release-compiled lock files | |
| run: | | |
| echo "🔍 Checking .lock.yml files for release build compilation..." | |
| # Find all .lock.yml files in the repository | |
| LOCK_FILES=$(find . -type f -name "*.lock.yml" | sort) | |
| if [ -z "$LOCK_FILES" ]; then | |
| echo "⚠️ WARNING: No .lock.yml files found" | |
| exit 0 | |
| fi | |
| # Track if any release-compiled files are found | |
| FOUND_RELEASE=0 | |
| # Check each file for release-build markers. | |
| # Release builds include version like: "# This file was automatically generated by gh-aw (v1.0.0). DO NOT EDIT." | |
| # Dev builds do not: "# This file was automatically generated by gh-aw. DO NOT EDIT." | |
| for file in $LOCK_FILES; do | |
| # Release-compiled lock files can be identified by either: | |
| # 1. Header marker with version suffix (legacy): "...generated by gh-aw (vX.Y.Z)." | |
| # 2. Metadata marker: compiler_version field in gh-aw-metadata. | |
| HEADER_MARKER=$(grep -E '^# This file was automatically generated by gh-aw \([v0-9]' "$file" || true) | |
| METADATA_MARKER=$(grep -E '^# gh-aw-metadata: .*"compiler_version":' "$file" || true) | |
| if [ -n "$HEADER_MARKER$METADATA_MARKER" ]; then | |
| echo "❌ ERROR: Found release-compiled lock file: $file" | |
| echo "" | |
| echo "Release-build marker(s):" | |
| printf '%s\n%s\n' "$HEADER_MARKER" "$METADATA_MARKER" | sed '/^$/d' | |
| echo "" | |
| FOUND_RELEASE=1 | |
| fi | |
| done | |
| if [ $FOUND_RELEASE -eq 1 ]; then | |
| echo "" | |
| echo "💡 Lock files should NOT be compiled with a release build!" | |
| echo "" | |
| echo "Lock files in the repository must be compiled with development builds." | |
| echo "Release builds include version markers (header or metadata), which should only" | |
| echo "appear in released binaries, not in source-controlled workflow files." | |
| echo "" | |
| echo "To fix:" | |
| echo " 1. Build the CLI with 'make build' (dev build, no release flag)" | |
| echo " 2. Run 'make recompile' to regenerate all lock files" | |
| echo " 3. Commit the updated lock files" | |
| echo "" | |
| echo "The release build flag is only set during the release process via:" | |
| echo " scripts/build-release.sh (sets -X main.isRelease=true)" | |
| echo "" | |
| exit 1 | |
| fi | |
| echo "✅ All lock files compiled with development build (no release markers)" | |
| - name: Check skill file URLs use main branch | |
| run: | | |
| echo "🔍 Checking .github/skills/agentic-workflows/SKILL.md for correct branch URLs..." | |
| AGENT_FILE=".github/skills/agentic-workflows/SKILL.md" | |
| if [ ! -f "$AGENT_FILE" ]; then | |
| echo "⚠️ WARNING: $AGENT_FILE not found, skipping check" | |
| exit 0 | |
| fi | |
| # Check for URLs that don't use 'main' branch | |
| # Pattern matches: https://github.com/github/gh-aw/blob/{anything-except-main}/ | |
| # Uses negative lookahead to exclude 'main' | |
| INVALID_URLS=$(grep -n 'https://github.com/github/gh-aw/blob/' "$AGENT_FILE" | grep -v '/blob/main/' || true) | |
| if [ -n "$INVALID_URLS" ]; then | |
| echo "❌ ERROR: Found URLs not using 'main' branch in $AGENT_FILE" | |
| echo "" | |
| echo "Lines with invalid URLs:" | |
| echo "$INVALID_URLS" | |
| echo "" | |
| echo "💡 All GitHub URLs in skill files must reference the 'main' branch!" | |
| echo "" | |
| echo "URLs should use the pattern:" | |
| echo " https://github.com/github/gh-aw/blob/main/.github/aw/..." | |
| echo "" | |
| echo "To fix:" | |
| echo " 1. Edit $AGENT_FILE" | |
| echo " 2. Replace all 'blob/{commit-hash}/' or 'blob/{tag}/' with 'blob/main/'" | |
| echo " 3. Commit the updated file" | |
| echo "" | |
| exit 1 | |
| fi | |
| echo "✅ All URLs in $AGENT_FILE correctly use 'main' branch" | |
| - name: Validate releases.json structure and version formats | |
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const CONFIG_FILE = '.github/aw/releases.json'; | |
| const SCHEMA_FILE = '.github/aw/releases.schema.json'; | |
| core.info(`🔍 Validating ${CONFIG_FILE} against ${SCHEMA_FILE}...`); | |
| if (!fs.existsSync(CONFIG_FILE)) { | |
| core.setFailed(`ERROR: ${CONFIG_FILE} not found`); | |
| return; | |
| } | |
| if (!fs.existsSync(SCHEMA_FILE)) { | |
| core.setFailed(`ERROR: ${SCHEMA_FILE} not found`); | |
| return; | |
| } | |
| let config; | |
| try { | |
| config = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8')); | |
| } catch (err) { | |
| core.setFailed(`ERROR: ${CONFIG_FILE} is not valid JSON: ${err.message}`); | |
| return; | |
| } | |
| core.info(`✅ ${CONFIG_FILE} is valid JSON`); | |
| const errors = []; | |
| // Check additionalProperties (only allow known keys) | |
| const allowedKeys = new Set(['$schema', 'blockedVersions', 'minimumVersion', 'minRecommendedVersion']); | |
| for (const key of Object.keys(config)) { | |
| if (!allowedKeys.has(key)) { | |
| errors.push(`Unknown property: '${key}'`); | |
| } | |
| } | |
| // Validate blockedVersions | |
| if ('blockedVersions' in config) { | |
| const bv = config.blockedVersions; | |
| if (!Array.isArray(bv)) { | |
| errors.push("'blockedVersions' must be an array"); | |
| } else { | |
| const versionPattern = /^v[0-9]+\.[0-9]+\.[0-9]+$/; | |
| const seen = new Set(); | |
| bv.forEach((v, i) => { | |
| if (typeof v !== 'string') { | |
| errors.push(`'blockedVersions[${i}]' must be a string`); | |
| } else if (!versionPattern.test(v)) { | |
| errors.push(`'blockedVersions[${i}]' ('${v}') does not match expected version pattern (vMAJOR.MINOR.PATCH, e.g. 'v1.2.3')`); | |
| } else if (seen.has(v)) { | |
| errors.push(`'blockedVersions' contains duplicate entry: '${v}'`); | |
| } else { | |
| seen.add(v); | |
| } | |
| }); | |
| } | |
| } | |
| // Validate minimumVersion | |
| if ('minimumVersion' in config) { | |
| const mv = config.minimumVersion; | |
| if (typeof mv !== 'string') { | |
| errors.push("'minimumVersion' must be a string"); | |
| } else if (mv !== '' && !/^v[0-9]+\.[0-9]+\.[0-9]+$/.test(mv)) { | |
| errors.push(`'minimumVersion' ('${mv}') does not match expected version pattern (vMAJOR.MINOR.PATCH, e.g. 'v1.2.3' or empty string)`); | |
| } | |
| } | |
| // Validate minRecommendedVersion | |
| if ('minRecommendedVersion' in config) { | |
| const mrv = config.minRecommendedVersion; | |
| if (typeof mrv !== 'string') { | |
| errors.push("'minRecommendedVersion' must be a string"); | |
| } else if (mrv !== '' && !/^v[0-9]+\.[0-9]+\.[0-9]+$/.test(mrv)) { | |
| errors.push(`'minRecommendedVersion' ('${mrv}') does not match expected version pattern (vMAJOR.MINOR.PATCH, e.g. 'v1.2.3' or empty string)`); | |
| } | |
| } | |
| if (errors.length > 0) { | |
| core.setFailed(`❌ ${CONFIG_FILE} schema validation failed:\n${errors.map(e => ` - ${e}`).join('\n')}`); | |
| return; | |
| } | |
| core.info(`✅ ${CONFIG_FILE} is valid and conforms to ${SCHEMA_FILE}`); | |
| - name: Validate compat.json structure and version formats | |
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const CONFIG_FILE = '.github/aw/compat.json'; | |
| const SCHEMA_FILE = '.github/aw/compat.schema.json'; | |
| core.info(`🔍 Validating ${CONFIG_FILE} (shape per ${SCHEMA_FILE} + cross-row invariants)...`); | |
| if (!fs.existsSync(CONFIG_FILE)) { | |
| core.setFailed(`ERROR: ${CONFIG_FILE} not found`); | |
| return; | |
| } | |
| if (!fs.existsSync(SCHEMA_FILE)) { | |
| core.setFailed(`ERROR: ${SCHEMA_FILE} not found`); | |
| return; | |
| } | |
| let config; | |
| try { | |
| config = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8')); | |
| } catch (err) { | |
| core.setFailed(`ERROR: ${CONFIG_FILE} is not valid JSON: ${err.message}`); | |
| return; | |
| } | |
| core.info(`✅ ${CONFIG_FILE} is valid JSON`); | |
| const errors = []; | |
| const allowedTopKeys = new Set(['$schema', 'blockedVersions', 'minimumVersion', 'minRecommendedVersion', 'agent-compat-v1']); | |
| for (const key of Object.keys(config)) { | |
| if (!allowedTopKeys.has(key)) { | |
| errors.push(`Unknown top-level property: '${key}'`); | |
| } | |
| } | |
| const releaseVersionRe = /^v[0-9]+\.[0-9]+\.[0-9]+$/; | |
| if ('blockedVersions' in config) { | |
| if (!Array.isArray(config.blockedVersions)) { | |
| errors.push("'blockedVersions' must be an array"); | |
| } else { | |
| const seenBlocked = new Set(); | |
| config.blockedVersions.forEach((v, i) => { | |
| if (typeof v !== 'string') { | |
| errors.push(`blockedVersions[${i}] must be a string`); | |
| return; | |
| } | |
| if (!releaseVersionRe.test(v)) { | |
| errors.push(`blockedVersions[${i}] ('${v}') must match vMAJOR.MINOR.PATCH`); | |
| } | |
| if (seenBlocked.has(v)) { | |
| errors.push(`blockedVersions contains duplicate entry '${v}'`); | |
| } | |
| seenBlocked.add(v); | |
| }); | |
| } | |
| } | |
| if ('minimumVersion' in config) { | |
| const mv = config.minimumVersion; | |
| if (typeof mv !== 'string') { | |
| errors.push("'minimumVersion' must be a string"); | |
| } else if (!(mv === '' || releaseVersionRe.test(mv))) { | |
| errors.push(`'minimumVersion' ('${mv}') does not match expected version pattern (vMAJOR.MINOR.PATCH or empty string)`); | |
| } | |
| } | |
| if ('minRecommendedVersion' in config) { | |
| const mrv = config.minRecommendedVersion; | |
| if (typeof mrv !== 'string') { | |
| errors.push("'minRecommendedVersion' must be a string"); | |
| } else if (!(mrv === '' || releaseVersionRe.test(mrv))) { | |
| errors.push(`'minRecommendedVersion' ('${mrv}') does not match expected version pattern (vMAJOR.MINOR.PATCH or empty string)`); | |
| } | |
| } | |
| const matrix = config['agent-compat-v1']; | |
| if (typeof matrix !== 'object' || matrix === null || Array.isArray(matrix)) { | |
| core.setFailed(`ERROR: 'agent-compat-v1' must be an object`); | |
| return; | |
| } | |
| const semverRe = /^[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z.-]+)?$/; | |
| // Full semver 2.0.0 compare: base triplet, then prerelease identifiers | |
| // (numeric < non-numeric, all-prerelease < no-prerelease). | |
| const parseSemver = (v) => { | |
| const m = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/.exec(v); | |
| if (!m) return null; | |
| return { | |
| base: [Number(m[1]), Number(m[2]), Number(m[3])], | |
| pre: m[4] ? m[4].split('.') : null, | |
| }; | |
| }; | |
| const cmp = (a, b) => { | |
| const A = parseSemver(a); | |
| const B = parseSemver(b); | |
| if (!A || !B) throw new Error(`cmp() called with non-semver: '${a}' / '${b}'`); | |
| for (let i = 0; i < 3; i++) { | |
| if (A.base[i] !== B.base[i]) return A.base[i] - B.base[i]; | |
| } | |
| if (A.pre === null && B.pre === null) return 0; | |
| if (A.pre === null) return 1; | |
| if (B.pre === null) return -1; | |
| const len = Math.max(A.pre.length, B.pre.length); | |
| for (let i = 0; i < len; i++) { | |
| if (i >= A.pre.length) return -1; | |
| if (i >= B.pre.length) return 1; | |
| const ai = A.pre[i], bi = B.pre[i]; | |
| const aN = /^\d+$/.test(ai), bN = /^\d+$/.test(bi); | |
| if (aN && bN) { | |
| const da = Number(ai), db = Number(bi); | |
| if (da !== db) return da - db; | |
| } else if (aN) return -1; | |
| else if (bN) return 1; | |
| else if (ai !== bi) return ai < bi ? -1 : 1; | |
| } | |
| return 0; | |
| }; | |
| // Compare gh-aw bounds where '*' means +infinity (only valid on max-gh-aw). | |
| const cmpGhAw = (a, b) => { | |
| if (a === '*' && b === '*') return 0; | |
| if (a === '*') return 1; | |
| if (b === '*') return -1; | |
| return cmp(a, b); | |
| }; | |
| if ('cache-ttl-days' in matrix) { | |
| const ttl = matrix['cache-ttl-days']; | |
| if (!Number.isInteger(ttl) || ttl < 1) { | |
| errors.push(`'agent-compat-v1.cache-ttl-days' must be a positive integer (got ${JSON.stringify(ttl)})`); | |
| } | |
| } | |
| // Keep the agent names here in sync with agent-compat-v1.properties in compat.schema.json. | |
| const allowedAgentKeys = new Set(['cache-ttl-days', 'copilot', 'claude']); | |
| for (const key of Object.keys(matrix)) { | |
| if (!allowedAgentKeys.has(key)) { | |
| errors.push(`Unknown property under 'agent-compat-v1': '${key}'`); | |
| } | |
| } | |
| for (const [agent, rows] of Object.entries(matrix)) { | |
| if (agent === 'cache-ttl-days') continue; | |
| if (!Array.isArray(rows) || rows.length < 1) { | |
| errors.push(`'agent-compat-v1.${agent}' must be a non-empty array`); | |
| continue; | |
| } | |
| const allowedRowKeys = new Set(['min-gh-aw', 'max-gh-aw', 'min-agent', 'max-agent', 'open']); | |
| const requiredRowKeys = ['min-gh-aw', 'max-gh-aw', 'min-agent', 'max-agent']; | |
| rows.forEach((row, idx) => { | |
| const where = `${agent}[${idx}]`; | |
| if (typeof row !== 'object' || row === null || Array.isArray(row)) { | |
| errors.push(`${where} must be an object`); | |
| return; | |
| } | |
| for (const key of Object.keys(row)) { | |
| if (!allowedRowKeys.has(key)) { | |
| errors.push(`${where} has unknown property '${key}'`); | |
| } | |
| } | |
| for (const key of requiredRowKeys) { | |
| if (!(key in row)) { | |
| errors.push(`${where} is missing required property '${key}'`); | |
| } | |
| } | |
| for (const k of ['min-gh-aw', 'min-agent', 'max-agent']) { | |
| if (k in row && !semverRe.test(row[k])) { | |
| errors.push(`${where}.${k} ('${row[k]}') is not a valid semver (MAJOR.MINOR.PATCH)`); | |
| } | |
| } | |
| if ('max-gh-aw' in row && row['max-gh-aw'] !== '*' && !semverRe.test(row['max-gh-aw'])) { | |
| errors.push(`${where}.max-gh-aw ('${row['max-gh-aw']}') must be either '*' or a valid semver`); | |
| } | |
| if ('min-agent' in row && 'max-agent' in row && semverRe.test(row['min-agent']) && semverRe.test(row['max-agent'])) { | |
| if (cmp(row['min-agent'], row['max-agent']) > 0) { | |
| errors.push(`${where}: min-agent (${row['min-agent']}) must be <= max-agent (${row['max-agent']})`); | |
| } | |
| } | |
| if (row['max-gh-aw'] === '*') { | |
| if ('open' in row && typeof row['open'] !== 'boolean') { | |
| errors.push(`${where}.open must be a boolean`); | |
| } | |
| } else if ('max-gh-aw' in row) { | |
| if (semverRe.test(row['min-gh-aw']) && semverRe.test(row['max-gh-aw'])) { | |
| if (cmp(row['min-gh-aw'], row['max-gh-aw']) > 0) { | |
| errors.push(`${where}: min-gh-aw (${row['min-gh-aw']}) must be <= max-gh-aw (${row['max-gh-aw']})`); | |
| } | |
| } | |
| if ('open' in row) { | |
| errors.push(`${where}: 'open' is only permitted on the catch-all row (max-gh-aw '*'); bounded rows are closed-by-construction`); | |
| } | |
| } | |
| }); | |
| for (let i = 0; i < rows.length; i++) { | |
| for (let j = i + 1; j < rows.length; j++) { | |
| const a = rows[i]; | |
| const b = rows[j]; | |
| // Skip non-object rows (already reported above) so we do not throw on a/b['min-gh-aw']. | |
| if (typeof a !== 'object' || a === null || Array.isArray(a)) continue; | |
| if (typeof b !== 'object' || b === null || Array.isArray(b)) continue; | |
| if (![a['min-gh-aw'], a['max-gh-aw'], b['min-gh-aw'], b['max-gh-aw']].every(v => v === '*' || semverRe.test(v))) continue; | |
| // Ranges are closed/inclusive on both ends; two rows that share a boundary version count as overlapping. | |
| if (cmpGhAw(a['min-gh-aw'], b['max-gh-aw']) <= 0 && cmpGhAw(b['min-gh-aw'], a['max-gh-aw']) <= 0) { | |
| errors.push(`${agent}: rows [${i}] and [${j}] have overlapping gh-aw ranges (${a['min-gh-aw']}..${a['max-gh-aw']} vs ${b['min-gh-aw']}..${b['max-gh-aw']})`); | |
| } | |
| } | |
| } | |
| } | |
| if (errors.length > 0) { | |
| core.setFailed(`❌ ${CONFIG_FILE} validation failed:\n${errors.map(e => ` - ${e}`).join('\n')}`); | |
| return; | |
| } | |
| core.info(`✅ ${CONFIG_FILE} passes all structural and cross-row invariant checks`); | |
| check-validator-sizes: | |
| name: Check validator file sizes | |
| needs: [checkout-cache, front-door-decision] | |
| if: always() && !cancelled() && needs.checkout-cache.result == 'success' && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'check-validator-sizes')) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| # Non-blocking: report violations but don't fail the build until existing files are cleaned up | |
| continue-on-error: true | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Restore checkout | |
| id: restore-checkout | |
| uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: . | |
| key: checkout-cgo-${{ github.run_id }}-${{ github.sha }} | |
| - name: Checkout on cache miss | |
| if: steps.restore-checkout.outputs.cache-hit != 'true' | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.sha }} | |
| fetch-depth: 2 | |
| persist-credentials: false | |
| - name: Check validator file sizes | |
| id: check | |
| run: | | |
| set +e | |
| OUTPUT=$(NO_COLOR=1 bash scripts/check-validator-sizes.sh 2>&1) | |
| EXIT_CODE=$? | |
| echo "$OUTPUT" | |
| echo "exit_code=$EXIT_CODE" >> "$GITHUB_OUTPUT" | |
| echo "## Validator File Size Check" >> "$GITHUB_STEP_SUMMARY" | |
| echo "" >> "$GITHUB_STEP_SUMMARY" | |
| echo "Checking \`*_validation.go\` files against the 768-line hard limit (AGENTS.md)." >> "$GITHUB_STEP_SUMMARY" | |
| echo "" >> "$GITHUB_STEP_SUMMARY" | |
| echo "\`\`\`" >> "$GITHUB_STEP_SUMMARY" | |
| echo "$OUTPUT" >> "$GITHUB_STEP_SUMMARY" | |
| echo "\`\`\`" >> "$GITHUB_STEP_SUMMARY" | |
| if [ "$EXIT_CODE" -ne 0 ]; then | |
| echo "" >> "$GITHUB_STEP_SUMMARY" | |
| echo "⚠️ This check is currently non-blocking. Fix violations to keep the codebase healthy." >> "$GITHUB_STEP_SUMMARY" | |
| fi | |
| exit "$EXIT_CODE" | |
| lint-go-format: | |
| needs: [checkout-cache, front-door-decision] | |
| if: always() && !cancelled() && needs.checkout-cache.result == 'success' && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'lint-go-format')) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ci-${{ github.ref }}-lint-go-format | |
| cancel-in-progress: true | |
| steps: | |
| - name: Restore checkout | |
| id: restore-checkout | |
| uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: . | |
| key: checkout-cgo-${{ github.run_id }}-${{ github.sha }} | |
| - name: Checkout on cache miss | |
| if: steps.restore-checkout.outputs.cache-hit != 'true' | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.sha }} | |
| fetch-depth: 2 | |
| persist-credentials: false | |
| - name: Set up Go | |
| id: setup-go | |
| uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v6 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Report Go cache status | |
| run: | | |
| if [ "${{ steps.setup-go.outputs.cache-hit }}" == "true" ]; then | |
| echo "✅ Go cache hit" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "⚠️ Go cache miss" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| # Go formatting check (fast, no deps needed) | |
| - name: Check Go formatting | |
| run: | | |
| unformatted=$(go fmt ./...) | |
| if [ -n "$unformatted" ]; then | |
| echo "❌ Code is not formatted. Run 'make fmt' to fix." >> $GITHUB_STEP_SUMMARY | |
| echo "Unformatted files:" >> $GITHUB_STEP_SUMMARY | |
| echo "$unformatted" >> $GITHUB_STEP_SUMMARY | |
| echo "" | |
| echo "To fix this locally, run:" | |
| echo " make fmt" | |
| echo "" | |
| echo "Or format individual files with:" | |
| echo " go fmt ./path/to/file.go" | |
| exit 1 | |
| fi | |
| echo "✅ Go formatting check passed" >> $GITHUB_STEP_SUMMARY | |
| lint-go-golangci: | |
| needs: [checkout-cache, front-door-decision] | |
| if: always() && !cancelled() && needs.checkout-cache.result == 'success' && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'lint-go-golangci')) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| permissions: | |
| contents: read | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| shard: [0, 1, 2] | |
| concurrency: | |
| group: ci-${{ github.ref }}-lint-go-golangci-${{ matrix.shard }} | |
| cancel-in-progress: true | |
| steps: | |
| - name: Restore checkout | |
| id: restore-checkout | |
| uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: . | |
| key: checkout-cgo-${{ github.run_id }}-${{ github.sha }} | |
| - name: Checkout on cache miss | |
| if: steps.restore-checkout.outputs.cache-hit != 'true' | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.sha }} | |
| fetch-depth: 2 | |
| persist-credentials: false | |
| - name: Set up Go | |
| id: setup-go | |
| uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v6 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Report Go cache status | |
| run: | | |
| if [ "${{ steps.setup-go.outputs.cache-hit }}" == "true" ]; then | |
| echo "✅ Go cache hit" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "⚠️ Go cache miss" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| # Ensure the module cache is fully populated before linting. | |
| # golangci-lint type-checks packages and would otherwise fetch missing | |
| # modules inline, where a transient proxy.golang.org error surfaces as a | |
| # confusing "could not import ... (typecheck)" lint failure. | |
| # Runs unconditionally because a restored Go cache can still be incomplete. | |
| - name: Download dependencies with retry | |
| run: | | |
| set -e | |
| MAX_RETRIES=3 | |
| RETRY_DELAY=5 | |
| for i in $(seq 1 $MAX_RETRIES); do | |
| echo "Attempt $i of $MAX_RETRIES: Downloading Go modules..." | |
| if go mod download; then | |
| echo "✅ Successfully downloaded Go modules" | |
| break | |
| else | |
| if [ $i -eq $MAX_RETRIES ]; then | |
| echo "❌ Failed to download Go modules after $MAX_RETRIES attempts" | |
| echo "This may indicate that proxy.golang.org is unreachable" | |
| exit 1 | |
| fi | |
| echo "⚠️ Download failed, retrying in ${RETRY_DELAY}s..." | |
| sleep $RETRY_DELAY | |
| fi | |
| done | |
| # Install golangci-lint binary (avoiding GPL dependencies) | |
| # Downloads pre-built binary from GitHub releases instead of using go install | |
| - name: Install golangci-lint | |
| run: | | |
| GOLANGCI_LINT_VERSION="v2.15.0" | |
| GOOS=$(go env GOOS) | |
| GOARCH=$(go env GOARCH) | |
| GOPATH=$(go env GOPATH) | |
| BINARY_NAME="golangci-lint" | |
| echo "Installing golangci-lint $GOLANGCI_LINT_VERSION for $GOOS/$GOARCH..." | |
| DOWNLOAD_URL="https://github.com/golangci/golangci-lint/releases/download/$GOLANGCI_LINT_VERSION/golangci-lint-${GOLANGCI_LINT_VERSION#v}-$GOOS-$GOARCH.tar.gz" | |
| ARCHIVE="/tmp/golangci-lint.tar.gz" | |
| # Save archive to disk first so we can verify it before extracting. | |
| # --fail causes curl to exit non-zero on HTTP errors (4xx/5xx), | |
| # --retry 3 retries transient network failures automatically. | |
| curl --fail --retry 3 -sSL "$DOWNLOAD_URL" -o "$ARCHIVE" | |
| tar -xz -C /tmp -f "$ARCHIVE" | |
| mkdir -p "$GOPATH/bin" | |
| mv /tmp/golangci-lint-*/$BINARY_NAME "$GOPATH/bin/$BINARY_NAME" | |
| chmod +x "$GOPATH/bin/$BINARY_NAME" | |
| echo "✓ golangci-lint $GOLANGCI_LINT_VERSION installed" | |
| "$GOPATH/bin/$BINARY_NAME" version | |
| # Split the configured linters across jobs without hard-coding their names. | |
| - name: Run golangci-lint | |
| env: | |
| GITHUB_EVENT_NAME: ${{ github.event_name }} | |
| LINTER_SHARD: ${{ matrix.shard }} | |
| run: | | |
| export PATH="$PATH:$(go env GOPATH)/bin" | |
| # Disable the other shards' linters while retaining the shared settings | |
| # and exclusions from .golangci.yml. | |
| DISABLED_LINTERS=$(golangci-lint linters --json | jq -r --argjson shard "$LINTER_SHARD" \ | |
| '[.Enabled | to_entries[] | select(.key % 3 != $shard) | .value.name] | join(",")') | |
| if [ -z "$DISABLED_LINTERS" ]; then | |
| echo "Could not partition the enabled golangci-lint linters" | |
| exit 1 | |
| fi | |
| if [ "$GITHUB_EVENT_NAME" = "pull_request" ] && git rev-parse --verify -q 'HEAD^2^{commit}' >/dev/null; then | |
| # A PR checkout is a merge commit: its first parent is the base branch. | |
| # Both commits are in the depth-2 checkout; no network fetch is needed. | |
| golangci-lint run --disable "$DISABLED_LINTERS" --new-from-rev=HEAD^1 ./cmd/... ./pkg/... | |
| else | |
| # Full scan on main or if a PR checkout does not contain a merge commit. | |
| golangci-lint run --disable "$DISABLED_LINTERS" ./cmd/... ./pkg/... | |
| fi | |
| lint-go-govulncheck: | |
| needs: [checkout-cache, front-door-decision] | |
| if: always() && !cancelled() && needs.checkout-cache.result == 'success' && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'lint-go-govulncheck')) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ci-${{ github.ref }}-lint-go-govulncheck | |
| cancel-in-progress: true | |
| steps: | |
| - name: Restore checkout | |
| id: restore-checkout | |
| uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: . | |
| key: checkout-cgo-${{ github.run_id }}-${{ github.sha }} | |
| - name: Checkout on cache miss | |
| if: steps.restore-checkout.outputs.cache-hit != 'true' | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.sha }} | |
| fetch-depth: 2 | |
| persist-credentials: false | |
| - name: Set up Go | |
| uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v6 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Download dependencies with retry | |
| run: | | |
| set -e | |
| MAX_RETRIES=3 | |
| RETRY_DELAY=5 | |
| for ((i = 1; i <= MAX_RETRIES; i++)); do | |
| echo "Attempt $i of $MAX_RETRIES: Downloading Go modules..." | |
| if go mod download; then | |
| echo "Successfully downloaded Go modules" | |
| break | |
| else | |
| if [ "$i" -eq "$MAX_RETRIES" ]; then | |
| echo "Failed to download Go modules after $MAX_RETRIES attempts" | |
| exit 1 | |
| fi | |
| echo "Download failed, retrying in ${RETRY_DELAY}s..." | |
| sleep "$RETRY_DELAY" | |
| fi | |
| done | |
| - name: Run govulncheck | |
| run: make security-govulncheck | |
| lint-go-custom: | |
| needs: [checkout-cache, front-door-decision] | |
| if: always() && !cancelled() && needs.checkout-cache.result == 'success' && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'lint-go-custom')) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ci-${{ github.ref }}-lint-go-custom | |
| cancel-in-progress: true | |
| steps: | |
| - name: Restore checkout | |
| id: restore-checkout | |
| uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: . | |
| key: checkout-cgo-${{ github.run_id }}-${{ github.sha }} | |
| - name: Checkout on cache miss | |
| if: steps.restore-checkout.outputs.cache-hit != 'true' | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.sha }} | |
| fetch-depth: 2 | |
| persist-credentials: false | |
| - name: Set up Go | |
| id: setup-go | |
| uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v6 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Report Go cache status | |
| run: | | |
| if [ "${{ steps.setup-go.outputs.cache-hit }}" == "true" ]; then | |
| echo "✅ Go cache hit" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "⚠️ Go cache miss" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| # Enforce selected production custom analyzers without blocking on unrelated | |
| # legacy custom analyzer findings in tests or other analyzer families. | |
| # Note: -test=false intentionally scopes this gate to production code only. | |
| - name: Run custom linters | |
| run: make golint-custom LINTER_FLAGS="-errstringmatch -panicinlibrarycode -manualmutexunlock -osexitinlibrary -rawloginlib -logfatallibrary -regexpcompileinfunction -fprintlnsprintf -strconvparseignorederror -jsonmarshalignoredeerror -uncheckedtypeassertion -fmterrorfnoverbs -tolowerequalfold -httpnoctx -httprespbodyclose -httpstatuscode -timeafterleak -errortypeassertion -execcommandwithoutcontext -sprintfint -stringsindexcontains -stringscountcontains -bytesbufferstring -ioutildeprecated -mapclearloop -mapdeletecheck -sprintfbool -appendoneelement -timenowsub -stringsjoinone -writebytestring -lenstringsplit -stringreplaceminusone -osgetenvlibrary -ossetenvlibrary -stringsindexhasprefix -contextcancelnotdeferred -ctxbackground -wgdonenotdeferred -goroutinemissingrecover -trimleftright -walkfuncerrshadow -uncheckedflushreturn -bytescomparestring -nilctxpassed -stringbytesroundtrip -fileclosenotdeferred -timesleepnocontext -sprintferrorsnew -globwalkignorederror -appendbytestring -slicemakezerolength -sortslice -deferinloop -regexpdynamicpattern -generatedyamlheredoc -test=false" | |
| - name: Check console stderr formatting | |
| run: make golint-custom LINTER_FLAGS="-consolestderr -test=false" | |
| - name: Report unchecked printf errors as warnings | |
| run: | | |
| linter_dir=$(mktemp -d) | |
| trap 'rm -rf "$linter_dir"' EXIT | |
| env -u GOOS -u GOARCH go build -o "$linter_dir/gh-aw-linters" ./cmd/linters | |
| log_file="$linter_dir/fprintf-lint.log" | |
| status=0 | |
| "$linter_dir/gh-aw-linters" -fprintferrorunchecked -test=false ./cmd/... ./pkg/... > "$log_file" 2>&1 || status=$? | |
| if [ "$status" -eq 0 ]; then | |
| exit 0 | |
| fi | |
| if [ "$status" -ne 3 ]; then | |
| cat "$log_file" | |
| exit "$status" | |
| fi | |
| while IFS= read -r diagnostic; do | |
| if [[ "$diagnostic" =~ ^([^:]+):([0-9]+):([0-9]+):[[:space:]]*(.*)$ ]]; then | |
| echo "::warning file=${BASH_REMATCH[1]},line=${BASH_REMATCH[2]},col=${BASH_REMATCH[3]}::${BASH_REMATCH[4]}" | |
| else | |
| echo "$diagnostic" | |
| fi | |
| done < "$log_file" | |
| - name: Run custom linters (wasm) | |
| run: GOOS=js GOARCH=wasm make golint-custom LINTER_FLAGS="-errstringmatch -panicinlibrarycode -manualmutexunlock -osexitinlibrary -rawloginlib -logfatallibrary -regexpcompileinfunction -fprintlnsprintf -strconvparseignorederror -jsonmarshalignoredeerror -uncheckedtypeassertion -fmterrorfnoverbs -tolowerequalfold -httpnoctx -httprespbodyclose -httpstatuscode -timeafterleak -errortypeassertion -execcommandwithoutcontext -sprintfint -stringsindexcontains -stringscountcontains -bytesbufferstring -ioutildeprecated -mapclearloop -mapdeletecheck -sprintfbool -appendoneelement -timenowsub -stringsjoinone -writebytestring -lenstringsplit -stringreplaceminusone -osgetenvlibrary -ossetenvlibrary -stringsindexhasprefix -contextcancelnotdeferred -ctxbackground -wgdonenotdeferred -goroutinemissingrecover -trimleftright -walkfuncerrshadow -uncheckedflushreturn -bytescomparestring -nilctxpassed -stringbytesroundtrip -fileclosenotdeferred -timesleepnocontext -sprintferrorsnew -globwalkignorederror -appendbytestring -slicemakezerolength -sortslice -deferinloop -regexpdynamicpattern -generatedyamlheredoc -test=false" LINTER_PACKAGES="./pkg/console ./pkg/parser ./pkg/styles ./pkg/tty ./pkg/workflow" | |
| - name: Check console stderr formatting (wasm) | |
| run: GOOS=js GOARCH=wasm make golint-custom LINTER_FLAGS="-consolestderr -test=false" LINTER_PACKAGES="./pkg/console ./pkg/parser ./pkg/styles ./pkg/tty ./pkg/workflow" | |
| # Ensure no action shell scripts invoke python or python3 | |
| - name: Lint action shell scripts | |
| run: make lint-action-sh | |
| lint-error-messages: | |
| needs: [checkout-cache, front-door-decision] | |
| if: always() && !cancelled() && needs.checkout-cache.result == 'success' && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'lint-error-messages')) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ci-${{ github.ref }}-lint-error-messages | |
| cancel-in-progress: true | |
| steps: | |
| - name: Restore checkout | |
| id: restore-checkout | |
| uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: . | |
| key: checkout-cgo-${{ github.run_id }}-${{ github.sha }} | |
| - name: Checkout on cache miss | |
| if: steps.restore-checkout.outputs.cache-hit != 'true' | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.sha }} | |
| fetch-depth: 2 | |
| persist-credentials: false | |
| - name: Set up Go | |
| uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v6 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| # Error message linting (requires Go only) | |
| - name: Lint error messages | |
| continue-on-error: true | |
| run: make lint-errors | |
| actions-build: | |
| needs: [checkout-cache, front-door-decision] | |
| if: always() && !cancelled() && needs.checkout-cache.result == 'success' && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'actions-build')) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ci-${{ github.ref }}-actions-build | |
| cancel-in-progress: true | |
| steps: | |
| - name: Restore checkout | |
| id: restore-checkout | |
| uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: . | |
| key: checkout-cgo-${{ github.run_id }}-${{ github.sha }} | |
| - name: Checkout on cache miss | |
| if: steps.restore-checkout.outputs.cache-hit != 'true' | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.sha }} | |
| fetch-depth: 2 | |
| persist-credentials: false | |
| - name: Set up Go | |
| id: setup-go | |
| uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v6 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Report Go cache status | |
| run: | | |
| if [ "${{ steps.setup-go.outputs.cache-hit }}" == "true" ]; then | |
| echo "✅ Go cache hit" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "⚠️ Go cache miss" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| - name: Download dependencies with retry | |
| if: steps.setup-go.outputs.cache-hit != 'true' | |
| run: | | |
| set -e | |
| MAX_RETRIES=3 | |
| RETRY_DELAY=5 | |
| for i in $(seq 1 $MAX_RETRIES); do | |
| echo "Attempt $i of $MAX_RETRIES: Downloading Go modules..." | |
| if go mod download; then | |
| echo "✅ Successfully downloaded Go modules" | |
| break | |
| else | |
| if [ $i -eq $MAX_RETRIES ]; then | |
| echo "❌ Failed to download Go modules after $MAX_RETRIES attempts" | |
| echo "This may indicate that proxy.golang.org is unreachable" | |
| echo "Please check network connectivity or consider vendoring dependencies" | |
| exit 1 | |
| fi | |
| echo "⚠️ Download failed, retrying in ${RETRY_DELAY}s..." | |
| sleep $RETRY_DELAY | |
| fi | |
| done | |
| - name: Verify dependencies | |
| run: go mod verify | |
| - name: Build actions | |
| run: make actions-build | |
| - name: Validate actions | |
| run: make actions-validate | |
| fuzz: | |
| if: always() && !cancelled() && needs.checkout-cache.result == 'success' && (github.event_name == 'pull_request' || github.ref == 'refs/heads/main') && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'fuzz')) | |
| needs: [checkout-cache, front-door-decision] | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ci-${{ github.ref }}-fuzz-${{ matrix.group }} | |
| cancel-in-progress: true | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - group: Parser | |
| tests: >- | |
| FuzzParseFrontmatter:./pkg/parser/ | |
| FuzzScheduleParser:./pkg/parser/ | |
| FuzzRuntimeImportExpressionValidation:./pkg/parser/ | |
| FuzzRuntimeImportProcessExpressions:./pkg/parser/ | |
| - group: Workflow-Core | |
| tests: >- | |
| FuzzExpressionParser:./pkg/workflow/ | |
| FuzzBashCommandParserModel:./pkg/workflow/ | |
| FuzzMentionsFiltering:./pkg/workflow/ | |
| FuzzSanitizeOutput:./pkg/workflow/ | |
| FuzzSanitizeIncomingText:./pkg/workflow/ | |
| FuzzSanitizeLabelContent:./pkg/workflow/ | |
| FuzzWrapExpressionsInTemplateConditionals:./pkg/workflow/ | |
| - group: Workflow-Parsing | |
| tests: >- | |
| FuzzYAMLParsing:./pkg/workflow/ | |
| FuzzTemplateRendering:./pkg/workflow/ | |
| FuzzInputValidation:./pkg/workflow/ | |
| FuzzNetworkPermissions:./pkg/workflow/ | |
| FuzzSafeJobConfig:./pkg/workflow/ | |
| FuzzParseLabelTriggerShorthand:./pkg/workflow/ | |
| - group: Workflow-Triggers | |
| tests: >- | |
| FuzzExpandLabelTriggerShorthand:./pkg/workflow/ | |
| FuzzValidateNoTemplateInjection:./pkg/workflow/ | |
| FuzzRemoveHeredocContent:./pkg/workflow/ | |
| FuzzMarkdownCodeRegionBalancer:./pkg/workflow/ | |
| FuzzParseTriggerShorthand:./pkg/workflow/ | |
| FuzzTriggerIRToYAMLMap:./pkg/workflow/ | |
| FuzzParseInputDefinition:./pkg/workflow/ | |
| FuzzParseInputDefinitions:./pkg/workflow/ | |
| steps: | |
| - name: Restore checkout | |
| id: restore-checkout | |
| uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: . | |
| key: checkout-cgo-${{ github.run_id }}-${{ github.sha }} | |
| - name: Checkout on cache miss | |
| if: steps.restore-checkout.outputs.cache-hit != 'true' | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.sha }} | |
| fetch-depth: 2 | |
| persist-credentials: false | |
| - name: Set up Go | |
| id: setup-go | |
| uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v6 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Report Go cache status | |
| run: | | |
| if [ "${{ steps.setup-go.outputs.cache-hit }}" == "true" ]; then | |
| echo "✅ Go cache hit" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "⚠️ Go cache miss" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| - name: Download dependencies with retry | |
| if: steps.setup-go.outputs.cache-hit != 'true' | |
| env: | |
| GOPROXY: "https://proxy.golang.org,direct" | |
| run: | | |
| set -e | |
| MAX_RETRIES=3 | |
| RETRY_DELAY=5 | |
| for i in $(seq 1 $MAX_RETRIES); do | |
| echo "Attempt $i of $MAX_RETRIES: Downloading Go modules..." | |
| if go mod download; then | |
| echo "✅ Successfully downloaded Go modules" | |
| break | |
| else | |
| if [ $i -eq $MAX_RETRIES ]; then | |
| echo "❌ Failed to download Go modules after $MAX_RETRIES attempts" | |
| echo "This indicates that proxy.golang.org is unreachable or returning errors" | |
| echo "- Network connectivity: checking proxy.golang.org..." | |
| if curl -s -I --connect-timeout 5 https://proxy.golang.org/golang.org/@v/list >/dev/null 2>&1; then | |
| echo " ✓ proxy.golang.org is reachable" | |
| else | |
| echo " ✗ proxy.golang.org is NOT reachable" | |
| fi | |
| echo "Please check network connectivity or re-run the workflow once the proxy recovers" | |
| exit 1 | |
| fi | |
| echo "⚠️ Download failed, retrying in ${RETRY_DELAY}s..." | |
| sleep $RETRY_DELAY | |
| fi | |
| done | |
| - name: Verify dependencies | |
| run: go mod verify | |
| - name: Verify integration build | |
| run: | | |
| # Compile and link all integration-tagged test binaries without | |
| # executing package test binaries or TestMain side effects. | |
| # Fuzz tests such as FuzzSanitizeOutput run with -tags=integration; a build | |
| # error in any integration-tagged file causes the entire fuzz run to fail | |
| # with a misleading error message. | |
| go test -run='^$' -exec=true -tags=integration ./... | |
| - name: Run fuzz tests (${{ matrix.group }}) | |
| run: | | |
| set -o pipefail | |
| # Create directory for fuzz results | |
| mkdir -p fuzz-results | |
| # Helper function to run fuzz test and handle context deadline | |
| # Go fuzz tests can exit with status 1 and "context deadline exceeded" when | |
| # they reach the -fuzztime limit. We treat this as expected success to allow | |
| # all fuzz targets to run instead of stopping at the first timeout. | |
| run_fuzz_test() { | |
| local fuzz_name=$1 | |
| local package=$2 | |
| local tags_arg="" | |
| local output_file="fuzz-results/${fuzz_name}.txt" | |
| if [ "${fuzz_name}" = "FuzzSanitizeOutput" ] || [ "${fuzz_name}" = "FuzzSanitizeIncomingText" ]; then | |
| tags_arg="-tags=integration" | |
| fi | |
| echo "Running ${fuzz_name}..." | |
| if go test -run='^$' -fuzz="^${fuzz_name}$" -fuzztime=10s ${tags_arg:+"${tags_arg}"} "${package}" 2>&1 | tee "${output_file}"; then | |
| echo "✅ ${fuzz_name} completed successfully" | |
| return 0 | |
| else | |
| # Check if the failure was due to context deadline (expected) | |
| if grep -q "context deadline exceeded" "${output_file}"; then | |
| echo "✅ ${fuzz_name} completed (context deadline reached as expected)" | |
| return 0 | |
| else | |
| echo "❌ ${fuzz_name} failed with unexpected error" | |
| return 1 | |
| fi | |
| fi | |
| } | |
| # Run fuzz tests for this matrix group | |
| for entry in ${{ matrix.tests }}; do | |
| fuzz_name="${entry%%:*}" | |
| package="${entry##*:}" | |
| run_fuzz_test "${fuzz_name}" "${package}" | |
| done | |
| # Copy fuzz corpus data (testdata/fuzz directories) | |
| echo "Copying fuzz corpus data..." | |
| find ./pkg -path "*/testdata/fuzz" -type d | while read -r dir; do | |
| pkg_name=$(echo "$dir" | sed 's|^\./pkg/||' | sed 's|/testdata/fuzz$||') | |
| echo "Copying corpus from $dir to fuzz-results/corpus/$pkg_name/" | |
| mkdir -p "fuzz-results/corpus/$pkg_name" | |
| cp -r "$dir"/* "fuzz-results/corpus/$pkg_name/" 2>/dev/null || echo "No corpus data in $dir" | |
| done | |
| - name: Upload fuzz test results | |
| if: always() | |
| uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 | |
| with: | |
| name: fuzz-results-${{ matrix.group }} | |
| path: fuzz-results/ | |
| retention-days: 7 | |
| security: | |
| needs: [checkout-cache, build, front-door-decision] | |
| if: always() && !cancelled() && needs.checkout-cache.result == 'success' && needs.build.result == 'success' && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'security')) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ci-${{ github.ref }}-security | |
| cancel-in-progress: true | |
| steps: | |
| - name: Restore checkout | |
| id: restore-checkout | |
| uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: . | |
| key: checkout-cgo-${{ github.run_id }}-${{ github.sha }} | |
| - name: Checkout on cache miss | |
| if: steps.restore-checkout.outputs.cache-hit != 'true' | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.sha }} | |
| fetch-depth: 2 | |
| persist-credentials: false | |
| - name: Set up Go | |
| id: setup-go | |
| uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v6 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Report Go cache status | |
| run: | | |
| if [ "${{ steps.setup-go.outputs.cache-hit }}" == "true" ]; then | |
| echo "✅ Go cache hit" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "⚠️ Go cache miss" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| - name: Download dependencies with retry | |
| if: steps.setup-go.outputs.cache-hit != 'true' | |
| run: | | |
| set -e | |
| MAX_RETRIES=3 | |
| RETRY_DELAY=5 | |
| for i in $(seq 1 $MAX_RETRIES); do | |
| echo "Attempt $i of $MAX_RETRIES: Downloading Go modules..." | |
| if go mod download; then | |
| echo "✅ Successfully downloaded Go modules" | |
| break | |
| else | |
| if [ $i -eq $MAX_RETRIES ]; then | |
| echo "❌ Failed to download Go modules after $MAX_RETRIES attempts" | |
| echo "This may indicate that proxy.golang.org is unreachable" | |
| echo "Please check network connectivity or consider vendoring dependencies" | |
| exit 1 | |
| fi | |
| echo "⚠️ Download failed, retrying in ${RETRY_DELAY}s..." | |
| sleep $RETRY_DELAY | |
| fi | |
| done | |
| - name: Verify dependencies | |
| run: go mod verify | |
| - name: Run security regression tests | |
| run: make test-security | |
| security-scan: | |
| if: always() && !cancelled() && needs.checkout-cache.result == 'success' && needs.build.result == 'success' && (github.event_name == 'pull_request' || github.ref == 'refs/heads/main') && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'security-scan')) | |
| needs: [checkout-cache, build, front-door-decision] | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 # Prevent jobs from hanging indefinitely | |
| permissions: | |
| contents: read | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| tool: | |
| - name: zizmor | |
| flag: --zizmor | |
| - name: actionlint | |
| flag: --actionlint | |
| - name: poutine | |
| flag: --poutine | |
| - name: runner-guard | |
| flag: --runner-guard | |
| concurrency: | |
| group: ci-${{ github.ref }}-security-scan-${{ matrix.tool.name }} | |
| cancel-in-progress: true | |
| name: "Security Scan: ${{ matrix.tool.name }}" | |
| steps: | |
| - name: Restore checkout | |
| id: restore-checkout | |
| uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: . | |
| key: checkout-cgo-${{ github.run_id }}-${{ github.sha }} | |
| - name: Checkout on cache miss | |
| if: steps.restore-checkout.outputs.cache-hit != 'true' | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.sha }} | |
| fetch-depth: 2 | |
| persist-credentials: false | |
| - name: Download gh-aw binary | |
| uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 | |
| with: | |
| name: gh-aw-linux-amd64 | |
| - name: Make gh-aw executable | |
| run: chmod +x gh-aw | |
| - name: Run ${{ matrix.tool.name }} security scan on poem workflow | |
| run: ./gh-aw compile poem-bot ${{ matrix.tool.flag }} --verbose | |
| mcp-server-compile-test: | |
| needs: [checkout-cache, front-door-decision] | |
| if: always() && !cancelled() && needs.checkout-cache.result == 'success' && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'mcp-server-compile-test')) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ci-${{ github.ref }}-mcp-server-compile-test | |
| cancel-in-progress: true | |
| steps: | |
| - name: Restore checkout | |
| id: restore-checkout | |
| uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: . | |
| key: checkout-cgo-${{ github.run_id }}-${{ github.sha }} | |
| - name: Checkout on cache miss | |
| if: steps.restore-checkout.outputs.cache-hit != 'true' | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.sha }} | |
| fetch-depth: 2 | |
| persist-credentials: false | |
| - name: Set up Go | |
| id: setup-go | |
| uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v6 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Report Go cache status | |
| run: | | |
| if [ "${{ steps.setup-go.outputs.cache-hit }}" == "true" ]; then | |
| echo "✅ Go cache hit" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "⚠️ Go cache miss" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| - name: Build gh-aw binary | |
| run: make build | |
| - name: Create test workflow with error | |
| run: | | |
| mkdir -p .github/workflows | |
| cat > .github/workflows/test-invalid.md << 'EOF' | |
| --- | |
| on: push | |
| engine: copilot | |
| invalid_field: this will cause an error | |
| --- | |
| # Test Invalid Workflow | |
| This workflow has an invalid field that will cause a compilation error. | |
| EOF | |
| - name: Test MCP server compile tool | |
| run: | | |
| # Create a test script using the MCP Go SDK | |
| cat > test_mcp_compile.go << 'GOEOF' | |
| package main | |
| import ( | |
| "context" | |
| "encoding/json" | |
| "fmt" | |
| "os" | |
| "os/exec" | |
| "time" | |
| "github.com/modelcontextprotocol/go-sdk/mcp" | |
| ) | |
| func main() { | |
| // Create MCP client | |
| client := mcp.NewClient(&mcp.Implementation{ | |
| Name: "ci-test-client", | |
| Version: "1.0.0", | |
| }, nil) | |
| // Start the MCP server as a subprocess with absolute path | |
| binaryPath := "./gh-aw" | |
| serverCmd := exec.Command(binaryPath, "mcp-server", "--cmd", binaryPath) | |
| transport := &mcp.CommandTransport{Command: serverCmd} | |
| ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | |
| defer cancel() | |
| // Connect to the server | |
| session, err := client.Connect(ctx, transport, nil) | |
| if err != nil { | |
| fmt.Fprintf(os.Stderr, "Failed to connect to MCP server: %v\n", err) | |
| os.Exit(1) | |
| } | |
| defer session.Close() | |
| fmt.Println("✅ Successfully connected to MCP server") | |
| // Call the compile tool with the invalid workflow | |
| params := &mcp.CallToolParams{ | |
| Name: "compile", | |
| Arguments: map[string]any{ | |
| "workflows": []string{"test-invalid.md"}, | |
| }, | |
| } | |
| result, err := session.CallTool(ctx, params) | |
| if err != nil { | |
| fmt.Fprintf(os.Stderr, "MCP tool call returned error (this is expected): %v\n", err) | |
| // Check if the error contains expected error information | |
| fmt.Println("✅ Compile tool correctly returned an error") | |
| os.Exit(0) | |
| } | |
| // Get the result content | |
| if len(result.Content) == 0 { | |
| fmt.Fprintln(os.Stderr, "❌ Expected non-empty result from compile tool") | |
| os.Exit(1) | |
| } | |
| textContent, ok := result.Content[0].(*mcp.TextContent) | |
| if !ok { | |
| fmt.Fprintln(os.Stderr, "❌ Expected text content from compile tool") | |
| os.Exit(1) | |
| } | |
| fmt.Printf("Compile tool output:\n%s\n", textContent.Text) | |
| // Parse the JSON output to check for errors | |
| var compileResults []map[string]any | |
| if err := json.Unmarshal([]byte(textContent.Text), &compileResults); err != nil { | |
| fmt.Fprintf(os.Stderr, "Failed to parse JSON output: %v\n", err) | |
| os.Exit(1) | |
| } | |
| // Check if the workflow is marked as invalid | |
| if len(compileResults) == 0 { | |
| fmt.Fprintln(os.Stderr, "❌ Expected at least one workflow result") | |
| os.Exit(1) | |
| } | |
| result0 := compileResults[0] | |
| valid, ok := result0["valid"].(bool) | |
| if !ok { | |
| fmt.Fprintln(os.Stderr, "❌ Expected 'valid' field in result") | |
| os.Exit(1) | |
| } | |
| if valid { | |
| fmt.Fprintln(os.Stderr, "❌ Expected workflow to be invalid") | |
| os.Exit(1) | |
| } | |
| // Check that errors field exists and has at least one error | |
| errors, ok := result0["errors"].([]any) | |
| if !ok || len(errors) == 0 { | |
| fmt.Fprintln(os.Stderr, "❌ Expected errors array with at least one error") | |
| os.Exit(1) | |
| } | |
| fmt.Println("✅ Compile tool correctly reported validation errors:") | |
| errorsJSON, _ := json.MarshalIndent(errors, " ", " ") | |
| fmt.Printf(" %s\n", string(errorsJSON)) | |
| os.Exit(0) | |
| } | |
| GOEOF | |
| # Run the test | |
| go run test_mcp_compile.go | |
| - name: Report test results | |
| if: always() | |
| run: | | |
| echo "## MCP Server Compile Tool Test" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "This test verifies that:" >> $GITHUB_STEP_SUMMARY | |
| echo "1. The gh-aw MCP server can be started successfully" >> $GITHUB_STEP_SUMMARY | |
| echo "2. The compile tool can be invoked through the MCP server" >> $GITHUB_STEP_SUMMARY | |
| echo "3. The compile tool correctly detects and reports validation errors" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "✅ Test completed successfully" >> $GITHUB_STEP_SUMMARY | |
| cross-platform-build: | |
| needs: [checkout-cache, build, front-door-decision] | |
| if: always() && !cancelled() && needs.checkout-cache.result == 'success' && needs.build.result == 'success' && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'cross-platform-build')) | |
| name: Build & Test on ${{ matrix.os }} | |
| runs-on: ${{ matrix.os }} | |
| timeout-minutes: 20 | |
| permissions: | |
| contents: read | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [macos-latest, windows-latest] | |
| concurrency: | |
| group: ci-${{ github.ref }}-cross-platform-${{ matrix.os }} | |
| cancel-in-progress: true | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| - name: Set up Go | |
| id: setup-go | |
| uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v6 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Report Go cache status | |
| shell: bash | |
| run: | | |
| if [ "${{ steps.setup-go.outputs.cache-hit }}" == "true" ]; then | |
| echo "✅ Go cache hit" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "⚠️ Go cache miss" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| - name: Download dependencies with retry | |
| if: steps.setup-go.outputs.cache-hit != 'true' | |
| shell: bash | |
| run: | | |
| set -e | |
| MAX_RETRIES=3 | |
| RETRY_DELAY=5 | |
| for i in $(seq 1 $MAX_RETRIES); do | |
| echo "Attempt $i of $MAX_RETRIES: Downloading Go modules..." | |
| if go mod download; then | |
| echo "✅ Successfully downloaded Go modules" | |
| break | |
| else | |
| if [ $i -eq $MAX_RETRIES ]; then | |
| echo "❌ Failed to download Go modules after $MAX_RETRIES attempts" | |
| echo "This may indicate that proxy.golang.org is unreachable" | |
| echo "Please check network connectivity or consider vendoring dependencies" | |
| exit 1 | |
| fi | |
| echo "⚠️ Download failed, retrying in ${RETRY_DELAY}s..." | |
| sleep $RETRY_DELAY | |
| fi | |
| done | |
| - name: Verify dependencies | |
| run: go mod verify | |
| - name: Build gh-aw binary | |
| run: make build | |
| - name: Check generated fetch syntax with macOS Bash | |
| if: runner.os == 'macOS' | |
| shell: bash | |
| run: | | |
| export PATH="/bin:$PATH" | |
| bash --version | |
| go test ./pkg/workflow -run '^TestGenerateFetchStepSyntax$' -count=1 | |
| - name: Scan built binary with Microsoft Defender | |
| if: runner.os == 'Windows' | |
| shell: pwsh | |
| run: | | |
| $workspaceBinaryPath = Join-Path $PWD "gh-aw.exe" | |
| if (-not (Test-Path -Path $workspaceBinaryPath -PathType Leaf)) { | |
| Write-Host "Current directory: $($PWD.Path)" | |
| Write-Host "Directory contents:" | |
| Get-ChildItem -Name | ForEach-Object { Write-Host " - $_" } | |
| Write-Error "Built binary not found: $workspaceBinaryPath" | |
| exit 1 | |
| } | |
| $workspaceBinaryPath = (Resolve-Path -Path $workspaceBinaryPath).Path | |
| # Stabilize file before scanning to avoid transient build/link races. | |
| $stabilizationDelaySeconds = 3 | |
| $initialBinaryItem = Get-Item -LiteralPath $workspaceBinaryPath | |
| Start-Sleep -Seconds $stabilizationDelaySeconds | |
| $stableBinaryItem = Get-Item -LiteralPath $workspaceBinaryPath | |
| if ( | |
| $initialBinaryItem.Length -ne $stableBinaryItem.Length -or | |
| $initialBinaryItem.LastWriteTimeUtc -ne $stableBinaryItem.LastWriteTimeUtc | |
| ) { | |
| Write-Error "Built binary changed during stabilization window (${stabilizationDelaySeconds}s): $workspaceBinaryPath" | |
| Write-Error "Initial: size=$($initialBinaryItem.Length), lastWriteUtc=$($initialBinaryItem.LastWriteTimeUtc)" | |
| Write-Error "Current: size=$($stableBinaryItem.Length), lastWriteUtc=$($stableBinaryItem.LastWriteTimeUtc)" | |
| exit 1 | |
| } | |
| $workspaceBinaryHash = (Get-FileHash -LiteralPath $workspaceBinaryPath -Algorithm SHA256).Hash | |
| # Copy to a dedicated scan directory instead of scanning directly under D:\a\ workspace. | |
| $scanBaseRoot = $env:TEMP | |
| if (-not $scanBaseRoot) { | |
| $scanBaseRoot = "C:\Temp" | |
| } | |
| $scanBasePath = Join-Path $scanBaseRoot "defender-scan" | |
| New-Item -ItemType Directory -Path $scanBasePath -Force | Out-Null | |
| $scanFileName = "scan-$([guid]::NewGuid().ToString('N')).exe" | |
| $binaryPath = Join-Path $scanBasePath $scanFileName | |
| Copy-Item -LiteralPath $workspaceBinaryPath -Destination $binaryPath -Force | |
| if (-not (Test-Path -Path $binaryPath -PathType Leaf)) { | |
| Write-Error "Copied scan target not found: $binaryPath" | |
| exit 1 | |
| } | |
| $binaryPath = (Resolve-Path -Path $binaryPath).Path | |
| $workspaceRoot = $null | |
| if ($env:GITHUB_WORKSPACE -and (Test-Path -Path $env:GITHUB_WORKSPACE -PathType Container)) { | |
| $workspaceRoot = (Resolve-Path -Path $env:GITHUB_WORKSPACE).Path | |
| } | |
| if ($workspaceRoot -and $binaryPath.StartsWith($workspaceRoot, [System.StringComparison]::OrdinalIgnoreCase)) { | |
| Write-Error "Refusing to scan from workspace path: $binaryPath" | |
| exit 1 | |
| } | |
| # Validate copied file integrity before scanning. | |
| $scanBinaryItem = Get-Item -LiteralPath $binaryPath | |
| $scanBinaryHash = (Get-FileHash -LiteralPath $binaryPath -Algorithm SHA256).Hash | |
| if ($scanBinaryItem.Length -ne $stableBinaryItem.Length) { | |
| Write-Error "Copied file size mismatch: source=$($stableBinaryItem.Length), copy=$($scanBinaryItem.Length)" | |
| exit 1 | |
| } | |
| if ($scanBinaryHash -ne $workspaceBinaryHash) { | |
| Write-Error "Copied file hash mismatch: source=$workspaceBinaryHash, copy=$scanBinaryHash" | |
| exit 1 | |
| } | |
| $mpCmdRun = Join-Path $env:ProgramFiles "Windows Defender\MpCmdRun.exe" | |
| if (-not (Test-Path $mpCmdRun)) { | |
| $programFilesX86 = (Get-Item -Path "Env:ProgramFiles(x86)" -ErrorAction SilentlyContinue).Value | |
| if ($programFilesX86) { | |
| $mpCmdRun = Join-Path $programFilesX86 "Windows Defender\MpCmdRun.exe" | |
| } | |
| } | |
| if (-not (Test-Path $mpCmdRun)) { | |
| Write-Error "Microsoft Defender CLI not found (MpCmdRun.exe)" | |
| exit 1 | |
| } | |
| # Log Defender status, preference, and execution details for diagnostics. | |
| Write-Host "=== Microsoft Defender diagnostic info ===" | |
| try { | |
| $mpStatus = Get-MpComputerStatus | |
| } catch { | |
| $mpStatus = $null | |
| Write-Host "Could not query Microsoft Defender status: $_" | |
| } | |
| if ($mpStatus) { | |
| Write-Host "AntivirusEnabled: $($mpStatus.AntivirusEnabled)" | |
| Write-Host "RealTimeProtectionEnabled: $($mpStatus.RealTimeProtectionEnabled)" | |
| Write-Host "AntivirusSignatureVersion: $($mpStatus.AntivirusSignatureVersion)" | |
| Write-Host "AntivirusSignatureLastUpdated: $($mpStatus.AntivirusSignatureLastUpdated)" | |
| Write-Host "AMProductVersion: $($mpStatus.AMProductVersion)" | |
| Write-Host "AMEngineVersion: $($mpStatus.AMEngineVersion)" | |
| } else { | |
| Write-Host "(Get-MpComputerStatus unavailable)" | |
| } | |
| try { | |
| $mpPreference = Get-MpPreference | |
| } catch { | |
| $mpPreference = $null | |
| Write-Host "Could not query Microsoft Defender preferences: $_" | |
| } | |
| if ($mpPreference) { | |
| Write-Host "ExclusionPath: $(@($mpPreference.ExclusionPath) -join '; ')" | |
| Write-Host "ExclusionExtension: $(@($mpPreference.ExclusionExtension) -join '; ')" | |
| Write-Host "ExclusionProcess: $(@($mpPreference.ExclusionProcess) -join '; ')" | |
| Write-Host "ExclusionIpAddress: $(@($mpPreference.ExclusionIpAddress) -join '; ')" | |
| } else { | |
| Write-Host "(Get-MpPreference unavailable)" | |
| } | |
| $winDefendService = Get-Service -Name WinDefend -ErrorAction SilentlyContinue | |
| if ($winDefendService) { | |
| Write-Host "WinDefend service status: $($winDefendService.Status)" | |
| Write-Host "WinDefend service start: $($winDefendService.StartType)" | |
| } else { | |
| Write-Host "(WinDefend service unavailable)" | |
| } | |
| if ($mpStatus) { | |
| Write-Host "AMRunningMode: $($mpStatus.AMRunningMode)" | |
| Write-Host "IoavProtectionEnabled: $($mpStatus.IoavProtectionEnabled)" | |
| } | |
| Write-Host "MpCmdRun.exe path: $mpCmdRun" | |
| Write-Host "Workspace binary: $workspaceBinaryPath" | |
| Write-Host "Workspace size: $($stableBinaryItem.Length) bytes" | |
| Write-Host "Workspace SHA256: $workspaceBinaryHash" | |
| Write-Host "Binary to scan: $binaryPath" | |
| Write-Host "Binary size: $($scanBinaryItem.Length) bytes" | |
| Write-Host "Binary SHA256: $scanBinaryHash" | |
| Write-Host "==========================================" | |
| # ScanType 3 = custom scan. Use -File to scan only the copied binary. | |
| # Capture output (2>&1 merges stderr into the output stream so all | |
| # MpCmdRun messages are available for strict failure checks below. | |
| # Retry on transient service errors (e.g. WinDefend in StopPending state, | |
| # hr = 0x800106ba) which can occur transiently on Windows runners. | |
| $scanAttempts = 3 | |
| $scanDelaySeconds = 15 | |
| $output = $null | |
| $scanExitCode = 0 | |
| $outputText = "" | |
| for ($scanAttempt = 1; $scanAttempt -le $scanAttempts; $scanAttempt++) { | |
| if ($scanAttempt -gt 1) { | |
| Write-Host "Retrying Microsoft Defender scan (attempt $scanAttempt/$scanAttempts)..." | |
| } | |
| $output = & $mpCmdRun -Scan -ScanType 3 -File $binaryPath -DisableRemediation 2>&1 | ForEach-Object { "$_" } | |
| $scanExitCode = $LASTEXITCODE | |
| $outputText = @($output) -join "`n" | |
| $isTransientError = $scanExitCode -ne 0 -and $outputText -imatch "0x800106ba" | |
| if (-not $isTransientError -or $scanAttempt -eq $scanAttempts) { | |
| break | |
| } | |
| Write-Warning "Defender scan failed with a transient service error (attempt $scanAttempt/$scanAttempts). Retrying in $scanDelaySeconds seconds..." | |
| Start-Sleep -Seconds $scanDelaySeconds | |
| } | |
| Write-Host "=== MpCmdRun output ===" | |
| $output | ForEach-Object { Write-Host $_ } | |
| Write-Host "Exit code: $scanExitCode" | |
| Write-Host "=======================" | |
| # Write diagnostic info and scan output to a log file for artifact upload. | |
| $logFile = Join-Path $env:RUNNER_TEMP "defender-scan-log.txt" | |
| $mpStatusLines = if ($mpStatus) { | |
| @( | |
| "AntivirusEnabled: $($mpStatus.AntivirusEnabled)", | |
| "RealTimeProtectionEnabled: $($mpStatus.RealTimeProtectionEnabled)", | |
| "AntivirusSignatureVersion: $($mpStatus.AntivirusSignatureVersion)", | |
| "AntivirusSignatureLastUpdated: $($mpStatus.AntivirusSignatureLastUpdated)", | |
| "AMProductVersion: $($mpStatus.AMProductVersion)", | |
| "AMEngineVersion: $($mpStatus.AMEngineVersion)", | |
| "AMRunningMode: $($mpStatus.AMRunningMode)", | |
| "IoavProtectionEnabled: $($mpStatus.IoavProtectionEnabled)" | |
| ) | |
| } else { | |
| @("(Get-MpComputerStatus unavailable)") | |
| } | |
| $mpPrefLines = if ($mpPreference) { | |
| @( | |
| "ExclusionPath: $(@($mpPreference.ExclusionPath) -join '; ')", | |
| "ExclusionExtension: $(@($mpPreference.ExclusionExtension) -join '; ')", | |
| "ExclusionProcess: $(@($mpPreference.ExclusionProcess) -join '; ')", | |
| "ExclusionIpAddress: $(@($mpPreference.ExclusionIpAddress) -join '; ')" | |
| ) | |
| } else { | |
| @("(Get-MpPreference unavailable)") | |
| } | |
| $winDefendLines = if ($winDefendService) { | |
| @( | |
| "WinDefend service status: $($winDefendService.Status)", | |
| "WinDefend service start: $($winDefendService.StartType)" | |
| ) | |
| } else { | |
| @("(WinDefend service unavailable)") | |
| } | |
| $logContent = @( | |
| "=== Microsoft Defender diagnostic info ===", | |
| ($mpStatusLines -join "`n"), | |
| ($mpPrefLines -join "`n"), | |
| ($winDefendLines -join "`n"), | |
| "MpCmdRun.exe path: $mpCmdRun", | |
| "Workspace binary: $workspaceBinaryPath", | |
| "Workspace size: $($stableBinaryItem.Length) bytes", | |
| "Workspace SHA256: $workspaceBinaryHash", | |
| "Binary to scan: $binaryPath", | |
| "Binary size: $($scanBinaryItem.Length) bytes", | |
| "Binary SHA256: $scanBinaryHash", | |
| "==========================================", | |
| "", | |
| "=== MpCmdRun output ===", | |
| $outputText, | |
| "Exit code: $scanExitCode", | |
| "=======================" | |
| ) -join "`n" | |
| try { | |
| Set-Content -Path $logFile -Value $logContent -Encoding UTF8 | |
| } catch { | |
| Write-Host "Warning: could not write defender scan log file: $_" | |
| } | |
| # Exit code alone is not enough: explicitly parse output to confirm scan execution. | |
| $skipped = $output | Where-Object { $_ -imatch "\bwas skipped\b|\bcannot be scanned\b|\bnot performed\b|\b(?:file|scan).*\bexcluded\b" } | |
| $threatLines = $output | Where-Object { $_ -match "\bThreat\b" } | |
| $scanStarted = $outputText -imatch "\bScan starting\b" | |
| $scanFinished = $outputText -imatch "\bScan finished\b" | |
| if ($scanExitCode -ne 0) { | |
| Write-Error "Microsoft Defender scan failed with exit code $scanExitCode" | |
| exit $scanExitCode | |
| } | |
| if ($skipped) { | |
| Write-Error "Microsoft Defender scan was skipped for $binaryPath - the binary was NOT scanned." | |
| Write-Error "Possible causes: file/path exclusion, stale signatures, or protection disabled." | |
| # Wrap with @() so a single matched line is joined as one line, not character-by-character. | |
| Write-Error "Skipped output: $(@($skipped) -join '; ')" | |
| exit 1 | |
| } | |
| if ($threatLines) { | |
| Write-Error "Microsoft Defender reported threat indicators in scan output." | |
| Write-Error "Threat output: $(@($threatLines) -join '; ')" | |
| exit 1 | |
| } | |
| if (-not ($scanStarted -and $scanFinished)) { | |
| Write-Error "Could not confirm scan completion from MpCmdRun output (expected both 'Scan starting' and 'Scan finished')." | |
| exit 1 | |
| } | |
| Write-Host "✅ Microsoft Defender scan completed successfully for $binaryPath" | |
| - name: Upload Defender scan logs | |
| if: always() && runner.os == 'Windows' | |
| uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 | |
| with: | |
| name: defender-scan-log-${{ github.run_id }}-${{ github.run_attempt }} | |
| path: ${{ runner.temp }}/defender-scan-log.txt | |
| retention-days: 7 | |
| - name: Create test workflow | |
| shell: bash | |
| run: | | |
| mkdir -p .github/workflows | |
| cat > .github/workflows/test-cross-platform.md << 'EOF' | |
| --- | |
| on: push | |
| engine: copilot | |
| --- | |
| # Test Workflow for Cross-Platform CI | |
| This is a simple test workflow to verify the compile command works correctly. | |
| ## Task | |
| Echo hello world. | |
| EOF | |
| - name: Test compile command | |
| shell: bash | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| echo "Testing compile command on ${{ matrix.os }}..." | |
| # Determine binary name based on OS | |
| if [[ "$RUNNER_OS" == "Windows" ]]; then | |
| BINARY="./gh-aw.exe" | |
| else | |
| BINARY="./gh-aw" | |
| fi | |
| # Verify binary exists | |
| if [ ! -f "$BINARY" ]; then | |
| echo "❌ Binary not found: $BINARY" | |
| ls -la | |
| exit 1 | |
| fi | |
| # Run compile command | |
| "$BINARY" compile test-cross-platform --verbose | |
| # Check if lock file was generated | |
| if [ -f ".github/workflows/test-cross-platform.lock.yml" ]; then | |
| echo "✅ Compile succeeded - lock file generated" | |
| else | |
| echo "❌ Compile failed - no lock file generated" | |
| exit 1 | |
| fi | |
| echo "## Cross-Platform Test Results" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "✅ Successfully compiled workflow on ${{ matrix.os }}" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Platform:** ${{ matrix.os }}" >> $GITHUB_STEP_SUMMARY | |
| echo "**Binary:** $BINARY" >> $GITHUB_STEP_SUMMARY | |
| echo "**Go version:** $(go version)" >> $GITHUB_STEP_SUMMARY | |
| - name: Clean up test files | |
| if: always() | |
| shell: bash | |
| run: | | |
| rm -f .github/workflows/test-cross-platform.md | |
| rm -f .github/workflows/test-cross-platform.lock.yml | |
| alpine-container-test: | |
| if: always() && !cancelled() && needs.checkout-cache.result == 'success' && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'alpine-container-test')) | |
| name: Alpine Container Test | |
| needs: [checkout-cache, front-door-decision] | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ci-${{ github.ref }}-alpine-container | |
| cancel-in-progress: true | |
| steps: | |
| - name: Restore checkout | |
| id: restore-checkout | |
| uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: . | |
| key: checkout-cgo-${{ github.run_id }}-${{ github.sha }} | |
| - name: Checkout on cache miss | |
| if: steps.restore-checkout.outputs.cache-hit != 'true' | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.sha }} | |
| fetch-depth: 2 | |
| persist-credentials: false | |
| - name: Set up Go | |
| id: setup-go | |
| uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v6 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Report Go cache status | |
| run: | | |
| if [ "${{ steps.setup-go.outputs.cache-hit }}" == "true" ]; then | |
| echo "✅ Go cache hit" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "⚠️ Go cache miss" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| - name: Download dependencies with retry | |
| if: steps.setup-go.outputs.cache-hit != 'true' | |
| run: | | |
| set -e | |
| MAX_RETRIES=3 | |
| RETRY_DELAY=5 | |
| for i in $(seq 1 $MAX_RETRIES); do | |
| echo "Attempt $i of $MAX_RETRIES: Downloading Go modules..." | |
| if go mod download; then | |
| echo "✅ Successfully downloaded Go modules" | |
| break | |
| else | |
| if [ $i -eq $MAX_RETRIES ]; then | |
| echo "❌ Failed to download Go modules after $MAX_RETRIES attempts" | |
| echo "This may indicate that proxy.golang.org is unreachable" | |
| echo "Please check network connectivity or consider vendoring dependencies" | |
| exit 1 | |
| fi | |
| echo "⚠️ Download failed, retrying in ${RETRY_DELAY}s..." | |
| sleep $RETRY_DELAY | |
| fi | |
| done | |
| - name: Verify dependencies | |
| run: go mod verify | |
| - name: Build Linux binary for Alpine | |
| run: make build-linux | |
| - name: Build Alpine Docker image | |
| run: | | |
| echo "Building Alpine Docker image..." | |
| docker build -t gh-aw-alpine:test \ | |
| --build-arg BINARY=gh-aw-linux-amd64 \ | |
| -f Dockerfile . | |
| echo "✅ Alpine Docker image built successfully" | |
| - name: Test Docker image basic commands | |
| run: | | |
| echo "Testing Docker image basic commands..." | |
| docker run --rm gh-aw-alpine:test --version | |
| docker run --rm gh-aw-alpine:test --help | |
| echo "✅ Basic commands work" | |
| - name: Create test workflow in container | |
| run: | | |
| echo "Creating test workflow file..." | |
| mkdir -p test-workspace/.github/workflows | |
| cat > test-workspace/.github/workflows/test-alpine.md << 'EOF' | |
| --- | |
| on: push | |
| engine: copilot | |
| --- | |
| # Test Workflow for Alpine Container | |
| This is a simple test workflow to verify the compile command works correctly in Alpine container. | |
| ## Task | |
| Echo hello from Alpine container. | |
| EOF | |
| echo "✅ Test workflow created" | |
| - name: Run compile through Alpine container | |
| run: | | |
| echo "Running compile command through Alpine container..." | |
| docker run --rm \ | |
| -v "$(pwd)/test-workspace:/workspace" \ | |
| -w /workspace \ | |
| gh-aw-alpine:test compile test-alpine --verbose | |
| echo "✅ Compile command executed" | |
| - name: Verify lock file generation | |
| run: | | |
| echo "Verifying lock file was generated..." | |
| if [ -f "test-workspace/.github/workflows/test-alpine.lock.yml" ]; then | |
| echo "✅ Lock file generated successfully" | |
| echo "" | |
| echo "Lock file contents:" | |
| head -20 test-workspace/.github/workflows/test-alpine.lock.yml | |
| else | |
| echo "❌ Lock file not found" | |
| ls -la test-workspace/.github/workflows/ | |
| exit 1 | |
| fi | |
| - name: Generate test summary | |
| if: always() | |
| run: | | |
| echo "## Alpine Container Test Results" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "This test verifies that:" >> $GITHUB_STEP_SUMMARY | |
| echo "1. The Alpine Docker image can be built successfully" >> $GITHUB_STEP_SUMMARY | |
| echo "2. The gh-aw binary works correctly in Alpine Linux" >> $GITHUB_STEP_SUMMARY | |
| echo "3. The compile command can process workflows in the container" >> $GITHUB_STEP_SUMMARY | |
| echo "4. Lock files are generated correctly" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| if [ -f "test-workspace/.github/workflows/test-alpine.lock.yml" ]; then | |
| echo "✅ All tests passed successfully" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "❌ Lock file generation failed" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| - name: Clean up test files | |
| if: always() | |
| run: | | |
| rm -rf test-workspace | |
| safe-outputs-conformance: | |
| needs: [checkout-cache, front-door-decision] | |
| if: always() && !cancelled() && needs.checkout-cache.result == 'success' && (github.event_name != 'pull_request' || needs.front-door-decision.result != 'success' || !needs.front-door-decision.outputs.suite_ids || contains(fromJSON(needs.front-door-decision.outputs.suite_ids), 'safe-outputs-conformance')) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Restore checkout | |
| id: restore-checkout | |
| uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: . | |
| key: checkout-cgo-${{ github.run_id }}-${{ github.sha }} | |
| - name: Checkout on cache miss | |
| if: steps.restore-checkout.outputs.cache-hit != 'true' | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ github.sha }} | |
| fetch-depth: 2 | |
| persist-credentials: false | |
| - name: Run Safe Outputs Conformance Checker | |
| id: conformance | |
| continue-on-error: true | |
| run: | | |
| echo "## Safe Outputs Conformance Check" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| # Run the conformance checker and capture output | |
| if ./scripts/check-safe-outputs-conformance.sh > conformance-output.txt 2>&1; then | |
| echo "✅ All conformance checks passed" >> $GITHUB_STEP_SUMMARY | |
| EXIT_CODE=0 | |
| else | |
| EXIT_CODE=$? | |
| if [ $EXIT_CODE -eq 2 ]; then | |
| echo "⚠️ Critical conformance issues found (treated as warning)" >> $GITHUB_STEP_SUMMARY | |
| elif [ $EXIT_CODE -eq 1 ]; then | |
| echo "⚠️ High priority conformance issues found (treated as warning)" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "⚠️ Conformance check completed with warnings" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| fi | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### Conformance Check Output" >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| cat conformance-output.txt >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| # Also output to console for visibility | |
| echo "=== Conformance Check Results ===" | |
| cat conformance-output.txt | |
| # Always succeed (treat as warning only) | |
| exit 0 | |
| - name: Upload conformance report | |
| if: always() | |
| uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 | |
| with: | |
| name: safe-outputs-conformance-report | |
| path: conformance-output.txt | |
| retention-days: 7 | |
| summarize-timing: | |
| name: Summarize workflow timing | |
| needs: | |
| - front-door-decision | |
| - front-door-conformance | |
| - test-pageindex-workflow | |
| - checkout-cache | |
| - verify-integration-build | |
| - test | |
| - test-slow | |
| - canary-go | |
| - impacted-go-tests | |
| - native-javascript-tests | |
| - build | |
| - build-wasm | |
| - validate-yaml | |
| - check-validator-sizes | |
| - lint-go-format | |
| - lint-go-golangci | |
| - lint-go-govulncheck | |
| - lint-go-custom | |
| - lint-error-messages | |
| - actions-build | |
| - fuzz | |
| - security | |
| - security-scan | |
| - mcp-server-compile-test | |
| - cross-platform-build | |
| - alpine-container-test | |
| - safe-outputs-conformance | |
| if: always() | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| permissions: | |
| actions: write | |
| steps: | |
| - name: Delete checkout cache | |
| continue-on-error: true | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| CACHE_KEY: checkout-cgo-${{ github.run_id }}-${{ github.sha }} | |
| run: | | |
| cache_id=$(gh cache list --repo "$GITHUB_REPOSITORY" --key "$CACHE_KEY" --ref "$GITHUB_REF" --limit 1 --json id,key --jq '.[] | select(.key == env.CACHE_KEY) | .id') | |
| if [ -n "$cache_id" ]; then | |
| gh cache delete "$cache_id" --repo "$GITHUB_REPOSITORY" | |
| fi | |
| - name: Summarize job and step durations | |
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 | |
| with: | |
| retries: 3 | |
| script: | | |
| const fs = require('fs'); | |
| const formatDuration = (startedAt, completedAt) => { | |
| if (!startedAt || !completedAt) return 'n/a'; | |
| const milliseconds = new Date(completedAt) - new Date(startedAt); | |
| if (!Number.isFinite(milliseconds) || milliseconds < 0) return 'n/a'; | |
| const totalSeconds = Math.round(milliseconds / 1000); | |
| const hours = Math.floor(totalSeconds / 3600); | |
| const minutes = Math.floor((totalSeconds % 3600) / 60); | |
| const seconds = totalSeconds % 60; | |
| if (hours > 0) return `${hours}h ${minutes}m ${seconds}s`; | |
| if (minutes > 0) return `${minutes}m ${seconds}s`; | |
| return `${seconds}s`; | |
| }; | |
| const cell = (value) => String(value ?? '').replace(/\|/g, '\\|').replace(/\r?\n/g, ' '); | |
| let jobs; | |
| try { | |
| jobs = await github.paginate(github.rest.actions.listJobsForWorkflowRun, { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| run_id: context.runId, | |
| per_page: 100, | |
| }); | |
| } catch (error) { | |
| if (error.status !== 429 && (error.status !== 403 || !/rate limit exceeded|exceeded a secondary rate limit/i.test(error.message))) throw error; | |
| const message = 'Workflow timing is unavailable because the GitHub Actions API rate limit was exceeded. Build and test results are unchanged; see the individual job logs.'; | |
| core.warning(message); | |
| fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, `## Workflow timing summary\n\n${message}\n`); | |
| return; | |
| } | |
| const rows = []; | |
| for (const job of jobs) { | |
| if (job.name === 'Summarize workflow timing' || job.name === 'summarize-timing') continue; | |
| rows.push(`| [${cell(job.name)}](${job.html_url}) | job | ${cell(job.conclusion || job.status)} | ${formatDuration(job.started_at, job.completed_at)} |`); | |
| for (const step of job.steps || []) { | |
| rows.push(`| ${cell(`- ${step.name}`)} | step | ${cell(step.conclusion || step.status)} | ${formatDuration(step.started_at, step.completed_at)} |`); | |
| } | |
| } | |
| const summary = [ | |
| '## Workflow timing summary', | |
| '', | |
| 'Step-level timing collected from the GitHub Actions API for this run.', | |
| '', | |
| '| Name | Type | Result | Duration |', | |
| '| --- | --- | --- | --- |', | |
| ...rows, | |
| '', | |
| ].join('\n'); | |
| fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, summary); |