-
Notifications
You must be signed in to change notification settings - Fork 0
67 lines (54 loc) · 2.09 KB
/
Copy pathupdate-metrics.yml
File metadata and controls
67 lines (54 loc) · 2.09 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
name: update-gh-pages-metrics
on:
schedule:
- cron: '0 0 * * 1' # Weekly schedule
workflow_dispatch: # Manual trigger
permissions:
contents: write
statuses: write
jobs:
update-metrics:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the repository
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7.0.1
# Step 2: Install jq for JSON processing
- name: Install jq
run: |
sudo apt-get update
sudo apt-get install -y jq
# Step 3: Fetch and generate metrics.json
- name: Generate metrics.json
env:
API_URL: "https://api.github.com/orgs/${{ github.repository_owner }}/repos"
METRICS_FILE: "data/metrics.json"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Validate token availability
if [[ -z "$GITHUB_TOKEN" ]]; then
echo "Error: GITHUB_TOKEN is not available."
exit 1
fi
# Prepare directories
rm -rf data && mkdir -p data
# Fetch repository data
status_code=$(curl -s -o response.json -w "%{http_code}" -H "Authorization: token $GITHUB_TOKEN" "$API_URL")
# Check HTTP status code
if [ "$status_code" -ne 200 ]; then
echo "Failed to fetch repository data. HTTP Status: $status_code"
echo "Response:"
cat response.json
exit 1
fi
# Parse and sort repositories by stargazers_count (top 5)
repos=$(jq -r '.[] | {(.name): .stargazers_count}' response.json | jq -s add | jq -r 'to_entries | sort_by(-.value)[:5] | from_entries')
# Generate metrics.json
echo "$repos" | jq -r '.' > "$METRICS_FILE"
echo "metrics.json generated successfully."
# Step 4: Commit and push changes
- name: Commit and push changes
uses: EndBug/add-and-commit@cc9c08ba6c8df3b93a8f2db63e89b98368ae2ae8 #v11.1.1
with:
message: "Update metrics.json with top repositories"
add: "data/metrics.json"