Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 29 additions & 112 deletions .github/workflows/auto-fix-build-errors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,56 +23,27 @@ jobs:
git lfs install
git lfs pull

- name: Download Artifacts
uses: actions/github-script@v7
- name: Setup Node.js
uses: actions/setup-node@v4
with:
script: |
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }}
});

const buildLog = artifacts.data.artifacts.find(artifact => artifact.name === "ipa-files");
if (!buildLog) {
console.log("No build log artifacts found.");
return;
}

const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: buildLog.id,
archive_format: 'zip'
});

const fs = require('fs');
fs.writeFileSync('artifact.zip', Buffer.from(download.data));

console.log("Downloaded artifact.zip");
node-version: '20'

- name: Extract Artifacts
- name: Download Artifacts
run: |
mkdir -p artifact-contents
unzip -o artifact.zip -d artifact-contents || echo "No artifacts to extract"
ls -la artifact-contents || echo "No artifact contents"
# Make scripts executable
chmod +x scripts/ci/*.sh

if [ -f "artifact-contents/build_log.txt" ]; then
echo "Build log found, copying for analysis..."
cp artifact-contents/build_log.txt ./
else
echo "::warning::No build log found in artifacts"
fi

- name: Install Python Dependencies
run: |
pip3 install html
# Download artifacts using the helper script
./scripts/ci/download-artifacts.sh "${{ github.event.workflow_run.id }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Run Build Error Analysis
id: analysis
run: |
chmod +x scripts/ci/auto-fix-build-errors.py
# No special Python libraries needed - using standard library only

# Run analysis script
if [ -f "build_log.txt" ]; then
echo "Analyzing build log..."
python3 scripts/ci/auto-fix-build-errors.py build_log.txt || echo "Analysis completed with errors"
Expand Down Expand Up @@ -105,45 +76,15 @@ jobs:
- name: Generate Summary
if: steps.analysis.outputs.report_generated == 'true'
run: |
echo "## 📊 Build Error Analysis Report" > $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "A detailed analysis of the build errors has been generated." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY

# Extract summary information from the JSON report
if [ -f "build_error_report.json" ]; then
ERROR_COUNT=$(grep -o '"error_count":[0-9]*' build_error_report.json | cut -d ":" -f2)
WARNING_COUNT=$(grep -o '"warning_count":[0-9]*' build_error_report.json | cut -d ":" -f2)

echo "### Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "* 🛑 **Errors**: ${ERROR_COUNT:-0}" >> $GITHUB_STEP_SUMMARY
echo "* ⚠️ **Warnings**: ${WARNING_COUNT:-0}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
fi

echo "### Common Issues" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY

# Include top issues from the report
if [ -f "build_error_report.txt" ]; then
# Extract top error types
echo "#### Top Error Types" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
grep -A 5 "ERROR TYPES:" build_error_report.txt >> $GITHUB_STEP_SUMMARY || echo "No error types found"
echo '```' >> $GITHUB_STEP_SUMMARY
fi

echo "" >> $GITHUB_STEP_SUMMARY
echo "Please download the full HTML report from the artifacts for a comprehensive analysis." >> $GITHUB_STEP_SUMMARY
# Use the dedicated script to generate the GitHub step summary
./scripts/ci/generate-report-summary.sh

- name: Create Comment on PR
- name: Determine PR Number
id: pr-finder
if: github.event.workflow_run.event == 'pull_request' && steps.analysis.outputs.report_generated == 'true'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');

// Get PR number from the workflow run
const run = await github.rest.actions.getWorkflowRun({
owner: context.repo.owner,
Expand All @@ -153,43 +94,19 @@ jobs:

// Extract PR number from the run data
const prNumber = run.data.pull_requests[0]?.number;
if (!prNumber) {
if (prNumber) {
console.log(`Found PR number: ${prNumber}`);
return prNumber;
} else {
console.log("Could not determine PR number from workflow run");
return;
return '';
}

// Read summary information from the JSON report
if (fs.existsSync('build_error_report.json')) {
const reportData = JSON.parse(fs.readFileSync('build_error_report.json', 'utf8'));
const errorCount = reportData.summary.error_count;
const warningCount = reportData.summary.warning_count;

// Create a comment on the PR
const body = `## 🔍 Build Error Analysis Report

This PR contains:
- 🛑 **${errorCount} errors**
- ⚠️ **${warningCount} warnings**

<details>
<summary>Click to see error type breakdown</summary>
result-encoding: string

\`\`\`
${Object.entries(reportData.summary.error_types)
.map(([type, count]) => `${type}: ${count}`)
.join('\n')}
\`\`\`
</details>

Please check the workflow run for the full HTML report with error details and suggestions for fixing them.
`;

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: body.replace(/^\s+/gm, '') // Remove leading spaces
});

console.log(`Created comment on PR #${prNumber}`);
}
- name: Create Comment on PR
if: github.event.workflow_run.event == 'pull_request' && steps.analysis.outputs.report_generated == 'true' && steps.pr-finder.outputs.result != ''
run: |
# Use dedicated script to create PR comment
./scripts/ci/create-pr-comment.sh "${{ steps.pr-finder.outputs.result }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
112 changes: 112 additions & 0 deletions scripts/ci/create-pr-comment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/bin/bash
set -eo pipefail

# This script creates a PR comment with build error analysis
# It requires a GitHub token and PR number

echo "💬 Creating PR comment with build error analysis..."

# Validate input parameters
PR_NUMBER="$1"
if [ -z "$PR_NUMBER" ]; then
echo "::error::No PR number provided"
exit 1
fi

if [ ! -f "build_error_report.json" ]; then
echo "::error::No build error report found"
exit 1
fi

# Create a temporary directory for the Node.js script
mkdir -p temp
cat > temp/create-comment.js << 'EOL'
const fs = require('fs');

async function createComment() {
try {
// Parse inputs
const prNumber = process.env.PR_NUMBER;
const token = process.env.GITHUB_TOKEN;
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');

if (!prNumber || !token || !owner || !repo) {
console.error('Missing required environment variables');
process.exit(1);
}

console.log(`Creating comment on PR #${prNumber} in ${owner}/${repo}`);

// Create the Octokit client
const { Octokit } = require('@octokit/rest');
const octokit = new Octokit({ auth: token });

// Read the error report data
if (!fs.existsSync('build_error_report.json')) {
console.error('Error report JSON file not found');
process.exit(1);
}

const reportData = JSON.parse(fs.readFileSync('build_error_report.json', 'utf8'));
const errorCount = reportData.summary.error_count;
const warningCount = reportData.summary.warning_count;

// Format error types for display
let errorTypesList = '';
if (reportData.summary.error_types) {
errorTypesList = Object.entries(reportData.summary.error_types)
.map(([type, count]) => `${type}: ${count}`)
.join('\n');
}

// Create the comment body
const body = `## 🔍 Build Error Analysis Report

This PR contains:
- 🛑 **${errorCount} errors**
- ⚠️ **${warningCount} warnings**

<details>
<summary>Click to see error type breakdown</summary>

\`\`\`
${errorTypesList}
\`\`\`
</details>

Please check the workflow run for the full HTML report with error details and suggestions for fixing them.
`;

// Create the comment
await octokit.issues.createComment({
owner,
repo,
issue_number: prNumber,
body
});

console.log(`Successfully created comment on PR #${prNumber}`);
process.exit(0);
} catch (error) {
console.error('Error creating PR comment:', error.message);
process.exit(1);
}
}

createComment();
EOL

# Install octokit if not already installed
npm install @octokit/rest

# Set environment variables and run the script
export PR_NUMBER="$PR_NUMBER"
export GITHUB_TOKEN="${GITHUB_TOKEN}"

echo "Running comment creation script..."
node temp/create-comment.js

# Clean up temporary files
rm -rf temp

echo "✅ PR comment creation complete"
Loading
Loading