@@ -21,43 +21,73 @@ jobs:
21
21
name : Prepare environment
22
22
runs-on : ubuntu-latest
23
23
outputs :
24
- changed-files : ${{ steps.changed-files.outputs.all_changed_files }}
25
- changed-files-count : ${{ steps.changed-files.outputs.all_changed_files_count }}
24
+ changed-files : ${{ steps.find- changed-files.outputs.changed_files }}
25
+ changed-files-count : ${{ steps.find- changed-files.outputs.changed_files_count }}
26
26
27
27
steps :
28
28
- name : Checkout current repository
29
29
uses : actions/checkout@v3
30
-
31
- - name : Get all "global.ini" files that have changed
32
- id : changed-files
33
- uses : tj-actions/changed-files@v39
34
30
with :
35
- files : " data/Localization/*/global.ini"
36
- separator : " \" \" "
31
+ fetch-depth : 0 # Fetch all history for comparing changes
32
+
33
+ - name : Find changed global.ini files
34
+ id : find-changed-files
35
+ run : |
36
+ echo "${{ github.event_name }} event triggered this workflow"
37
+
38
+ # Determine the base and head references based on the event type
39
+ if [ "${{ github.event_name }}" == "pull_request" ]; then
40
+ BASE_REF="${{ github.event.pull_request.base.sha }}"
41
+ HEAD_REF="${{ github.event.pull_request.head.sha }}"
42
+ elif [ "${{ github.event_name }}" == "push" ]; then
43
+ BASE_REF="HEAD^"
44
+ HEAD_REF="HEAD"
45
+ else
46
+ # For workflow_dispatch or any other event, compare with the main branch
47
+ git fetch origin main
48
+ BASE_REF="origin/main"
49
+ HEAD_REF="HEAD"
50
+ fi
51
+
52
+ echo "Comparing $BASE_REF...$HEAD_REF"
53
+
54
+ # Get changed files with a single git diff command
55
+ # Using quotes around the grep pattern to prevent shell expansion of the asterisk
56
+ CHANGED_FILES=$(git diff --name-only $BASE_REF $HEAD_REF | grep -E "data/Localization/.*/global\.ini" || echo "")
57
+
58
+ # Format the files for output with correct separator
59
+ if [ ! -z "$CHANGED_FILES" ]; then
60
+ # Properly format the changed files for the output with quotes and spaces
61
+ FORMATTED_FILES=$(echo "$CHANGED_FILES" | sed 's/.*/"&"/' | tr '\n' ' ')
62
+ echo "Changed files: $FORMATTED_FILES"
63
+ echo "changed_files=$FORMATTED_FILES" >> $GITHUB_OUTPUT
64
+ echo "changed_files_count=$(echo "$CHANGED_FILES" | wc -l)" >> $GITHUB_OUTPUT
65
+ else
66
+ echo "No global.ini files changed"
67
+ echo "changed_files=''" >> $GITHUB_OUTPUT
68
+ echo "changed_files_count=0" >> $GITHUB_OUTPUT
69
+ fi
37
70
38
71
- name : List all changed files
39
- run : echo "Changed files ${{ steps.changed-files.outputs.all_changed_files }}"
72
+ run : echo "Changed files ${{ steps.find- changed-files.outputs.changed-files }}"
40
73
41
74
validate-encoding :
42
75
name : Validate global.ini Encoding
43
76
runs-on : ubuntu-latest
44
77
needs : prepare
45
-
78
+ if : needs.prepare.outputs.changed-files-count > 0
46
79
steps :
47
80
- name : Checkout current repository
48
- if : needs.prepare.outputs.changed-files-count > 0
49
81
uses : actions/checkout@v3
50
82
51
83
- name : Validate encoding
52
- if : needs.prepare.outputs.changed-files-count > 0
53
- run : bash tools/validate-encoding.bash "${{ needs.prepare.outputs.changed-files }}"
84
+ run : bash tools/validate-encoding.bash ${{ needs.prepare.outputs.changed-files }}
54
85
55
86
validate-entries :
56
87
name : Validate global.ini Entries
57
88
runs-on : ubuntu-latest
58
89
needs : prepare
59
90
if : needs.prepare.outputs.changed-files-count > 0
60
-
61
91
steps :
62
92
- name : Checkout current repository
63
93
uses : actions/checkout@v3
77
107
run : npm run build
78
108
79
109
- name : Validate key/value pairs
80
- run : node ./tools/ini-utils/dist/src/index.js validate --ci "$GITHUB_WORKSPACE/data/Localization/english/global.ini" " ${{ needs.prepare.outputs.changed-files }}"
110
+ run : node ./tools/ini-utils/dist/src/index.js validate --ci "$GITHUB_WORKSPACE/data/Localization/english/global.ini" ${{ needs.prepare.outputs.changed-files }}
0 commit comments