Skip to content

🔄 synced file(s) with PaddleHQ/go-library-template #63

🔄 synced file(s) with PaddleHQ/go-library-template

🔄 synced file(s) with PaddleHQ/go-library-template #63

# DO NOT EDIT: This file should only be modified in the `go-library-template` repo.
name: Check modified autogenerated files
on:
pull_request:
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true
jobs:
check-do-not-edit:
runs-on: ubuntu-latest
name: Check for DO NOT EDIT files
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@95d9a5deda9de15063e7595e9719c11c38c90ae2 # v2.13.2
with:
egress-policy: audit
- name: Skip if the PR was created by paddle-repo-file-sync[bot]
if: github.actor == 'paddle-repo-file-sync[bot]'
run: |
echo "Skipping check-do-not-edit for bot PR"
exit 0
- name: Checkout code
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
fetch-depth: 0
- name: Check for DO NOT EDIT warnings
shell: bash
run: |
echo "Checking changed files for DO NOT EDIT warnings..."
# Create a flag to track if any warnings were found
warnings_found=false
# Get changed files using git diff
echo "Getting changed files from git diff..."
mergeBase=`git merge-base origin/${{ github.event.pull_request.base.ref }} HEAD`
echo "Merge base: $mergeBase"
changed_files=$(git diff --name-only --merge-base $mergeBase)
if [[ -z "$changed_files" ]]; then
echo "No changed files found."
exit 0
fi
echo "Changed files:"
echo "$changed_files"
# Read changed files into an array
IFS=$'\n' read -d '' -r -a changed_files_array <<< "$changed_files" || true
for file in "${changed_files_array[@]}"; do
if [[ -f "$file" ]]; then
echo "Checking file: $file"
# Check first line for DO NOT EDIT (case insensitive)
if head -n 1 "$file" | grep -i "do not edit" > /dev/null 2>&1; then
echo "::warning file=$file,line=1::This file contains 'DO NOT EDIT' warning. Please do not edit this file manually as it may be auto-generated."
warnings_found=true
echo "Found DO NOT EDIT warning in: $file"
fi
fi
done
if [[ "$warnings_found" == "true" ]]; then
echo "::notice::Some files contain DO NOT EDIT warnings. Please review the annotations above."
else
echo "No DO NOT EDIT warnings found in changed files."
fi