pytorch/.github/workflows/runner-determinator-validator.yml
Catherine Lee 66a3c249ae Linter for no workflows on fork (#138849)
MInor, adds a linter that ensures that all jobs run on pull_request, schedule, push etc have a `if: github.repository_owner == 'pytorch'` or are dependent on a job that has that check

There is also a setting in Github repos that can disable all workflows for that repo

A lot of these are unnecessary because many jobs use reusable workflows that have that check.  However, this is a one time change so I'm not that bothered

Unfortunately I can't put this at the workflow level, which would make this better

Lots of weird string parsing

Pull Request resolved: https://github.com/pytorch/pytorch/pull/138849
Approved by: https://github.com/malfet
2024-10-28 17:46:50 +00:00

41 lines
No EOL
1.8 KiB
YAML

name: Validate Runner Determinator Script is in Sync
on:
# Run on PRs when the runner-determinator script is updated to ensure it's copies are kept in sync
pull_request:
paths:
- .github/workflows/_runner-determinator.yml
- .github/workflows/runner-determinator-validator.yml
- .github/scripts/runner_determinator.py
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }}
cancel-in-progress: true
jobs:
check-runner-determinator:
if: github.repository_owner == 'pytorch'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Run Hardcode runner-determinator script
id: hardcode-script
run: |
# Extract the script content from _runner-determinator.yml and skip the first 10 spaces of each line
script_content=$(awk '/cat <<EOF > runner_determinator.py/{flag=1;next}/EOF$/{flag=0}flag{print substr($0, 11)}' .github/workflows/_runner-determinator.yml)
# Write the extracted script content to runner_determinator.py
echo "$script_content" > runner_determinator_workflow.py
- name: Compare runner-determinator script embedded in workflow with checked in script
run: |
# Compare the extracted runner_determinator script with the existing one
# If this check fails, then make sure the contents of .github/scripts/runner_determinator.py is in sync with the
# version embedded into .github/workflows/_runner-determinator.yml
diff runner_determinator_workflow.py .github/scripts/runner_determinator.py
# Fail the job if the scripts are not identical
continue-on-error: false