-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8b2677
commit 864acf5
Showing
10 changed files
with
177 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/bin/bash | ||
|
||
# Set the path to the snippets folder | ||
WATCHER_PATH=$1 | ||
|
||
output() { | ||
echo "$1" | ||
} | ||
|
||
file_contains(){ | ||
local ERROR_FOUND=0 | ||
# Get the content of the URL | ||
FILE_CONTENT=$(curl -sl $WATCHER_URL) | ||
|
||
# Check if $WATCHER_CONTAINS contains the string "null" and is therefore empty or not set | ||
if [[ $WATCHER_CONTAINS == "null" ]]; then | ||
output "No contain set" | ||
echo 1 | ||
fi | ||
# Check if $WATCHER_CONTAINS contains the string $WATCHER_CONTAINS and if not call the Slack webhook | ||
if [[ $FILE_CONTENT == *"$WATCHER_CONTAINS"* ]]; then | ||
output "String found!" | ||
else | ||
output echo "String not found! Please check $WATCHER_URL" | ||
echo 1 | ||
fi | ||
} | ||
|
||
error_found() { | ||
ERROR_FOUND=$1 | ||
echo "Error found: $ERROR_FOUND" | ||
if [ "$ERROR_FOUND" -eq 1 ] | ||
then | ||
echo "Error found, exiting..." | ||
exit 1 | ||
fi | ||
} | ||
|
||
# Find all files in the snippets folder | ||
find $WATCHER_PATH -type f -print0 | while IFS= read -r -d '' file; do | ||
|
||
# Check if the file contains the string "WATCHER_URL" and is therefore a watcher file | ||
cat "$file" | grep 'WATCHER_URL' >> /dev/null || continue | ||
|
||
|
||
# Get the JSON from the first line of the file | ||
HEAD=$(cat "$file" | grep 'WATCHER_URL') | ||
JSON=$(sed "s/# //g" <<< "$HEAD") | ||
|
||
# Get the values from the JSON | ||
WATCHER_URL=$(echo $JSON | jq -r '.WATCHER_URL') | ||
WATCHER_HASH=$(echo $JSON | jq -r '.WATCHER_HASH') | ||
WATCHER_CONTAINS=$(echo $JSON | jq -r '.WATCHER_CONTAINS') | ||
|
||
# Get the hash of the URL | ||
EVAL_HASH="curl -sl $WATCHER_URL | md5sum | cut -d ' ' -f 1" | ||
CALLED_HASH="$(eval $EVAL_HASH)" | ||
|
||
# Check if the hashes are equal | ||
if [ "$WATCHER_HASH" == "$CALLED_HASH" ]; then | ||
echo "Both strings are equal." | ||
else | ||
echo "Strings are not equal." | ||
ERROR_FOUND="$(file_contains)" | ||
fi | ||
|
||
done | ||
|
||
error_found $ERROR_FOUND |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Check files for changes | ||
on: | ||
pull_request: | ||
workflow_dispatch: | ||
inputs: | ||
path: | ||
description: "Path to watch" | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
check-files: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- run: | | ||
bash .github/scripts/watch.sh snippets | ||
bash .github/scripts/watch.sh guides | ||
id: watcher | ||
continue-on-error: true | ||
- name: Send custom JSON data to Slack workflow | ||
if: steps.watcher.outcome != 'success' | ||
id: slack | ||
uses: slackapi/[email protected] | ||
with: | ||
payload: | | ||
{ | ||
"text": "Text: GitHub Action build result: ${{ job.status }}", | ||
"blocks": [ | ||
{ | ||
"type": "section", | ||
"text": { | ||
"type": "mrkdwn", | ||
"text": ":ladybug: Failed file watcher with status ${{ steps.watcher.outcome }}: Please check ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | ||
} | ||
} | ||
] | ||
} | ||
env: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_NOTIFICATIONS_WEBHOOK }} | ||
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK |
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
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,3 +1,4 @@ | ||
shopware: | ||
html_sanitizer: | ||
enabled: false | ||
# {"WATCHER_URL":"https://raw.githubusercontent.com/shopware/shopware/trunk/src/Core/Framework/Resources/config/packages/shopware.yaml","WATCHER_HASH":"183f85ba8f15e8e7d0006b70be20940f","WATCHER_CONTAINS":"html_sanitizer"} |
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
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/bin/bash | ||
|
||
# Set the path to the snippets folder | ||
WATCHER_PATH='snippets' | ||
|
||
# Set the Slack webhook | ||
SLACK_WEBHOOK='https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX' | ||
|
||
file_contains(){ | ||
# Get the content of the URL | ||
FILE_CONTENT=$(curl -sl $WATCHER_URL) | ||
|
||
# Check if $WATCHER_CONTAINS contains the string "null" and is therefore empty or not set | ||
if [[ $WATCHER_CONTAINS == "null" ]]; then | ||
exit 0 | ||
fi | ||
# Check if $WATCHER_CONTAINS contains the string $WATCHER_CONTAINS and if not call the Slack webhook | ||
if [[ $FILE_CONTENT == *"$WATCHER_CONTAINS"* ]]; then | ||
echo "String found - nice!" | ||
else | ||
echo "String not found - not nice!" | ||
curl -X POST -H 'Content-type: application/json' --data '{"text":"String not found - not nice!"}' $SLACK_WEBHOOK | ||
fi | ||
} | ||
|
||
# Find all files in the snippets folder | ||
find $WATCHER_PATH -type f -print0 | while IFS= read -r -d '' file; do | ||
|
||
# Check if the file contains the string "WATCHER_URL" and is therefore a watcher file | ||
cat "$file" | grep 'WATCHER_URL' >> /dev/null || continue | ||
|
||
|
||
# Get the JSON from the first line of the file | ||
HEAD=$(cat "$file" | grep 'WATCHER_URL') | ||
JSON=$(sed "s/# //g" <<< "$HEAD") | ||
|
||
# Get the values from the JSON | ||
WATCHER_URL=$(echo $JSON | jq -r '.WATCHER_URL') | ||
WATCHER_HASH=$(echo $JSON | jq -r '.WATCHER_HASH') | ||
WATCHER_CONTAINS=$(echo $JSON | jq -r '.WATCHER_CONTAINS') | ||
|
||
# Get the hash of the URL | ||
EVAL_HASH="curl -sl $WATCHER_URL | md5sum | cut -d ' ' -f 1" | ||
CALLED_HASH="$(eval $EVAL_HASH)" | ||
|
||
# Check if the hashes are equal | ||
if [ "$WATCHER_HASH" == "$CALLED_HASH" ]; then | ||
echo "Both strings are equal." | ||
else | ||
echo "Strings are not equal." | ||
file_contains | ||
fi | ||
|
||
|
||
done |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"WATCHER_URL": 'https://raw.githubusercontent.com/shopware/shopware/trunk/src/Core/Framework/Resources/config/packages/shopware.yaml', | ||
"WATCHER_HASH": "007d0a0b2d9ed8db6f484980b9a29459", | ||
"WATCHER_CONTAINS": "html_sanitizer" | ||
} |