diff --git a/.github/workflows/UpdateReadmeOnPush.yml b/.github/workflows/UpdateReadmeOnPush.yml index 5341163..46159f2 100644 --- a/.github/workflows/UpdateReadmeOnPush.yml +++ b/.github/workflows/UpdateReadmeOnPush.yml @@ -21,27 +21,31 @@ jobs: with: python-version: '3.12' - - name: Check if files match naming pattern - id: check-files + - name: Check for Allowed File Changes + uses: tj-actions/verify-changed-files@v19 + id: verify-changes + with: + # Only check for changes in Python and C++ files + files: | + **/*.py + **/*.cpp + # Fail if no allowed files changed + fail_on_empty_changes: true + + - name: Check File Names run: | - if git rev-parse --verify HEAD~1 >/dev/null 2>&1; then - files=$(git diff --name-only HEAD~1 HEAD -- ./ | grep -E '^\d+[A-Z]\.(cpp|py)$' | grep -v '^\.github/') - if [[ ! -z "$files" ]]; then - echo "::set-env name=CHANGED::true" - echo "::set-env name=UPDATED_FILES::$files" - else - echo "::set-env name=CHANGED::false" + changed_files=${{ steps.verify-changes.outputs.changed_files }} + for file in $changed_files; do + if [[ ! ($file =~ ^\d[A-Z]\.(cpp|py)$ ]]; then + echo "Error: File '$file' does not match allowed pattern" + exit 1 fi - else - echo "::warning:: No previous commit found. Skipping checks." - fi + done - name: Run Python script to update README - if: env.CHANGED == 'true' - run: python update_readme.py ${{ env.UPDATED_FILES }} + run: python update_readme.py ${{ steps.verify-changes.outputs.changed_files }} - name: Commit changes - if: env.CHANGED == 'true' run: | git config --local user.email "actions@github.com" git config --local user.name "GitHub Actions" @@ -49,7 +53,6 @@ jobs: git commit -m "Update README" - name: Push changes - if: env.CHANGED == 'true' uses: ad-m/github-push-action@master with: github_token: ${{ secrets.CODEFORCES_GITHUB_TOKEN }}