-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated content package version check script
- Loading branch information
harishsundar-okta
committed
Aug 30, 2024
1 parent
95a1a5e
commit ea3c9a7
Showing
2 changed files
with
78 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,22 @@ | ||
name: Check Content Version | ||
|
||
on: | ||
schedule: | ||
- cron: '0 * * * *' # Runs every hour | ||
workflow_dispatch: # Allows manual trigger from GitHub Actions tab | ||
|
||
jobs: | ||
run-script: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Make script executable | ||
run: chmod +x scripts/check-version.sh | ||
shell: bash | ||
|
||
- name: Run check-version.sh script | ||
run: scripts/check-version.sh | ||
shell: bash |
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,56 @@ | ||
#!/bin/bash | ||
|
||
# URL of the webpage | ||
URL="https://auth0.com/docs" | ||
|
||
# Slack webhook URL | ||
WEBHOOK_URL="https://hooks.slack.com/triggers/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" | ||
|
||
# Function to send Slack notification with the version as a data variable | ||
send_slack_notification() { | ||
local version="$1" | ||
curl -s -X POST -H 'Content-type: application/json' --data "{ | ||
\"version\": \"${version}\" | ||
}" "$WEBHOOK_URL" | ||
} | ||
|
||
# Directory to store the current version file | ||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
VERSION_FILE="${SCRIPT_DIR}/tmp/current_version.txt" | ||
|
||
# Ensure the tmp directory exists | ||
mkdir -p "${SCRIPT_DIR}/tmp" | ||
|
||
# Read the current version from the file, if it exists | ||
if [ -f "$VERSION_FILE" ]; then | ||
current_version=$(cat "$VERSION_FILE") | ||
else | ||
current_version="" | ||
fi | ||
|
||
# Bypass cache by using cache-control headers and appending a unique query string | ||
cache_bypass=$(date +%s) | ||
response=$(curl -s -H "Cache-Control: no-cache, no-store, must-revalidate" \ | ||
-H "Pragma: no-cache" \ | ||
-H "Expires: 0" \ | ||
"${URL}?nocache=${cache_bypass}") | ||
|
||
# Print the response for debugging | ||
echo "Response from URL: $response" | ||
|
||
# Extract the new version from the response | ||
new_version=$(echo "$response" | sed -n 's/.*"CONTENT_PACKAGE_VERSION":"\([^"]*\)".*/\1/p') | ||
|
||
# Print the new version for debugging | ||
echo "Extracted new version: $new_version" | ||
|
||
# Compare with stored version | ||
if [ "$new_version" != "$current_version" ]; then | ||
echo "Package version updated: $new_version" | ||
# Send Slack notification with the version | ||
send_slack_notification "$new_version" | ||
# Update the current version in the file | ||
echo "$new_version" > "$VERSION_FILE" | ||
else | ||
echo "Package version has not changed." | ||
fi |