Skip to content

Commit 83c424c

Browse files
committed
Remove not needed and not secure features
All features, which require secrets, are considered as unsafe. Depending on how script-diff action is used, secrets can be compromised with prepared script to call.
1 parent dda47cc commit 83c424c

File tree

2 files changed

+26
-119
lines changed

2 files changed

+26
-119
lines changed

README.md

+4-40
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,16 @@
22

33
* Execute given script
44
* Generates a diff over a given file
5-
* Posts a comment to the PR with custom message if there is a diff
6-
* Posts a different comment if there is no diff
7-
* If there is diff and the PR author reacted with a defineable emote, an auto commit is added
5+
* Verify if content of generated and commited files equals
86

97
## Usage
108
``` yaml
119

12-
- uses: nrfconnect/action-script-diff@v0.2
10+
- uses: nrfconnect/action-script-diff@v0.3
1311
with:
14-
# Token needed to post comments and add commits
15-
github-token: ''
16-
17-
# Comment message to post when a diff was detected
18-
message_diff: ''
19-
20-
# Comment message to post when no diff was detected
21-
message_success: ''
12+
# Path to file which should be inspected - relative to GitHub workspace
13+
diff_file: ''
2214

2315
# Relative path and script name to be executed
2416
script_call: ''
25-
26-
# File to check for diff
27-
diff_file: ''
28-
29-
# Path within the repo where the file to watch is present
30-
diff_path: ''
31-
32-
# The root folder for the git diff
33-
git_diff_root: ''
34-
35-
# User name to be used in the auto commit (Needs to be 'Firstname' 'Lastname')
36-
git_user_name: '<Firstname> <Lastname>'
37-
38-
# E-Mail to be used in the auto commit (Needs to be the verified e-mail of the account to be used)
39-
git_user_email: ''
40-
41-
# Github comment remote to check if present
42-
# See https://docs.github.com/en/rest/reactions/reactions
43-
# Available emotes:
44-
# 👍 -1
45-
# 👎 -1
46-
# 😄 laugh
47-
# 😕 confused
48-
# ❤️ heart
49-
# 🎉 hooray
50-
# 🚀 rocket
51-
# 👀 eyes
52-
reaction_emote: ''
5317
```

action.yml

+22-79
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,37 @@
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.
36
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
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
3313
runs:
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/[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-
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

Comments
 (0)