1
- name : ' script diff push'
2
- description : ' Run a script, show git diff and push changes if allowed'
1
+ name : ' Git diff after script call'
2
+ description : |
3
+ Check if content of given file changed after calling a script.
4
+ Action can be used to check if content of commited autogenerated file is valid.
5
+ Expected content of file can be found in check action's summary and artifacts sections.
3
6
inputs :
4
- github-token :
5
- description : ' The token to authenticate with'
6
- message_diff :
7
- description : ' Message if there is a diff'
8
- required : true
9
- message_success :
10
- description : ' Message if no more diff'
11
- required : true
12
7
script_call :
13
- description : ' Script call '
8
+ description : ' Script which should be called '
14
9
required : true
15
10
diff_file :
16
- description : ' File to run diff on, full path within the git repo'
17
- required : true
18
- diff_path :
19
- description : ' Diff file path within the repo'
20
- required : true
21
- git_diff_root :
22
- description : ' Root path of the git diff'
23
- required : true
24
- git_user_name :
25
- description : ' User name used for git push'
26
- required : true
27
- git_user_email :
28
- description : ' User email used for git push'
29
- required : true
30
- reaction_emote :
31
- description : ' Reaction to check by the PR author'
11
+ description : ' Path to file which should be inspected - relative to GitHub workspace'
32
12
required : true
33
13
runs :
34
14
using : " composite"
35
15
steps :
16
+ - name : ' Set env variables'
17
+ run : |
18
+ echo "DIFF_FILE_ABS='${{ github.workspace }}/${{ inputs.diff_file }}'" >> $GITHUB_ENV
19
+ echo "DIFF_FILE_DIR=$(dirname '${{ github.workspace }}/${{ inputs.diff_file }}')" >> $GITHUB_ENV
20
+ echo "DIFF_FILE_NAME=$(basename '${{ github.workspace }}/${{ inputs.diff_file }}')" >> $GITHUB_ENV
21
+ shell : bash
22
+
36
23
- name : Execute ${{ inputs.script_call }}
37
- working-directory : ${{ inputs.git_diff_root }}
38
24
run : ${{ inputs.script_call }}
39
25
shell : bash
40
26
41
27
- name : ' Upload Artifact: ${{ inputs.diff_file }}'
42
- uses : actions/upload-artifact@v3
28
+ uses : actions/upload-artifact@v4
43
29
with :
44
- name : ${{ inputs.diff_file }}
45
- path : ${{ inputs.git_diff_root }}/${{ inputs.diff_path }}/${{ inputs. diff_file }}
30
+ name : ${{ env.DIFF_FILE_NAME }}
31
+ path : ${{ inputs.diff_file }}
46
32
47
33
- name : Check for changes in ${{ inputs.diff_file }}
48
- working-directory : ${{ inputs.git_diff_root }}
34
+ working-directory : ${{ env.DIFF_FILE_DIR }}
49
35
id : diff
50
36
shell : bash
51
37
run : |
@@ -65,73 +51,30 @@ runs:
65
51
echo EOF
66
52
} >> $GITHUB_ENV
67
53
68
- - name : Post diff comment
69
- uses :
nrfconnect/[email protected]
70
- id : comment
71
- if : ${{ steps.diff.outputs.diff_result == 1 }}
72
- env :
73
- REACT_EMOTE : ${{ inputs.reaction_emote }}
74
- with :
75
- github-token : ${{ inputs.github-token }}
76
- reaction : " ${{ env.REACT_EMOTE }}"
77
- message : " ${{ inputs.message_diff }}"
78
-
79
- - name : Post success comment
80
- uses :
nrfconnect/[email protected]
81
- env :
82
- REACT_EMOTE : ${{ inputs.reaction_emote }}
83
- if : ${{ steps.diff.outputs.diff_result == 0 }}
84
- with :
85
- github-token : ${{ inputs.github-token }}
86
- reaction : " ${{ env.REACT_EMOTE }}"
87
- message : " ${{ inputs.message_success }}"
88
-
89
- - name : Add changed file
90
- working-directory : ${{ inputs.git_diff_root }}
91
- if : ${{ steps.comment.outputs.found_reaction == 'True' && steps.diff.outputs.diff_result == 1 }}
92
- shell : bash
93
- env :
94
- GH_TOKEN : ${{ inputs.github-token }}
95
- run : |
96
- gh pr checkout ${{ github.event.pull_request.number }}
97
- git config user.email "\"${{ inputs.git_user_email }}\""
98
- git config user.name "\"${{ inputs.git_user_name }}\""
99
- git add ${{ inputs.diff_path }}/${{ inputs.diff_file }}
100
-
101
- echo -e '`${{ inputs.diff_file }}` has changed. Pushing to PR branch.' >> $GITHUB_STEP_SUMMARY
102
- git config credential.helper store
103
- echo "https://x-access-token:${{ inputs.github-token }}@github.com" >> ~/.git-credentials
104
-
105
- git commit -s -m "ci: Updating ${{ inputs.diff_file }}" \
106
- -m 'This is an automated commit from github workflow by NordicBuilder'
107
- git push
108
- rm ~/.git-credentials
109
- unset GH_TOKEN
110
-
111
54
- name : Post summary
112
55
if : ${{ !cancelled() }}
113
56
shell : bash
114
57
run : |
115
58
if [[ 1 == ${{ steps.diff.outputs.diff_result }} ]]; then
116
59
echo -e 'New ${{ inputs.diff_file }} file differs from the current file.' >> $GITHUB_STEP_SUMMARY
117
60
fi
118
- if [[ -e ${{ inputs.git_diff_root }}/${{ inputs.diff_path }}/${{ inputs.diff_file }} ]]; then
61
+ if [[ -e ${{ env.DIFF_FILE_ABS }} ]]; then
119
62
echo -e '
120
63
<details>
121
64
<summary>${{ inputs.diff_file }}</summary>
122
65
123
66
```' >> $GITHUB_STEP_SUMMARY
124
- cat ${{ inputs.git_diff_root }}/${{ inputs.diff_path }}/${{ inputs.diff_file }} >> $GITHUB_STEP_SUMMARY
67
+ cat ${{ env.DIFF_FILE_ABS }} >> $GITHUB_STEP_SUMMARY
125
68
echo -e '```
126
69
127
70
</details>' >> $GITHUB_STEP_SUMMARY
128
71
else
129
- echo -e 'Error during workflow, ${{ inputs.diff_file }} file was not created' >> GITHUB_STEP_SUMMARY
72
+ echo -e 'Error during workflow, ${{ inputs.diff_file }} file was not created' >> $ GITHUB_STEP_SUMMARY
130
73
fi
131
74
if [[ -n $GITDIFF ]] && [[ 1 == ${{ steps.diff.outputs.diff_result}} ]]; then
132
75
echo -e '
133
76
<details>
134
- <summary>${{ inputs.diff_file }} diff</summary>
77
+ <summary>${{ env.DIFF_FILE_NAME }} diff</summary>
135
78
136
79
``` diff' >> $GITHUB_STEP_SUMMARY
137
80
echo "$GITDIFF" >> $GITHUB_STEP_SUMMARY
0 commit comments