Skip to content

Auto Update BGP Data #3971

Auto Update BGP Data

Auto Update BGP Data #3971

Workflow file for this run

name: Auto Update BGP Data
on:
schedule:
# Routing table data: updated every 2 hours
- cron: "0 */2 * * *"
# ASN and Tags data: updated daily at 01:00 UTC
- cron: "0 1 * * *"
workflow_dispatch:
inputs:
data_type:
description: "Select the data type to update"
required: true
default: "all"
type: choice
options:
- all
- table
- asns
- tags
env:
NODE_VERSION: "22"
PNPM_VERSION: "10.11.0"
GO_VERSION: "1.25"
TABLE_SCHEDULE: "0 */2 * * *"
ARCHIVE_SCHEDULE: "0 1 * * *"
concurrency:
group: auto-update-${{ github.ref }}
cancel-in-progress: true
jobs:
update-data:
runs-on: ubuntu-22.04
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v7
with:
fetch-depth: 1
token: ${{ secrets.GITHUB_TOKEN }}
ref: main
- name: Cleanup disk space
uses: ./.github/actions/cleanup-disk-space
with:
clean-tools-cache: "false"
clean-docker: "false"
- name: Setup runtime
uses: ./.github/actions/setup-runtime
with:
node-version: ${{ env.NODE_VERSION }}
pnpm-version: ${{ env.PNPM_VERSION }}
go-version: ${{ env.GO_VERSION }}
- name: Configure git
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Determine update targets
id: targets
env:
EVENT_NAME: ${{ github.event_name }}
SCHEDULE: ${{ github.event.schedule }}
INPUT_DATA_TYPE: ${{ github.event.inputs.data_type }}
run: |
set -euo pipefail
TARGETS=""
MODE=""
if [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then
case "$INPUT_DATA_TYPE" in
all) TARGETS="table asns tags" ;;
table) TARGETS="table" ;;
asns) TARGETS="asns" ;;
tags) TARGETS="tags" ;;
*) echo "❌ Unknown data_type input: $INPUT_DATA_TYPE" && exit 1 ;;
esac
elif [[ "$EVENT_NAME" == "schedule" ]]; then
if [[ "$SCHEDULE" == "${{ env.TABLE_SCHEDULE }}" ]]; then
TARGETS="table"
elif [[ "$SCHEDULE" == "${{ env.ARCHIVE_SCHEDULE }}" ]]; then
TARGETS="asns tags"
MODE="daily"
else
echo "⚠️ Schedule $SCHEDULE not mapped to any dataset. Exiting."
exit 0
fi
else
echo "⚠️ Event $EVENT_NAME not supported."
exit 0
fi
if [[ -z "$TARGETS" ]]; then
echo "⚠️ No targets determined. Exiting."
exit 0
fi
echo "Selected targets: $TARGETS"
if [[ -n "$MODE" ]]; then
echo "Additional mode: $MODE"
fi
echo "targets=$TARGETS" >> "$GITHUB_OUTPUT"
echo "mode=$MODE" >> "$GITHUB_OUTPUT"
- name: Setup auto-update branch
run: ./scripts/setup-auto-update-branch.js
- name: Update datasets
if: steps.targets.outputs.targets != ''
env:
TARGETS: ${{ steps.targets.outputs.targets }}
MODE: ${{ steps.targets.outputs.mode }}
run: |
set -euo pipefail
for dataset in $TARGETS; do
echo "🔄 Updating $dataset..."
if [[ "$dataset" == "table" || -z "$MODE" ]]; then
./scripts/update-and-commit-data.js "$dataset"
else
./scripts/update-and-commit-data.js "$dataset" "$MODE"
fi
./scripts/clean-old-files.js "$dataset"
done
- name: Push changes
if: steps.targets.outputs.targets != ''
run: ./scripts/push-to-auto-update.js