Skip to content

Commit 1872a2f

Browse files
authored
Merge pull request vavkamil#57 from vavkamil/vavkamil/workflow
feat(ci): Add Stargazers check
2 parents d8fa6e9 + b80da49 commit 1872a2f

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

.github/workflows/stargazers.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Stargazers
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'README.md'
7+
8+
permissions: {}
9+
10+
jobs:
11+
check-new-links:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/[email protected]
19+
with:
20+
fetch-depth: 0 # we need history for diff
21+
22+
- name: Fetch base branch
23+
run: |
24+
git fetch origin ${{ github.base_ref }} --depth=1
25+
26+
- name: Extract newly added GitHub repo links
27+
run: |
28+
# Show diff between base branch and PR HEAD, only for README
29+
git diff --unified=0 origin/${{ github.base_ref }}...HEAD -- README.md > diff.txt
30+
31+
# Extract only added (+) lines that contain github.com, strip the leading '+'
32+
# Then use a simple regex-ish sed to grab the URL
33+
sed -n 's/^+.*\(https:\/\/github.com\/[^ )]*\).*/\1/p' diff.txt \
34+
| sort -u > new_links.txt
35+
36+
echo "New links found:"
37+
cat new_links.txt || echo "None"
38+
39+
- name: Check stars for new links (unauthenticated)
40+
run: |
41+
set -euo pipefail
42+
43+
while read -r url; do
44+
[ -z "$url" ] && continue
45+
46+
repo="$(printf '%s\n' "$url" | sed -E 's#https://github.com/([^/]+/[^/]+).*#\1#')"
47+
[ -z "$repo" ] && continue
48+
49+
echo "Checking $repo"
50+
51+
resp=$(curl -s "https://api.github.com/repos/$repo")
52+
msg=$(echo "$resp" | jq -r '.message // empty')
53+
54+
if [ "$msg" = "Not Found" ]; then
55+
echo "::error ::Repository $repo does not exist (404)"
56+
exit_code=1
57+
continue
58+
fi
59+
60+
stars=$(echo "$resp" | jq -r '.stargazers_count // 0')
61+
echo "Stars: $stars"
62+
63+
if [ "$stars" -lt 50 ]; then
64+
echo "::error ::Repository $repo has only $stars stars (< 50)"
65+
exit_code=1
66+
fi
67+
done < new_links.txt
68+
69+
exit ${exit_code:-0}

0 commit comments

Comments
 (0)