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.
36inputs :
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
127 script_call :
13- description : ' Script call '
8+ description : ' Script which should be called '
149 required : true
1510 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'
3212 required : true
3313runs :
3414 using : " composite"
3515 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+
3623 - name : Execute ${{ inputs.script_call }}
37- working-directory : ${{ inputs.git_diff_root }}
3824 run : ${{ inputs.script_call }}
3925 shell : bash
4026
4127 - name : ' Upload Artifact: ${{ inputs.diff_file }}'
42- uses : actions/upload-artifact@v3
28+ uses : actions/upload-artifact@v4
4329 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 }}
4632
4733 - name : Check for changes in ${{ inputs.diff_file }}
48- working-directory : ${{ inputs.git_diff_root }}
34+ working-directory : ${{ env.DIFF_FILE_DIR }}
4935 id : diff
5036 shell : bash
5137 run : |
@@ -65,73 +51,30 @@ runs:
6551 echo EOF
6652 } >> $GITHUB_ENV
6753
68- - name : Post diff comment
69- uses : nrfconnect/action-comment@v0.1
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/action-comment@v0.1
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-
11154 - name : Post summary
11255 if : ${{ !cancelled() }}
11356 shell : bash
11457 run : |
11558 if [[ 1 == ${{ steps.diff.outputs.diff_result }} ]]; then
11659 echo -e 'New ${{ inputs.diff_file }} file differs from the current file.' >> $GITHUB_STEP_SUMMARY
11760 fi
118- if [[ -e ${{ inputs.git_diff_root }}/${{ inputs.diff_path }}/${{ inputs.diff_file }} ]]; then
61+ if [[ -e ${{ env.DIFF_FILE_ABS }} ]]; then
11962 echo -e '
12063 <details>
12164 <summary>${{ inputs.diff_file }}</summary>
12265
12366 ```' >> $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
12568 echo -e '```
12669
12770 </details>' >> $GITHUB_STEP_SUMMARY
12871 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
13073 fi
13174 if [[ -n $GITDIFF ]] && [[ 1 == ${{ steps.diff.outputs.diff_result}} ]]; then
13275 echo -e '
13376 <details>
134- <summary>${{ inputs.diff_file }} diff</summary>
77+ <summary>${{ env.DIFF_FILE_NAME }} diff</summary>
13578
13679 ``` diff' >> $GITHUB_STEP_SUMMARY
13780 echo "$GITDIFF" >> $GITHUB_STEP_SUMMARY
0 commit comments