1
+ #! /bin/bash
2
+
3
+ # URL of the webpage
4
+ URL=" https://auth0.com/docs"
5
+
6
+ # Slack webhook URL
7
+ WEBHOOK_URL=" https://hooks.slack.com/triggers/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"
8
+
9
+ # Function to send Slack notification with the version as a data variable
10
+ send_slack_notification () {
11
+ local version=" $1 "
12
+ curl -s -X POST -H ' Content-type: application/json' --data " {
13
+ \" version\" : \" ${version} \"
14
+ }" " $WEBHOOK_URL "
15
+ }
16
+
17
+ # Directory to store the current version file
18
+ SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
19
+ VERSION_FILE=" ${SCRIPT_DIR} /tmp/current_version.txt"
20
+
21
+ # Ensure the tmp directory exists
22
+ mkdir -p " ${SCRIPT_DIR} /tmp"
23
+
24
+ # Read the current version from the file, if it exists
25
+ if [ -f " $VERSION_FILE " ]; then
26
+ current_version=$( cat " $VERSION_FILE " )
27
+ else
28
+ current_version=" "
29
+ fi
30
+
31
+ # Bypass cache by using cache-control headers and appending a unique query string
32
+ cache_bypass=$( date +%s)
33
+ response=$( curl -s -H " Cache-Control: no-cache, no-store, must-revalidate" \
34
+ -H " Pragma: no-cache" \
35
+ -H " Expires: 0" \
36
+ " ${URL} ?nocache=${cache_bypass} " )
37
+
38
+ # Print the response for debugging
39
+ echo " Response from URL: $response "
40
+
41
+ # Extract the new version from the response
42
+ new_version=$( echo " $response " | sed -n ' s/.*"CONTENT_PACKAGE_VERSION":"\([^"]*\)".*/\1/p' )
43
+
44
+ # Print the new version for debugging
45
+ echo " Extracted new version: $new_version "
46
+
47
+ # Compare with stored version
48
+ if [ " $new_version " != " $current_version " ]; then
49
+ echo " Package version updated: $new_version "
50
+ # Send Slack notification with the version
51
+ send_slack_notification " $new_version "
52
+ # Update the current version in the file
53
+ echo " $new_version " > " $VERSION_FILE "
54
+ else
55
+ echo " Package version has not changed."
56
+ fi
0 commit comments