Skip to content

[spec-enforcer] Enforce specifications for workflow/lint, workflowcontract, workflow/shellpattern #23668

[spec-enforcer] Enforce specifications for workflow/lint, workflowcontract, workflow/shellpattern

[spec-enforcer] Enforce specifications for workflow/lint, workflowcontract, workflow/shellpattern #23668

Workflow file for this run

name: CWI
on:
push:
branches: [main]
paths:
- '**/*.go'
- 'cmd/**'
- 'pkg/**'
- 'go.mod'
- 'go.sum'
- '.github/workflows/CWI.yml'
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- '**/*.go'
- 'cmd/**'
- 'pkg/**'
- 'go.mod'
- 'go.sum'
- '.github/workflows/CWI.yml'
workflow_dispatch:
jobs:
checkout-cache:
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 1
persist-credentials: false
- 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-cwi-${{ github.run_id }}-${{ github.sha }}
enableCrossOsArchive: true
build-windows:
name: Build Windows CLI
needs: [checkout-cache]
runs-on: windows-latest
timeout-minutes: 15
permissions:
contents: read
steps:
- name: Restore checkout
id: restore-checkout
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .
key: checkout-cwi-${{ github.run_id }}-${{ github.sha }}
enableCrossOsArchive: true
- 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: 1
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
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 Go modules
if: steps.setup-go.outputs.cache-hit != 'true'
shell: bash
run: go mod download
- name: Verify dependencies
shell: bash
run: go mod verify
- name: Build Windows binary
shell: bash
run: go build -ldflags "-s -w" -o gh-aw.exe ./cmd/gh-aw
- name: Upload Windows binary
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: gh-aw-windows-amd64
path: gh-aw.exe
retention-days: 1
integration:
name: "Windows Integration"
if: github.event_name != 'pull_request'
needs:
- checkout-cache
- build-windows
runs-on: windows-latest
timeout-minutes: 15
permissions:
contents: read
steps:
- name: Restore checkout
id: restore-checkout
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: .
key: checkout-cwi-${{ github.run_id }}-${{ github.sha }}
enableCrossOsArchive: true
- 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: 1
persist-credentials: false
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v6
with:
go-version-file: go.mod
cache: true
- name: Download Windows binary
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: gh-aw-windows-amd64
- name: Run version integration tests
shell: bash
env:
GH_AW_INTEGRATION_BINARY: ${{ github.workspace }}/gh-aw.exe
run: |
go test -v -timeout=5m -tags 'integration' -run 'TestVersion' ./cmd/gh-aw
- name: Run compile integration tests
shell: bash
env:
GH_AW_INTEGRATION_BINARY: ${{ github.workspace }}/gh-aw.exe
run: |
go test -v -timeout=5m -tags 'integration' -run '^TestCompileIntegration$' ./pkg/cli
- name: Run audit integration tests
shell: bash
env:
GH_AW_INTEGRATION_BINARY: ${{ github.workspace }}/gh-aw.exe
run: |
go test -v -timeout=5m -tags 'integration' -run '^TestAudit' ./pkg/cli
- name: Run logs integration tests
shell: bash
env:
GH_AW_INTEGRATION_BINARY: ${{ github.workspace }}/gh-aw.exe
run: |
go test -v -timeout=5m -tags 'integration' -run 'TestLogs' ./pkg/cli
- name: Run Windows MCP server integration test
shell: bash
env:
GH_AW_INTEGRATION_BINARY: ${{ github.workspace }}/gh-aw.exe
run: |
go test -v -timeout=5m -tags 'integration' -run '^TestMCPServer_WindowsSmokeCommands$' ./pkg/cli
summarize-timing:
name: Summarize workflow timing
needs:
- build-windows
- integration
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-cwi-${{ 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);