Skip to content

Sync Country IPs #12376

Sync Country IPs

Sync Country IPs #12376

Workflow file for this run

# Workflow Name
name: Sync Country IPs
# Triggers: When should this workflow run?
on:
# Allows manual execution from the GitHub Actions tab
workflow_dispatch:
# Scheduled run: Every 5 minutes
schedule:
- cron: '*/5 * * * *'
jobs:
sync-countries:
# Use the latest version of Ubuntu for this job
runs-on: ubuntu-latest
# Grant write permissions to the GITHUB_TOKEN for this job
permissions:
contents: write
# Job steps
steps:
# Step 1: Checkout your repository's code
- name: Checkout local repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
# Step 2: Sync Country IP Blocks
- name: Sync from herrbischoff/country-ip-blocks
run: |
echo "Cloning source repository for country IPs..."
git clone --depth 1 https://github.com/herrbischoff/country-ip-blocks.git temp_source_repo
echo "Syncing country IPs to custom directory names..."
mkdir -p ipv4-countries
mkdir -p ipv6-countries
rsync -av --delete temp_source_repo/ipv4/ ipv4-countries/
rsync -av --delete temp_source_repo/ipv6/ ipv6-countries/
echo "Cleaning up temporary directory..."
rm -rf temp_source_repo
# Step 3: Commit and push changes if any exist
- name: Commit and push changes
run: |
# Configure Git for committing with your details
git config --global user.name "mo13ammad"
git config --global user.email "mo13ammad@users.noreply.github.com"
# Stage changes only for the country directories
git add ipv4-countries/ ipv6-countries/
# Check if there are any staged changes to be committed
if ! git diff --staged --quiet; then
echo "Country IP changes detected. Committing and pushing..."
# Create a commit message with the date and time in Tehran time
COMMIT_DATE=$(TZ="Asia/Tehran" date +'%Y-%m-%d %H:%M:%S')
git commit -m "Auto-sync: Country IP data updated on $COMMIT_DATE (Tehran Time)"
# Push the changes to your repository
git push
else
echo "No changes detected for country IPs."
fi