Skip to content
Open
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
132 changes: 132 additions & 0 deletions .github/workflows/check-readme-changes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: Check README Changes

on:
pull_request:
types: [opened, synchronize, reopened]

jobs:
check-readme-changes:
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: read

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check if README files were modified without tags.yaml
id: check
run: |
# Get the base and head commits
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"

# Get list of changed files
changed_files=$(git diff --name-only --diff-filter=ACMR "$BASE_SHA" "$HEAD_SHA" || echo "")

readme_changed=false
tags_yaml_changed=false
readme_files=""

# Check each changed file
if [ -n "$changed_files" ]; then
while IFS= read -r file || [ -n "$file" ]; do
# Check if it's a TAG README file (tags/*/README.md)
if echo "$file" | grep -qE "^tags/[^/]+/README\.md$"; then
readme_changed=true
if [ -z "$readme_files" ]; then
readme_files="$file"
else
readme_files="$readme_files"$'\n'"$file"
fi
fi
# Check if it's a TOC subproject README file (toc_subprojects/*/README.md)
if echo "$file" | grep -qE "^toc_subprojects/[^/]+/README\.md$"; then
readme_changed=true
if [ -z "$readme_files" ]; then
readme_files="$file"
else
readme_files="$readme_files"$'\n'"$file"
fi
fi
# Check if tags.yaml was changed
if [ "$file" = "tags.yaml" ]; then
tags_yaml_changed=true
fi
done <<< "$changed_files"
fi

echo "readme_changed=$readme_changed" >> $GITHUB_OUTPUT
echo "tags_yaml_changed=$tags_yaml_changed" >> $GITHUB_OUTPUT

if [ "$readme_changed" = "true" ] && [ "$tags_yaml_changed" = "false" ]; then
echo "should_comment=true" >> $GITHUB_OUTPUT
# Format README files as markdown list
if [ -n "$readme_files" ]; then
formatted_list=$(echo "$readme_files" | while IFS= read -r file || [ -n "$file" ]; do
echo "- \`$file\`"
done)
{
echo "files_list<<EOF"
echo "$formatted_list"
echo "EOF"
} >> $GITHUB_OUTPUT
else
echo "files_list=" >> $GITHUB_OUTPUT
fi
else
echo "should_comment=false" >> $GITHUB_OUTPUT
echo "files_list=" >> $GITHUB_OUTPUT
fi

- name: Comment on PR
if: steps.check.outputs.should_comment == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const comment = `## ⚠️ README Files Should Be Updated via tags.yaml

The following TAG or TOC subproject README files have been directly edited:

${{ steps.check.outputs.files_list }}

These README files are auto-generated from the \`tags.yaml\` file using the generator script. **Please update the \`tags.yaml\` file instead** of editing the README files directly.

For more information on how to update these files, please see the [generator README](https://github.com/${{ github.repository }}/blob/main/generator/README.md).

Once you update \`tags.yaml\`, the README files will be automatically regenerated by the existing automation workflow.`;

// Check if we've already commented on this PR
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});

const botComment = comments.data.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('README Files Should Be Updated via tags.yaml')
);

if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.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
});
}