File tree Expand file tree Collapse file tree 2 files changed +84
-0
lines changed Expand file tree Collapse file tree 2 files changed +84
-0
lines changed Original file line number Diff line number Diff line change 1+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2+ # All rights reserved.
3+ #
4+ # This source code is licensed under the BSD-style license found in the
5+ # LICENSE file in the root directory of this source tree.
6+
7+
8+ """
9+ Helper to determine whether a CI should run on a list of modified files.
10+ Takes a list of modified files and a list of matchers.
11+ If any modified file matches to the matcher, print '1' to indicate CI should
12+ run.
13+ """
14+
15+
16+ import re
17+
18+
19+ def filename_matches (filename : str , matchers : list [str ]):
20+ combined = "(" + ")|(" .join (matchers ) + ")"
21+ return re .match (combined , filename )
22+
23+
24+ def any_match (modified_files : list [str ], matchers : list [str ]):
25+ return any (filename_matches (f , matchers ) for f in modified_files )
26+
27+
28+ def main (modified_file_list_path : str , matchers_path : str ):
29+ with open (modified_file_list_path , "r" ) as f :
30+ modified_files = f .read ().splitlines ()
31+ with open (matchers_path , "r" ) as f :
32+ matchers = f .read ().splitlines ()
33+ if any_match (modified_files , matchers ):
34+ print ("1" )
35+ else :
36+ print ("0" )
37+
38+
39+ if __name__ == "__main__" :
40+ main ()
Original file line number Diff line number Diff line change 55 workflow_dispatch :
66
77jobs :
8+ check_path :
9+ name : Check whether the affected path needs to be validated by this CI
10+ runs-on : ubuntu-22.04
11+ outputs :
12+ should_run : ${{ steps.check-path.outputs.should_run }}
13+ steps :
14+ - uses : actions/checkout@v3
15+ with :
16+ fetch-depth : ' 0'
17+ - uses : actions/setup-python@v4
18+ with :
19+ python-version : ' 3.10'
20+ - name : Check path
21+ id : check-path
22+ env :
23+ GITHUB_PR_NUMBER : ${{ github.event.pull_request.number }}
24+ GITHUB_PR_BASE : ${{ github.base_ref }}
25+ GITHUB_PR_HEAD : ${{ github.head_ref }}
26+ run : |
27+ if [ -z "$GITHUB_PR_NUMBER" ]; then
28+ # It's not for a PR, but pushed to a branch in pull.yml, or dispatch. Always run.
29+ echo "::set-output should_run=1"
30+ return 0
31+ fi
32+ if [ -z "$GITHUB_PR_BASE" ] || [ -z "$GITHUB_PR_HEAD" ] ; then
33+ # Seems like not a well-formed PR
34+ echo "::set-output should_run=1"
35+ return 0
36+ fi
37+ git diff --name-only "$GITHUB_PR_BASE" "$GITHUB_PR_HEAD" > modified_files
38+ cat >> matcher<< EOF
39+ .ci/docker/
40+ .github/workflows/android.yml
41+ build/.*android.*.sh
42+ install_requirements.sh
43+ examples/demo-apps/android
44+ extension/android
45+ extension/benchmark/android
46+ extension/module
47+ EOF
48+ echo "::set-output should_run=$(python .github/scripts/check_path_match.py modified_files matcher)"
49+
850 build-llm-demo :
951 name : build-llm-demo
1052 uses : pytorch/test-infra/.github/workflows/linux_job.yml@main
53+ needs : check_path
54+ if : ${{ needs.check_path.outputs.should_run }} == '1'
1155 with :
1256 runner : linux.2xlarge
1357 docker-image : executorch-ubuntu-22.04-clang12-android
You can’t perform that action at this time.
0 commit comments