-
Notifications
You must be signed in to change notification settings - Fork 0
124 lines (105 loc) · 4.66 KB
/
awesome-stars.yml
File metadata and controls
124 lines (105 loc) · 4.66 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
name: update awesome-stars
on:
workflow_dispatch:
schedule:
- cron: "30 0 * * *"
jobs:
awesome-stars:
name: update awesome-stars
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install starred requests
- name: get repository name
run: echo "REPOSITORY_NAME=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV
- name: update repo category by language
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPOSITORY: ${{ env.REPOSITORY_NAME }}
USERNAME: ${{ github.repository_owner }}
run: starred --username ${USERNAME} --repository ${REPOSITORY} --sort --token ${GITHUB_TOKEN} --message 'awesome-stars category by language update by github actions cron, created by starred'
- name: update repo category by topic
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPOSITORY: ${{ env.REPOSITORY_NAME }}
USERNAME: ${{ github.repository_owner }}
run: starred --username ${USERNAME} --repository ${REPOSITORY} --sort --token ${GITHUB_TOKEN} --message 'awesome-stars category by topic update by github actions cron, created by starred' --topic --topic_limit 500 --filename topics.md
- name: Sync Stars to Worker API
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
USERNAME: ${{ github.repository_owner }}
WORKER_API_URL: "https://core-github-api.hacolby.workers.dev/upsert/stars"
# Ensure you add this secret to your repo settings
WORKER_API_KEY: ${{ secrets.WORKER_API_KEY }}
run: |
cat <<EOF > sync_stars.py
import os
import requests
import json
import sys
def sync_stars():
token = os.environ.get("GITHUB_TOKEN")
username = os.environ.get("USERNAME")
worker_url = os.environ.get("WORKER_API_URL")
worker_secret = os.environ.get("WORKER_API_KEY")
if not worker_url:
print("::error::Worker URL is missing.")
sys.exit(1)
print(f"Fetching stars for {username}...")
# Fetch stars from GitHub (handling pagination)
stars = []
page = 1
headers = {
"Authorization": f"Bearer {token}",
"Accept": "application/vnd.github.v3+json"
}
while True:
try:
url = f"https://api.github.com/users/{username}/starred?per_page=100&page={page}"
response = requests.get(url, headers=headers)
response.raise_for_status()
data = response.json()
if not data:
break
stars.extend(data)
print(f"Fetched page {page} ({len(data)} repos)...")
page += 1
except Exception as e:
print(f"::error::Failed to fetch from GitHub: {e}")
sys.exit(1)
print(f"Total stars fetched: {len(stars)}")
# Prepare payload for Worker
payload = {
"username": username,
"count": len(stars),
"stars": stars
}
# Send to Cloudflare Worker
print(f"Sending data to {worker_url}...")
try:
# We use a custom header for security if you've implemented it on the worker side
worker_headers = {
"Content-Type": "application/json",
"User-Agent": "github-actions/awesome-stars-sync"
}
if worker_secret:
worker_headers["X-API-Key"] = worker_secret
worker_headers["Authorization"] = f"Bearer {worker_secret}"
r = requests.post(worker_url, json=payload, headers=worker_headers)
r.raise_for_status()
print("::notice::Successfully synced stars to Worker API.")
except Exception as e:
print(f"::error::Failed to post to Worker: {e}")
# Optional: Fail the job if sync fails, or allow it to pass
sys.exit(1)
if __name__ == "__main__":
sync_stars()
EOF
python sync_stars.py