Skip to content

Commit

Permalink
Structure and changes detector (#13)
Browse files Browse the repository at this point in the history
* Structure and changes detector

* Better message

* Final state
  • Loading branch information
vmc-crossmint authored Oct 9, 2024
1 parent 848c35c commit 1b3c215
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/check-schemas-structure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Check Schemas Structure

on:
pull_request:

jobs:
check-structure:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Check for required files
run: |
missing_files=0
for entity in schemas/*; do
if [ -d "$entity" ]; then
if [ ! -f "$entity/README.md" ]; then
echo "Missing README.md in $entity"
missing_files=1
fi
if [ ! -f "$entity/CODEOWNERS" ]; then
echo "Missing CODEOWNERS in $entity"
missing_files=1
fi
fi
done
exit $missing_files
- name: Check no changes to schemas
run: |
invalid_changes=0
changes=""
echo "Checking for changes in schema files..."
# Fetch the base branch to compare
git fetch origin ${{ github.event.pull_request.base.ref }}
# Get the list of changed files in the PR within 'schemas/**/*'
changed_files=$(git diff --name-only --diff-filter=M origin/${{ github.event.pull_request.base.ref }}...HEAD -- 'schemas/**/*')
echo "Changed files: $changed_files"
for file in $changed_files; do
if [ -f "$file" ] && [ "$(basename "$file")" != "README.md" ] && [ "$(basename "$file")" != "CODEOWNERS" ]; then
echo "Change detected in $file..."
changes="$changes\nUnexpected change in $file"
invalid_changes=1
fi
done
echo "changes<<EOF" >> $GITHUB_ENV
echo -e "$changes" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Comment on PR if there are unexpected changes
if: env.changes != ''
uses: actions/github-script@v6
with:
script: |
github.rest.pulls.createReview({
pull_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Unexpected changes detected, you should not update a schema file, consider creating a new version instead:\n${{ env.changes }}`,
event: 'REQUEST_CHANGES'
})

0 comments on commit 1b3c215

Please sign in to comment.