forked from super3/bitworld.gg
-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (100 loc) · 4.04 KB
/
update-subscriber-count.yml
File metadata and controls
113 lines (100 loc) · 4.04 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
name: Update Subscriber Count
on:
schedule:
# Run every hour
- cron: '0 * * * *'
workflow_dispatch: # Allow manual trigger
jobs:
update-count:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Fetch subscriber count from ConvertKit public page
id: fetch-count
run: |
# Try to fetch from public stats page
# Note: This URL pattern might need adjustment based on ConvertKit's public stats
STATS_URL="https://app.convertkit.com/forms/8269255/stats"
# For now, we'll need the API key since public stats aren't easily scrapeable
# If you find a public endpoint, replace this section
if [ -n "${{ secrets.CONVERTKIT_API_SECRET }}" ]; then
# Get form subscribers using the correct endpoint
RESPONSE=$(curl -s "https://api.convertkit.com/v3/forms/8269255/subscriptions?api_secret=${{ secrets.CONVERTKIT_API_SECRET }}")
echo "API Response: $RESPONSE"
COUNT=$(echo $RESPONSE | jq -r '.total_subscriptions // 0')
else
# Fallback: increment existing count (not ideal but works without API)
if [ -f subscriber-count.json ]; then
COUNT=$(cat subscriber-count.json | jq -r '.count // 1')
else
COUNT=1
fi
fi
# Update the JSON file
echo "{
\"count\": $COUNT,
\"lastUpdated\": \"$(date -u +%Y-%m-%dT%H:%M:%SZ)\"
}" > subscriber-count.json
echo "Subscriber count: $COUNT"
echo "count=$COUNT" >> $GITHUB_OUTPUT
- name: Update Gist with subscriber count
run: |
# Create or update gist with subscriber count
GIST_ID="${{ secrets.GIST_ID }}"
# Prepare the JSON content
JSON_CONTENT=$(cat subscriber-count.json | jq -c . | sed 's/"/\\"/g')
if [ -z "$GIST_ID" ]; then
echo "Creating new gist..."
RESPONSE=$(curl -s -X POST \
-H "Authorization: Bearer ${{ secrets.GIST_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-H "Content-Type: application/json" \
https://api.github.com/gists \
-d "{
\"description\": \"Bitworld subscriber count\",
\"public\": true,
\"files\": {
\"subscriber-count.json\": {
\"content\": \"$JSON_CONTENT\"
}
}
}")
echo "Full API Response: $RESPONSE"
NEW_GIST_ID=$(echo $RESPONSE | jq -r '.id // empty')
if [ -n "$NEW_GIST_ID" ] && [ "$NEW_GIST_ID" != "null" ]; then
echo "Created gist with ID: $NEW_GIST_ID"
echo "Add this as GIST_ID secret in your repository"
echo "Gist URL: https://gist.github.com/$NEW_GIST_ID"
else
echo "Failed to create gist. Check if GIST_TOKEN has 'gist' scope."
echo "Error details: $(echo $RESPONSE | jq -r '.message // empty')"
exit 1
fi
else
# Update existing gist
echo "Updating existing gist: $GIST_ID"
UPDATE_RESPONSE=$(curl -s -X PATCH \
-H "Authorization: Bearer ${{ secrets.GIST_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-H "Content-Type: application/json" \
https://api.github.com/gists/$GIST_ID \
-d "{
\"files\": {
\"subscriber-count.json\": {
\"content\": \"$JSON_CONTENT\"
}
}
}")
if echo "$UPDATE_RESPONSE" | jq -e '.id' > /dev/null; then
echo "Successfully updated gist: https://gist.github.com/$GIST_ID"
else
echo "Failed to update gist"
echo "Error: $(echo $UPDATE_RESPONSE | jq -r '.message // empty')"
exit 1
fi
fi