-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
dda47cc
commit 83c424c
Showing
2 changed files
with
26 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,37 @@ | ||
name: 'script diff push' | ||
description: 'Run a script, show git diff and push changes if allowed' | ||
name: 'Git diff after script call' | ||
description: | | ||
Check if content of given file changed after calling a script. | ||
Action can be used to check if content of commited autogenerated file is valid. | ||
Expected content of file can be found in check action's summary and artifacts sections. | ||
inputs: | ||
github-token: | ||
description: 'The token to authenticate with' | ||
message_diff: | ||
description: 'Message if there is a diff' | ||
required: true | ||
message_success: | ||
description: 'Message if no more diff' | ||
required: true | ||
script_call: | ||
description: 'Script call' | ||
description: 'Script which should be called' | ||
required: true | ||
diff_file: | ||
description: 'File to run diff on, full path within the git repo' | ||
required: true | ||
diff_path: | ||
description: 'Diff file path within the repo' | ||
required: true | ||
git_diff_root: | ||
description: 'Root path of the git diff' | ||
required: true | ||
git_user_name: | ||
description: 'User name used for git push' | ||
required: true | ||
git_user_email: | ||
description: 'User email used for git push' | ||
required: true | ||
reaction_emote: | ||
description: 'Reaction to check by the PR author' | ||
description: 'Path to file which should be inspected - relative to GitHub workspace' | ||
required: true | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: 'Set env variables' | ||
run: | | ||
echo "DIFF_FILE_ABS='${{ github.workspace }}/${{ inputs.diff_file }}'" >> $GITHUB_ENV | ||
echo "DIFF_FILE_DIR=$(dirname '${{ github.workspace }}/${{ inputs.diff_file }}')" >> $GITHUB_ENV | ||
echo "DIFF_FILE_NAME=$(basename '${{ github.workspace }}/${{ inputs.diff_file }}')" >> $GITHUB_ENV | ||
shell: bash | ||
|
||
- name: Execute ${{ inputs.script_call }} | ||
working-directory: ${{ inputs.git_diff_root }} | ||
run: ${{ inputs.script_call }} | ||
shell: bash | ||
|
||
- name: 'Upload Artifact: ${{ inputs.diff_file }}' | ||
uses: actions/upload-artifact@v3 | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ inputs.diff_file }} | ||
path: ${{ inputs.git_diff_root }}/${{ inputs.diff_path }}/${{ inputs.diff_file }} | ||
name: ${{ env.DIFF_FILE_NAME }} | ||
path: ${{ inputs.diff_file }} | ||
|
||
- name: Check for changes in ${{ inputs.diff_file }} | ||
working-directory: ${{ inputs.git_diff_root }} | ||
working-directory: ${{ env.DIFF_FILE_DIR }} | ||
id: diff | ||
shell: bash | ||
run: | | ||
|
@@ -65,73 +51,30 @@ runs: | |
echo EOF | ||
} >> $GITHUB_ENV | ||
- name: Post diff comment | ||
uses: nrfconnect/[email protected] | ||
id: comment | ||
if: ${{ steps.diff.outputs.diff_result == 1 }} | ||
env: | ||
REACT_EMOTE: ${{ inputs.reaction_emote }} | ||
with: | ||
github-token: ${{ inputs.github-token }} | ||
reaction: "${{ env.REACT_EMOTE }}" | ||
message: "${{ inputs.message_diff }}" | ||
|
||
- name: Post success comment | ||
uses: nrfconnect/[email protected] | ||
env: | ||
REACT_EMOTE: ${{ inputs.reaction_emote }} | ||
if: ${{ steps.diff.outputs.diff_result == 0 }} | ||
with: | ||
github-token: ${{ inputs.github-token }} | ||
reaction: "${{ env.REACT_EMOTE }}" | ||
message: "${{ inputs.message_success }}" | ||
|
||
- name: Add changed file | ||
working-directory: ${{ inputs.git_diff_root }} | ||
if: ${{ steps.comment.outputs.found_reaction == 'True' && steps.diff.outputs.diff_result == 1 }} | ||
shell: bash | ||
env: | ||
GH_TOKEN: ${{ inputs.github-token }} | ||
run: | | ||
gh pr checkout ${{ github.event.pull_request.number }} | ||
git config user.email "\"${{ inputs.git_user_email }}\"" | ||
git config user.name "\"${{ inputs.git_user_name }}\"" | ||
git add ${{ inputs.diff_path }}/${{ inputs.diff_file }} | ||
echo -e '`${{ inputs.diff_file }}` has changed. Pushing to PR branch.' >> $GITHUB_STEP_SUMMARY | ||
git config credential.helper store | ||
echo "https://x-access-token:${{ inputs.github-token }}@github.com" >> ~/.git-credentials | ||
git commit -s -m "ci: Updating ${{ inputs.diff_file }}" \ | ||
-m 'This is an automated commit from github workflow by NordicBuilder' | ||
git push | ||
rm ~/.git-credentials | ||
unset GH_TOKEN | ||
- name: Post summary | ||
if: ${{ !cancelled() }} | ||
shell: bash | ||
run: | | ||
if [[ 1 == ${{ steps.diff.outputs.diff_result }} ]]; then | ||
echo -e 'New ${{ inputs.diff_file }} file differs from the current file.' >> $GITHUB_STEP_SUMMARY | ||
fi | ||
if [[ -e ${{ inputs.git_diff_root }}/${{ inputs.diff_path }}/${{ inputs.diff_file }} ]]; then | ||
if [[ -e ${{ env.DIFF_FILE_ABS }} ]]; then | ||
echo -e ' | ||
<details> | ||
<summary>${{ inputs.diff_file }}</summary> | ||
```' >> $GITHUB_STEP_SUMMARY | ||
cat ${{ inputs.git_diff_root }}/${{ inputs.diff_path }}/${{ inputs.diff_file }} >> $GITHUB_STEP_SUMMARY | ||
cat ${{ env.DIFF_FILE_ABS }} >> $GITHUB_STEP_SUMMARY | ||
echo -e '``` | ||
</details>' >> $GITHUB_STEP_SUMMARY | ||
else | ||
echo -e 'Error during workflow, ${{ inputs.diff_file }} file was not created' >> GITHUB_STEP_SUMMARY | ||
echo -e 'Error during workflow, ${{ inputs.diff_file }} file was not created' >> $GITHUB_STEP_SUMMARY | ||
fi | ||
if [[ -n $GITDIFF ]] && [[ 1 == ${{ steps.diff.outputs.diff_result}} ]]; then | ||
echo -e ' | ||
<details> | ||
<summary>${{ inputs.diff_file }} diff</summary> | ||
<summary>${{ env.DIFF_FILE_NAME }} diff</summary> | ||
``` diff' >> $GITHUB_STEP_SUMMARY | ||
echo "$GITDIFF" >> $GITHUB_STEP_SUMMARY | ||
|