From 1678e4e459dc8c82ba921c2738096ceac0a1b97c Mon Sep 17 00:00:00 2001 From: Harish Sundar Date: Fri, 30 Aug 2024 11:58:22 +0530 Subject: [PATCH] updated content package version check script (#10455) Co-authored-by: harishsundar-okta --- .github/workflows/check-content-version.yml | 22 ++++++++ scripts/check-version.sh | 56 +++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 .github/workflows/check-content-version.yml create mode 100755 scripts/check-version.sh diff --git a/.github/workflows/check-content-version.yml b/.github/workflows/check-content-version.yml new file mode 100644 index 0000000000..8d471da8b9 --- /dev/null +++ b/.github/workflows/check-content-version.yml @@ -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 \ No newline at end of file diff --git a/scripts/check-version.sh b/scripts/check-version.sh new file mode 100755 index 0000000000..92a80085f8 --- /dev/null +++ b/scripts/check-version.sh @@ -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 \ No newline at end of file