Skip to content

Update structure-check.yml #6

Update structure-check.yml

Update structure-check.yml #6

name: Validate Project Structure
on:
push:
branches:
- '**'
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- name: Validate Structure
run: |
# Ensure there is atleast one previous commit
if [ $(git rev-parse --is-shallow-repository) = true ]; then
git fetch --unshallow
fi
# Get the list of changed files in the push
if git rev-parsem --verify HEAD~1 >/dev/null 2>&1; then
changed_files=$(git diff --name-only HEAD~1 HEAD)
else
changed_files=$(git ls-files)
fi
# Defined allowed Directories
username="${{ github.actor }}"
allowed_files="
^README.md
^.gitignore
^LICENSE
^${username}/app.py
^${username}/requirements.txt
^${username}/README.md
^${username}/static/
^${username}/static/css/
^${username}/static/js/
^${username}/templates/index.html
"
'^app.py|^requirements.txt|^README.md|^static/|^static/css/|^static/js/|^templates/index.html'
# Check if there are any dirty files outside the allowed structure
for file in $changed_files; do
if ! [[ $file =~ $allowed_files ]]; then
echo "Error: File $file is outside the allowed structure."
exit 1
fi
done
- name: Success Message
if: success()
run: echo "All changes are within allowed structure."