2
2
3
3
# Required environment variables:
4
4
# $INPUT_FILES: Pattern(s) to filter files by (e.g., "content/** data/**")
5
- # $FILTER: Derived from INPUT_FILES, defaults to "." if not provided
6
- # $PR: Pull request number (if running in PR context)
7
- # $HEAD: Current branch or SHA for git diff
5
+ # $INPUT_PR: Pull request number (if running in PR context)
6
+ # $INPUT_HEAD: Current branch or SHA for git diff
7
+ # $INPUT_OUTPUT_FILE: Optional file to redirect output to.
8
+ # $GH_TOKEN: the access token
8
9
9
10
# Default value for files parameter if not provided
10
11
FILTER=${INPUT_FILES:- .}
@@ -16,21 +17,21 @@ echo "$FILTER"
16
17
# Find the file diff in the pull request or merge group
17
18
# If its a pull request, use the faster call to the GitHub API
18
19
# For push, workflow_dispatch, and merge_group, use git diff
19
- if [ -n " $PR " ]
20
+ if [ -n " $INPUT_PR " ]
20
21
then
21
22
echo " __ running gh pr diff __"
22
- DIFF=` gh pr diff $PR --name-only`
23
+ DIFF=$( gh pr diff $INPUT_PR --name-only)
23
24
if [ -z " $DIFF " ]; then
24
25
echo " __ gh pr diff failed, falling back to git diff __"
25
- HEAD=$( gh pr view $PR --json headRefName --jq .headRefName)
26
+ HEAD=$( gh pr view $INPUT_PR --json headRefName --jq .headRefName)
26
27
fi
27
28
fi
28
29
29
30
if [ -z " $DIFF " ]; then
30
- echo " __ using branch name $HEAD __"
31
+ echo " __ using branch name $INPUT_HEAD __"
31
32
git fetch origin main --depth 1
32
33
echo " __ running git diff __"
33
- DIFF=` git diff --name-only origin/main $HEAD `
34
+ DIFF=$( git diff --name-only origin/main $INPUT_HEAD )
34
35
fi
35
36
36
37
# So we can inspect the output
@@ -64,9 +65,16 @@ echo "$FORMATTED_DIFF"
64
65
65
66
# Set the output for GitHub Actions
66
67
if [[ -n " $GITHUB_OUTPUT " ]]; then
67
- echo " all_changed_files=$DIFF " >> " $GITHUB_OUTPUT "
68
+ ALL_FORMATTED=$( echo " $DIFF " | tr ' \n' ' ' | tr -s ' ' )
69
+ echo " all_changed_files=$ALL_FORMATTED " >> " $GITHUB_OUTPUT "
68
70
echo " filtered_changed_files=$FORMATTED_DIFF " >> " $GITHUB_OUTPUT "
69
71
else
70
72
echo " all_changed_files=$DIFF "
71
73
echo " filtered_changed_files=$FORMATTED_DIFF "
72
74
fi
75
+
76
+ # If output file is specified, write the filtered changes to it
77
+ if [[ -n " $INPUT_OUTPUT_FILE " ]]; then
78
+ echo " $FORMATTED_DIFF " > " $INPUT_OUTPUT_FILE "
79
+ echo " __ wrote changes to $INPUT_OUTPUT_FILE __"
80
+ fi
0 commit comments