From c60cb4aa7b06faca439e4335b4eb9727570072db Mon Sep 17 00:00:00 2001 From: Mahipal <42860185+mukul975@users.noreply.github.com> Date: Wed, 15 Apr 2026 22:43:16 +0200 Subject: [PATCH] Update star.yml --- .github/workflows/star.yml | 224 +++++++++++++++++++++++++++---------- 1 file changed, 164 insertions(+), 60 deletions(-) diff --git a/.github/workflows/star.yml b/.github/workflows/star.yml index c1f03b0b..ec25e901 100644 --- a/.github/workflows/star.yml +++ b/.github/workflows/star.yml @@ -1,84 +1,188 @@ # .github/workflows/star-milestones.yml -name: Star Milestone Tracker +name: ⭐ Star Milestone Tracker on: schedule: - cron: '0 * * * *' workflow_dispatch: + inputs: + force_check: + description: 'Force milestone check regardless of current state' + required: false + default: 'false' permissions: actions: write +concurrency: + group: star-milestone-check + cancel-in-progress: false + +env: + REPO: mukul975/Anthropic-Cybersecurity-Skills + MILESTONE_INTERVAL: 500 + VAR_NAME: LAST_STAR_MILESTONE + jobs: check-stars: runs-on: ubuntu-latest + timeout-minutes: 5 + steps: - - name: Check star count & notify milestones - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} - REPO: mukul975/Anthropic-Cybersecurity-Skills + - name: Fetch star count + id: stars run: | - # Get current star count - STARS=$(curl -s -H "Authorization: token $GH_TOKEN" \ - https://api.github.com/repos/$REPO | jq .stargazers_count) - echo "Current stars: $STARS" + RESPONSE=$(curl -s -o /tmp/repo.json -w "%{http_code}" \ + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github+json" \ + "https://api.github.com/repos/$REPO") - # Get last notified milestone — separate body and status code - BODY=$(curl -s -o /tmp/var_response.json -w "%{http_code}" \ - -H "Authorization: token $GH_TOKEN" \ - "https://api.github.com/repos/$REPO/actions/variables/LAST_STAR_MILESTONE") - HTTP_STATUS="$BODY" - echo "HTTP status: $HTTP_STATUS" - - if [ "$HTTP_STATUS" = "200" ]; then - LAST=$(jq -r '.value // "0"' /tmp/var_response.json) - else - LAST="0" + if [ "$RESPONSE" != "200" ]; then + echo "❌ GitHub API error: $RESPONSE" + exit 1 fi - echo "Last notified milestone: $LAST" - # Calculate highest multiple of 500 crossed - NOTIFY_MILESTONE=$(( (STARS / 500) * 500 )) - NEXT=$(( (STARS / 500 + 1) * 500 )) - echo "Current milestone: $NOTIFY_MILESTONE | Next: $NEXT ($(( NEXT - STARS )) stars to go)" + STARS=$(jq .stargazers_count /tmp/repo.json) + FORKS=$(jq .forks_count /tmp/repo.json) + echo "stars=$STARS" >> $GITHUB_OUTPUT + echo "forks=$FORKS" >> $GITHUB_OUTPUT + echo "✅ Stars: $STARS | Forks: $FORKS" - if [ "$NOTIFY_MILESTONE" -gt "$LAST" ] && [ "$NOTIFY_MILESTONE" -gt 0 ]; then - echo "🎉 New milestone hit: $NOTIFY_MILESTONE" + - name: Fetch last milestone + id: last + run: | + RESPONSE=$(curl -s -o /tmp/var.json -w "%{http_code}" \ + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github+json" \ + "https://api.github.com/repos/$REPO/actions/variables/$VAR_NAME") - # Send Slack notification - curl -X POST "$SLACK_WEBHOOK" \ - -H 'Content-type: application/json' \ - -d "{ - \"text\": \"⭐ *Star Milestone Reached!*\", - \"attachments\": [{ - \"color\": \"#FFD700\", - \"fields\": [ - {\"title\": \"Milestone\", \"value\": \"$NOTIFY_MILESTONE stars 🎯\", \"short\": true}, - {\"title\": \"Current Stars\", \"value\": \"$STARS ⭐\", \"short\": true}, - {\"title\": \"Repo\", \"value\": \"$REPO\", \"short\": false}, - {\"title\": \"Link\", \"value\": \"https://github.com/$REPO\", \"short\": false} - ] - }] - }" + echo "status=$RESPONSE" >> $GITHUB_OUTPUT - # Create or update variable - if [ "$HTTP_STATUS" = "404" ]; then - curl -s -X POST \ - -H "Authorization: token $GH_TOKEN" \ - -H "Content-type: application/json" \ - "https://api.github.com/repos/$REPO/actions/variables" \ - -d "{\"name\":\"LAST_STAR_MILESTONE\",\"value\":\"$NOTIFY_MILESTONE\"}" - echo "Created LAST_STAR_MILESTONE = $NOTIFY_MILESTONE" - else - curl -s -X PATCH \ - -H "Authorization: token $GH_TOKEN" \ - -H "Content-type: application/json" \ - "https://api.github.com/repos/$REPO/actions/variables/LAST_STAR_MILESTONE" \ - -d "{\"name\":\"LAST_STAR_MILESTONE\",\"value\":\"$NOTIFY_MILESTONE\"}" - echo "Updated LAST_STAR_MILESTONE = $NOTIFY_MILESTONE" - fi + if [ "$RESPONSE" = "200" ]; then + LAST=$(jq -r '.value' /tmp/var.json) + else + LAST="INIT" + fi + echo "value=$LAST" >> $GITHUB_OUTPUT + echo "📌 Last milestone: $LAST" + + - name: Evaluate milestone + id: milestone + run: | + STARS=${{ steps.stars.outputs.stars }} + LAST="${{ steps.last.outputs.value }}" + + CURRENT=$(( (STARS / MILESTONE_INTERVAL) * MILESTONE_INTERVAL )) + NEXT=$(( CURRENT + MILESTONE_INTERVAL )) + REMAINING=$(( NEXT - STARS )) + PROGRESS=$(( (STARS % MILESTONE_INTERVAL) * 100 / MILESTONE_INTERVAL )) + + echo "current=$CURRENT" >> $GITHUB_OUTPUT + echo "next=$NEXT" >> $GITHUB_OUTPUT + echo "remaining=$REMAINING" >> $GITHUB_OUTPUT + echo "progress=$PROGRESS" >> $GITHUB_OUTPUT + + if [ "$LAST" = "INIT" ]; then + echo "notify=false" >> $GITHUB_OUTPUT + echo "init=true" >> $GITHUB_OUTPUT + echo "🚀 First run — initializing baseline at $CURRENT, no notification sent" + + elif [ "$CURRENT" -gt "$LAST" ] && [ "$CURRENT" -gt 0 ]; then + echo "notify=true" >> $GITHUB_OUTPUT + echo "init=false" >> $GITHUB_OUTPUT + echo "🎉 NEW MILESTONE: $CURRENT (was $LAST)" else - echo "No new milestone. Next at $NEXT stars ($(( NEXT - STARS )) to go)" + echo "notify=false" >> $GITHUB_OUTPUT + echo "init=false" >> $GITHUB_OUTPUT + echo "💤 No new milestone. Next: $NEXT in $REMAINING stars ($PROGRESS% there)" fi + + - name: Send Slack notification + if: steps.milestone.outputs.notify == 'true' + run: | + STARS=${{ steps.stars.outputs.stars }} + FORKS=${{ steps.stars.outputs.forks }} + MILESTONE=${{ steps.milestone.outputs.current }} + NEXT=${{ steps.milestone.outputs.next }} + REMAINING=${{ steps.milestone.outputs.remaining }} + PROGRESS=${{ steps.milestone.outputs.progress }} + + if [ "$MILESTONE" -ge 10000 ]; then BADGE="🏆" + elif [ "$MILESTONE" -ge 5000 ]; then BADGE="🔥" + elif [ "$MILESTONE" -ge 2500 ]; then BADGE="🚀" + elif [ "$MILESTONE" -ge 1000 ]; then BADGE="💫" + else BADGE="⭐" + fi + + curl -s -X POST "${{ secrets.SLACK_WEBHOOK_URL }}" \ + -H 'Content-type: application/json' \ + -d "{ + \"text\": \"$BADGE *$MILESTONE Star Milestone Reached!*\", + \"attachments\": [{ + \"color\": \"#FFD700\", + \"blocks\": [ + { + \"type\": \"section\", + \"fields\": [ + {\"type\": \"mrkdwn\", \"text\": \"*🎯 Milestone*\n$MILESTONE stars\"}, + {\"type\": \"mrkdwn\", \"text\": \"*⭐ Total Stars*\n$STARS\"}, + {\"type\": \"mrkdwn\", \"text\": \"*🍴 Forks*\n$FORKS\"}, + {\"type\": \"mrkdwn\", \"text\": \"*🔜 Next Milestone*\n$NEXT ($REMAINING to go — $PROGRESS% there)\"} + ] + }, + { + \"type\": \"actions\", + \"elements\": [{ + \"type\": \"button\", + \"text\": {\"type\": \"plain_text\", \"text\": \"View Repo ↗\"}, + \"url\": \"https://github.com/$REPO\", + \"style\": \"primary\" + }] + } + ] + }] + }" + echo "✅ Slack notified" + + - name: Save milestone + if: steps.milestone.outputs.notify == 'true' || steps.milestone.outputs.init == 'true' + run: | + MILESTONE=${{ steps.milestone.outputs.current }} + STATUS=${{ steps.last.outputs.status }} + + if [ "$STATUS" = "200" ]; then + METHOD="PATCH" + URL="https://api.github.com/repos/$REPO/actions/variables/$VAR_NAME" + else + METHOD="POST" + URL="https://api.github.com/repos/$REPO/actions/variables" + fi + + HTTP=$(curl -s -o /dev/null -w "%{http_code}" \ + -X "$METHOD" \ + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github+json" \ + -H "Content-type: application/json" \ + "$URL" \ + -d "{\"name\":\"$VAR_NAME\",\"value\":\"$MILESTONE\"}") + + if [ "$HTTP" = "200" ] || [ "$HTTP" = "201" ] || [ "$HTTP" = "204" ]; then + echo "✅ Saved $VAR_NAME = $MILESTONE" + else + echo "❌ Failed to save variable (HTTP $HTTP)" + exit 1 + fi + + - name: Summary + run: | + echo "## ⭐ Star Tracker Run" >> $GITHUB_STEP_SUMMARY + echo "| Field | Value |" >> $GITHUB_STEP_SUMMARY + echo "|---|---|" >> $GITHUB_STEP_SUMMARY + echo "| Current Stars | ${{ steps.stars.outputs.stars }} |" >> $GITHUB_STEP_SUMMARY + echo "| Current Forks | ${{ steps.stars.outputs.forks }} |" >> $GITHUB_STEP_SUMMARY + echo "| Last Milestone | ${{ steps.last.outputs.value }} |" >> $GITHUB_STEP_SUMMARY + echo "| Next Milestone | ${{ steps.milestone.outputs.next }} |" >> $GITHUB_STEP_SUMMARY + echo "| Stars to Next | ${{ steps.milestone.outputs.remaining }} |" >> $GITHUB_STEP_SUMMARY + echo "| Progress | ${{ steps.milestone.outputs.progress }}% |" >> $GITHUB_STEP_SUMMARY + echo "| Notified | ${{ steps.milestone.outputs.notify }} |" >> $GITHUB_STEP_SUMMARY