Skip to content

update awesome-stars #2

update awesome-stars

update awesome-stars #2

Workflow file for this run

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