Skip to content

Update URLS

Update URLS #2

Workflow file for this run

name: Update URLS
on:
schedule:
# Run every day at 6:00 AM CET (5:00 AM UTC)
- cron: "0 5 * * *"
workflow_dispatch: # Allows manual triggering
jobs:
update-main-url:
runs-on: ubuntu-latest
steps:
# Checkout the repository
- name: Checkout Code
uses: actions/checkout@v3
# Find the redirected URL and update the file if necessary
- name: Update mainUrl
run: |
# Define the file path
FILE_PATH="CB01/src/main/kotlin/it/dogior/hadEnough/CB01.kt"
# Ensure the file exists
if [ ! -f "$FILE_PATH" ]; then
echo "File $FILE_PATH not found!"
exit 1
fi
# Extract the current URL from the file
CURRENT_URL=$(grep -oP 'override var mainUrl = "\K[^"]+' "$FILE_PATH")
if [ -z "$CURRENT_URL" ]; then
echo "Could not find the current mainUrl in the file!"
exit 1
fi
echo "Current mainUrl: $CURRENT_URL"
# Perform the request and extract the redirected URL
REDIRECTED_URL=$(curl -Ls -o /dev/null -w %{url_effective} "https://cb01.uno")
if [ -z "$REDIRECTED_URL" ]; then
echo "Failed to retrieve the redirected URL!"
exit 1
fi
echo "Redirected URL: $REDIRECTED_URL"
# Check if the URLs match
if [ "$CURRENT_URL" = "$REDIRECTED_URL" ]; then
echo "The redirected URL is the same as the current mainUrl. No update necessary."
exit 0
fi
# Replace the mainUrl value in the file
sed -i "s|override var mainUrl = .*|override var mainUrl = \"$REDIRECTED_URL\"|" "$FILE_PATH"
echo "Updated mainUrl to: $REDIRECTED_URL"
# Commit and push the changes
- name: Commit and Push Changes
if: success() # Only run if the previous step succeeded and made changes
run: |
git config user.name "GitHub Actions Bot"
git config user.email "[email protected]"
git add CB01/src/main/kotlin/it/dogior/hadEnough/CB01.kt
git commit -m "Update url"
git push