Skip to content

Update RU ASN List

Update RU ASN List #45

Workflow file for this run

name: Update RU ASN List
on:
workflow_dispatch:
inputs:
force_large_change:
description: Allow publishing when ASN count drops by more than 50%
required: false
default: false
type: boolean
schedule:
- cron: "23 3 * * *"
concurrency:
group: update-ru-asn
cancel-in-progress: false
permissions:
contents: write
jobs:
update:
runs-on: ubuntu-latest
outputs:
repo_private: ${{ steps.repo_state.outputs.private }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: "3.x"
- name: Detect repository visibility
id: repo_state
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
private="$(gh api "repos/${GITHUB_REPOSITORY}" --jq '.private')"
echo "private=${private}" >> "$GITHUB_OUTPUT"
- name: Generate artifacts
env:
REPO_PRIVATE: ${{ steps.repo_state.outputs.private }}
FORCE_LARGE_CHANGE: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.force_large_change || 'false' }}
run: |
set -euo pipefail
args=()
if [ "${FORCE_LARGE_CHANGE}" = "true" ]; then
args+=(--force-large-change)
fi
if [ "${REPO_PRIVATE}" = "true" ]; then
args+=(--publish-pages)
fi
python3 tools/generate_ru_asn.py "${args[@]}"
- name: Validate generated list
run: python3 tools/generate_ru_asn.py --check
- name: Prepare heartbeat when needed
env:
REPO_PRIVATE: ${{ steps.repo_state.outputs.private }}
run: |
set -euo pipefail
if [ "${REPO_PRIVATE}" = "true" ]; then
exit 0
fi
if ! git diff --quiet -- ru_asn.list ru_asn.meta.json; then
exit 0
fi
python3 - <<'PY'
import json
from datetime import datetime, timedelta, timezone
from pathlib import Path
heartbeat_path = Path("meta/heartbeat.json")
now = datetime.now(timezone.utc).replace(microsecond=0)
previous = None
if heartbeat_path.exists():
data = json.loads(heartbeat_path.read_text(encoding="utf-8"))
previous_raw = data.get("heartbeat_at_utc")
if previous_raw:
previous = datetime.fromisoformat(previous_raw.replace("Z", "+00:00"))
if previous is not None and now - previous <= timedelta(days=30):
raise SystemExit(0)
heartbeat_path.parent.mkdir(parents=True, exist_ok=True)
payload = {
"heartbeat_at_utc": now.isoformat().replace("+00:00", "Z"),
}
heartbeat_path.write_text(
json.dumps(payload, ensure_ascii=False, indent=2) + "\n",
encoding="utf-8",
newline="\n",
)
PY
- name: Commit and push when needed
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
if git diff --cached --quiet; then
echo "No changes to commit"
exit 0
fi
if [ "$(git diff --cached --name-only | tr '\n' ' ')" = "meta/heartbeat.json " ]; then
message="chore: heartbeat"
else
message="chore: update RU ASN list"
fi
git commit -m "${message}"
git push
- name: Upload Pages artifact
if: steps.repo_state.outputs.private == 'true'
uses: actions/upload-pages-artifact@v5
with:
path: site
deploy-pages:
if: needs.update.outputs.repo_private == 'true'
needs: update
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy GitHub Pages artifact
id: deployment
uses: actions/deploy-pages@v5