-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (124 loc) · 4.14 KB
/
Copy pathupdate-ru-asn.yml
File metadata and controls
140 lines (124 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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