Skip to content

chore: Sync upstream 20260122 #831

chore: Sync upstream 20260122

chore: Sync upstream 20260122 #831

name: Check Block README Updates
on:
pull_request:
paths:
- 'blocks/**'
types: [opened, synchronize, reopened]
jobs:
check-block-readme:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full history for proper diff
- name: Check for block changes
id: check-blocks
run: |
# Get changed files in the PR
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }})
# Filter for block changes (excluding README.md files)
BLOCK_CHANGES=$(echo "$CHANGED_FILES" | grep -E '^blocks/[^/]+/.*\.(js|css|html)$' || true)
if [ -n "$BLOCK_CHANGES" ]; then
echo "has_block_changes=true" >> $GITHUB_OUTPUT
# Extract unique block names
BLOCK_NAMES=$(echo "$BLOCK_CHANGES" | sed 's|blocks/\([^/]*\)/.*|\1|' | sort -u | tr '\n' ',' | sed 's/,$//')
echo "changed_blocks=$BLOCK_NAMES" >> $GITHUB_OUTPUT
# Check which blocks have READMEs
MISSING_READMES=""
for block in $(echo "$BLOCK_NAMES" | tr ',' ' '); do
if [ ! -f "blocks/$block/README.md" ]; then
if [ -z "$MISSING_READMES" ]; then
MISSING_READMES="$block"
else
MISSING_READMES="$MISSING_READMES,$block"
fi
fi
done
if [ -n "$MISSING_READMES" ]; then
echo "missing_readmes=$MISSING_READMES" >> $GITHUB_OUTPUT
fi
else
echo "has_block_changes=false" >> $GITHUB_OUTPUT
fi
- name: Comment on PR
if: steps.check-blocks.outputs.has_block_changes == 'true'
uses: actions/github-script@v7
with:
script: |
const changedBlocks = '${{ steps.check-blocks.outputs.changed_blocks }}'.split(',');
const missingReadmes = '${{ steps.check-blocks.outputs.missing_readmes }}'.split(',').filter(Boolean);
const hasMissingReadmes = missingReadmes.length > 0;
const emoji = hasMissingReadmes ? '⚠️' : '📝';
const statusColor = hasMissingReadmes ? 'FF6B6B' : 'FFA500';
let comment = `## ${emoji} Block Changes Detected\n\n`;
comment += `This PR contains changes to the following blocks:\n\n`;
changedBlocks.forEach(block => {
const hasReadme = !missingReadmes.includes(block);
const status = hasReadme ? '✅' : '❌';
comment += `- ${status} \`blocks/${block}/\` ${hasReadme ? '(has README.md)' : '(missing README.md)'}\n`;
});
comment += `\n### 📋 README Requirements\n\n`;
comment += `Please ensure the README.md for each changed block includes:\n\n`;
comment += `- **Overview**: Clear description of the block's purpose and functionality\n`;
comment += `- **Configuration**: All configuration options, their types, defaults, and side effects\n`;
comment += `- **Integration**: URL parameters, localStorage usage, and event handling\n`;
comment += `- **Behavior Patterns**: User interaction flows and page context detection\n`;
comment += `- **Error Handling**: How the block handles errors and fallback scenarios\n\n`;
if (hasMissingReadmes) {
comment += `### ⚠️ Action Required\n\n`;
comment += `The following blocks are missing README.md files:\n\n`;
missingReadmes.forEach(block => {
comment += `- \`blocks/${block}/README.md\`\n`;
});
comment += `\nPlease create these README files before merging this PR.\n\n`;
} else {
comment += `### ✅ All blocks have README files\n\n`;
comment += `Please review and update the README files to ensure they accurately reflect any changes made to the blocks.\n\n`;
}
comment += `---\n`;
comment += `*This comment was automatically generated by the Block README Check workflow.*`;
// Check if we already commented on this PR
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existingComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Block Changes Detected')
);
if (existingComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: comment
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: comment
});
}
- name: Remove comment if no block changes
if: steps.check-blocks.outputs.has_block_changes == 'false'
uses: actions/github-script@v7
with:
script: |
// Check if we previously commented on this PR
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existingComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Block Changes Detected')
);
if (existingComment) {
// Remove the comment since there are no block changes
await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
});
}