1+ name : Environment File Check
2+
3+ on :
4+ pull_request :
5+ types : [opened, edited, synchronize]
6+
7+ jobs :
8+ check-environment-files :
9+ runs-on : ubuntu-latest
10+ steps :
11+ - uses : actions/checkout@v3
12+
13+ - name : Get changed files
14+ id : files
15+ run : |
16+ files=$(gh api \
17+ repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files \
18+ --jq '.[].filename')
19+ echo "Changed files:"
20+ printf ' -> %s\n' $files
21+ echo "changed_files<<EOF" >> $GITHUB_ENV
22+ echo "$files" >> $GITHUB_ENV
23+ echo "EOF" >> $GITHUB_ENV
24+ env :
25+ GH_TOKEN : ${{ github.token }}
26+
27+ - name : Determine missing environment/meta files
28+ id : check
29+ run : |
30+ # Required files
31+ required_files=("environment.yml" "environment_arm.yml" "environment_arm_linux.yml" "recipe/meta.yaml")
32+
33+ # Convert changed files to array
34+ readarray -t changed_array <<< "$changed_files"
35+
36+ # Check if any required file was changed
37+ any_changed=false
38+ for f in "${required_files[@]}"; do
39+ if printf '%s\n' "${changed_array[@]}" | grep -qx "$f"; then
40+ any_changed=true
41+ break
42+ fi
43+ done
44+
45+ if [ "$any_changed" = false ]; then
46+ echo "No environment/meta files changed."
47+ exit 0
48+ fi
49+
50+ # Determine missing files
51+ missing=()
52+ for f in "${required_files[@]}"; do
53+ if ! printf '%s\n' "${changed_array[@]}" | grep -qx "$f"; then
54+ missing+=("$f")
55+ fi
56+ done
57+
58+ # Set output if missing files exist
59+ if [ ${#missing[@]} -gt 0 ]; then
60+ formatted_missing=$(printf "%s\n" "${missing[@]}" | sed 's/^/> - /')
61+
62+ echo "missing_files<<EOF" >> $GITHUB_OUTPUT
63+ echo "$formatted_missing" >> $GITHUB_OUTPUT
64+ echo "EOF" >> $GITHUB_OUTPUT
65+ fi
66+ env :
67+ changed_files : ${{ env.changed_files }}
68+
69+ - name : Comment on PR if files are missing
70+ if : steps.check.outputs.missing_files
71+ uses : thollander/actions-comment-pull-request@v2
72+ with :
73+ message : |
74+ > [!CAUTION]
75+ > ## Environment/meta file update notice
76+ > You modified one of the environment/meta files but the following files were not updated:
77+ >
78+ ${{ steps.check.outputs.missing_files }}
79+ >
80+ > Please update them as well.
81+
82+ - name : Fail workflow if missing files
83+ if : steps.check.outputs.missing_files
84+ run : |
85+ echo "Missing required environment/meta files detected."
86+ exit 1
0 commit comments