pytorch/.github/workflows/runner_determinator_script_sync.yaml
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

43 lines
1.5 KiB
YAML

name: runner-determinator
on:
workflow_dispatch:
pull_request:
branches: [main]
paths:
- .github/workflows/_runner-determinator.yaml
- .github/workflows/_runner_determinator_script_sync.yaml
- .github/workflows/scripts/runner_determinator.py
jobs:
python-script-sync-check:
if: github.repository_owner == 'pytorch'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: |
.github
- name: Extract the script from runner_determinator
run: |
# Runner determinator files
RUNNER_DETERMINATOR_WORKFLOW_FILE=.github/workflows/_runner-determinator.yml
RUNNER_DETERMINATOR_PYTHON_SCRIPT_FILE=.github/scripts/runner_determinator.py
# Parse the job file, extract the script and run it, up to the final EOF,
# to generate the python file in the local folder
yq '.jobs.runner-determinator.steps[] | select(.id == "hardcode-script") | .run' \
"${RUNNER_DETERMINATOR_WORKFLOW_FILE}" | sed '/^EOF$/q' | bash
set +e
DIFF="$(diff "$(basename ${RUNNER_DETERMINATOR_PYTHON_SCRIPT_FILE})" ${RUNNER_DETERMINATOR_PYTHON_SCRIPT_FILE})"
IS_DIFF=$?
set -e
if [ $IS_DIFF -eq 0 ]; then
echo "Scripts are in sync! ^_^";
else
echo -e "Scripts are *NOT* in sync:\n ${DIFF}";
exit 1
fi