diff --git a/.github/workflows/validate_submission.yml b/.github/workflows/validate_submission.yml index fd49f63..3f0047a 100644 --- a/.github/workflows/validate_submission.yml +++ b/.github/workflows/validate_submission.yml @@ -41,6 +41,45 @@ jobs: echo "$file was changed" done + + # Look for file outside allowed folders + # --------------------------------------- + - name: Check if file are outside the allowed folders + run: | + # List of allowed folders + ALLOWED_FOLDERS=("model-output/" "model-metadata/") + + # Init var for not allowed files + FILES_OUTSIDE_FOLDERS="" + + # Iterate over changes + for FILE in $(echo ${{ steps.changed-files.outputs.all_changed_files }} | jq -r '.[]'); do + MATCH_FOUND=false + + # Check if file is under an allowed folder + for FOLDER in "${ALLOWED_FOLDERS[@]}"; do + if [[ "$FILE" == "$FOLDER"* ]]; then + MATCH_FOUND=true + break + fi + done + + # If not mathced, add to forbidden list + if [ "$MATCH_FOUND" = false ]; then + FILES_OUTSIDE_FOLDERS="${FILES_OUTSIDE_FOLDERS} $FILE" + fi + done + + # If one or more file outside allowed folders are present, submission fails + if [ ! -z "$FILES_OUTSIDE_FOLDERS" ]; then + echo "Error: PR contains files outside the allowed folders." + echo "Files outside allowed folders: $FILES_OUTSIDE_FOLDERS" + exit 1 + fi + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - uses: r-lib/actions/setup-r@v2 with: install-r: false