name: API Consistency Check
on:
pull_request:
paths:
- 'src/service/**/*.rs'
- 'src/core/**/*.rs'
push:
branches:
- main
paths:
- 'src/service/**/*.rs'
- 'src/core/**/*.rs'
permissions:
contents: read
pull-requests: write
issues: write
jobs:
check-api-consistency:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache target directory
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-target-${{ hashFiles('**/Cargo.lock') }}
- name: Build API Consistency Checker
run: |
cargo build --release --bin enhanced_api_checker
cargo build --release --bin api_compatibility_tester
- name: Run API Consistency Check
id: api_check
run: |
echo "## API Consistency Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Run enhanced API checker and capture output
./target/release/enhanced_api_checker | tee api_check_output.txt
# Extract metrics
STANDARD_RESPONSE=$(grep "StandardResponse coverage" api_check_output.txt | grep -oE '[0-9.]+%' | head -1)
BUILDER_PATTERN=$(grep "Builder pattern coverage" api_check_output.txt | grep -oE '[0-9.]+%' | head -1)
echo "### Coverage Metrics" >> $GITHUB_STEP_SUMMARY
echo "- StandardResponse coverage: $STANDARD_RESPONSE" >> $GITHUB_STEP_SUMMARY
echo "- Builder pattern coverage: $BUILDER_PATTERN" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Set outputs for badge generation
echo "standard_response=$STANDARD_RESPONSE" >> $GITHUB_OUTPUT
echo "builder_pattern=$BUILDER_PATTERN" >> $GITHUB_OUTPUT
# Check thresholds
SR_VALUE=$(echo $STANDARD_RESPONSE | tr -d '%')
BP_VALUE=$(echo $BUILDER_PATTERN | tr -d '%')
if (( $(echo "$SR_VALUE < 80" | bc -l) )); then
echo "⚠️ Warning: StandardResponse coverage below 80% threshold" >> $GITHUB_STEP_SUMMARY
fi
if (( $(echo "$BP_VALUE < 60" | bc -l) )); then
echo "⚠️ Warning: Builder pattern coverage below 60% threshold" >> $GITHUB_STEP_SUMMARY
fi
- name: Run Compatibility Tests
run: |
echo "### Compatibility Test Results" >> $GITHUB_STEP_SUMMARY
./target/release/api_compatibility_tester >> $GITHUB_STEP_SUMMARY 2>&1
- name: Comment PR with Results
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const output = fs.readFileSync('api_check_output.txt', 'utf8');
// Extract key metrics
const srMatch = output.match(/StandardResponse coverage: ([0-9.]+%)/);
const bpMatch = output.match(/Builder pattern coverage: ([0-9.]+%)/);
const srCoverage = srMatch ? srMatch[1] : 'N/A';
const bpCoverage = bpMatch ? bpMatch[1] : 'N/A';
const comment = `## 📊 API Consistency Check Results
### Coverage Metrics
- **StandardResponse coverage**: ${srCoverage}
- **Builder pattern coverage**: ${bpCoverage}
### Targets
- StandardResponse: 80%+
- Builder pattern: 60%+
<details>
<summary>View detailed report</summary>
\`\`\`
${output}
\`\`\`
</details>`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
- name: Upload Report Artifact
uses: actions/upload-artifact@v4
with:
name: api-consistency-report
path: api_check_output.txt