Skip to content

Commit c9eb542

Browse files
authored
fix gh action not picking up the modified files (#497)
1 parent 2c84267 commit c9eb542

File tree

2 files changed

+38
-48
lines changed

2 files changed

+38
-48
lines changed

.github/scripts/list_modified_scripts_with_secrets.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,24 @@ def process_files(files):
3131
]
3232

3333

34+
def get_modified_metas(files):
35+
filenames = files.split(",")
36+
return [
37+
{
38+
"file": file,
39+
"uid": uid,
40+
}
41+
for file in filenames if os.path.basename(file) == 'meta.yaml'
42+
for uid, num_tests in [get_file_info(file)]
43+
]
44+
45+
3446
if __name__ == "__main__":
3547
changed_files = sys.stdin.read().strip()
3648
processed_files = process_files(changed_files)
49+
modified_metas = get_modified_metas(changed_files)
3750
json_processed_files = json.dumps(processed_files)
3851
print(json_processed_files)
52+
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
53+
f.write(
54+
f"processed_files={json.dumps({'file_info': processed_files, 'modified_metas': modified_metas})}\n")

.github/workflows/run_tests_on_modified_meta_with_secrets.yml

Lines changed: 22 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -24,68 +24,42 @@ jobs:
2424
get_modified_files:
2525
runs-on: ubuntu-latest
2626
outputs:
27-
processed_files: ${{ steps.filter-modified-files.outputs.processed_files }}
28-
steps:
29-
- name: Checkout
30-
uses: actions/checkout@v4
31-
with:
32-
fetch-depth: 0
33-
34-
- name: Setup Python
35-
uses: actions/setup-python@v4
36-
with:
37-
python-version: '3.x'
38-
39-
- name: Install dependencies
40-
run: pip install pyyaml
27+
processed_files: ${{ steps.modified-files.outputs.processed_files }}
4128

42-
- name: Fetch base branch
43-
run: |
44-
git fetch origin +refs/heads/${{ github.event.pull_request.base.ref }}:refs/remotes/origin/${{ github.event.pull_request.base.ref }}
29+
steps:
30+
- name: 'Checkout'
31+
uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 2
4534

46-
- name: Get list of changed files
47-
id: modified-files
48-
run: |
49-
git diff --name-only origin/${{ github.event.pull_request.base.ref }}...HEAD > changed_files.txt
50-
echo "changed files:"
51-
echo " "
52-
cat changed_files.txt
53-
files=$(paste -sd, changed_files.txt)
54-
echo "files=$files" >> $GITHUB_OUTPUT
35+
- name: Setup Python
36+
uses: actions/setup-python@v2
37+
with:
38+
python-version: '3.x'
5539

56-
- name: Filter changed files
57-
id: filter-modified-files
58-
env:
59-
FILES: ${{ steps.modified-files.outputs.files }}
60-
run: |
61-
echo "Files to be processed $FILES"
62-
processed=$(echo "$FILES" | python3 .github/scripts/list_modified_scripts_with_secrets.py)
63-
echo "$processed"
64-
echo "processed_files<<EOF" >> $GITHUB_OUTPUT
65-
echo "$processed" >> $GITHUB_OUTPUT
66-
echo "EOF" >> $GITHUB_OUTPUT
40+
- name: Install dependencies
41+
run: |
42+
pip install pyyaml
6743
68-
- name: Debug processed_files output
69-
run: |
70-
echo "Processed files output:"
71-
echo "${{ steps.filter-modified-files.outputs.processed_files }}"
44+
- name: Get changed files
45+
id: modified-files
46+
run: |
47+
git remote add upstream ${{ github.event.pull_request.base.repo.clone_url }}
48+
git fetch upstream
49+
changed_files=$(git diff upstream/${{ github.event.pull_request.base.ref }} --name-only | paste -sd, -)
50+
echo "$changed_files" | python3 .github/scripts/list_modified_files.py
7251
7352
process_modified_files:
7453
needs:
7554
- get_modified_files
7655
- fetch-secret
7756
runs-on: ubuntu-latest
78-
if: needs.get_modified_files.outputs.processed_files != '[]'
57+
if: needs.get_modified_files.outputs.processed_files != '[]' && needs.get_modified_files.outputs.processed_files != ''
7958
strategy:
8059
fail-fast: false
8160
matrix:
82-
file_info: ${{ fromJSON(needs.get_modified_files.outputs.processed_files) }}
61+
file_info: ${{ fromJSON(needs.get_modified_files.outputs.processed_files).file_info }}
8362
steps:
84-
- name: Checkout repository
85-
uses: actions/checkout@v4
86-
with:
87-
fetch-depth: 2
88-
8963
- name: Set RCLONE Service account env var from secret
9064
shell: bash
9165
run: |

0 commit comments

Comments
 (0)