generated from decentralized-identity/template-for-work-items
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Structure and changes detector (#13)
* Structure and changes detector * Better message * Final state
- Loading branch information
1 parent
848c35c
commit 1b3c215
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
}) |