|
| 1 | +name: Collect Skill Stats |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '17 * * * *' # Every hour at :17 |
| 6 | + workflow_dispatch: {} |
| 7 | + |
| 8 | +jobs: |
| 9 | + collect: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - uses: actions/checkout@v4 |
| 13 | + |
| 14 | + - uses: actions/setup-node@v4 |
| 15 | + with: |
| 16 | + node-version: '20' |
| 17 | + |
| 18 | + - name: Install skills CLI |
| 19 | + run: npm install -g @anthropic-ai/skills 2>/dev/null || true |
| 20 | + |
| 21 | + - name: Collect our skills data |
| 22 | + id: our_skills |
| 23 | + run: | |
| 24 | + OUTPUT=$(npx skills find "second-me-01" 2>/dev/null || echo "") |
| 25 | + echo "output<<EOF" >> $GITHUB_OUTPUT |
| 26 | + echo "$OUTPUT" >> $GITHUB_OUTPUT |
| 27 | + echo "EOF" >> $GITHUB_OUTPUT |
| 28 | +
|
| 29 | + - name: Collect competitor data |
| 30 | + id: competitors |
| 31 | + run: | |
| 32 | + XHS=$(npx skills find "xhs" 2>/dev/null || echo "") |
| 33 | + BRAINSTORM=$(npx skills find "brainstorm" 2>/dev/null || echo "") |
| 34 | + echo "xhs<<EOF" >> $GITHUB_OUTPUT |
| 35 | + echo "$XHS" >> $GITHUB_OUTPUT |
| 36 | + echo "EOF" >> $GITHUB_OUTPUT |
| 37 | + echo "brainstorm<<EOF" >> $GITHUB_OUTPUT |
| 38 | + echo "$BRAINSTORM" >> $GITHUB_OUTPUT |
| 39 | + echo "EOF" >> $GITHUB_OUTPUT |
| 40 | +
|
| 41 | + - name: Parse and submit data |
| 42 | + env: |
| 43 | + API_URL: ${{ secrets.API_URL }} |
| 44 | + API_SECRET: ${{ secrets.API_SECRET }} |
| 45 | + run: | |
| 46 | + node << 'SCRIPT' |
| 47 | + const output = `${{ steps.our_skills.outputs.output }}`; |
| 48 | + const xhsOutput = `${{ steps.competitors.outputs.xhs }}`; |
| 49 | + const brainstormOutput = `${{ steps.competitors.outputs.brainstorm }}`; |
| 50 | +
|
| 51 | + function parseInstalls(text) { |
| 52 | + const results = []; |
| 53 | + const clean = text.replace(/\x1b\[[0-9;]*m/g, ''); |
| 54 | + const lines = clean.split('\n'); |
| 55 | + for (const line of lines) { |
| 56 | + const match = line.trim().match(/^(.+?)@(.+?)\s+([\d,.]+K?)\s+installs?$/); |
| 57 | + if (match) { |
| 58 | + let installs = match[3].replace(/,/g, ''); |
| 59 | + if (installs.endsWith('K')) installs = String(parseFloat(installs) * 1000); |
| 60 | + results.push({ repo: match[1], name: match[2], installs: Math.round(parseFloat(installs)) }); |
| 61 | + } |
| 62 | + } |
| 63 | + return results; |
| 64 | + } |
| 65 | +
|
| 66 | + const ours = parseInstalls(output); |
| 67 | + const xhs = parseInstalls(xhsOutput); |
| 68 | + const brainstorm = parseInstalls(brainstormOutput); |
| 69 | +
|
| 70 | + // Map our skills |
| 71 | + const data = []; |
| 72 | + const ourMap = { |
| 73 | + 'skill-hub': 'skill-hub', |
| 74 | + 'smart-brainstorm': 'smart-brainstorm', |
| 75 | + 'ui-design-system': 'ui-design-system', |
| 76 | + 'xhs-writer': 'xhs-writer', |
| 77 | + 'video-script': 'video-script', |
| 78 | + 'feishu-kit': 'feishu-kit', |
| 79 | + }; |
| 80 | +
|
| 81 | + for (const s of ours) { |
| 82 | + if (ourMap[s.name]) { |
| 83 | + data.push({ skill_id: ourMap[s.name], installs: s.installs, platform: 'skills.sh' }); |
| 84 | + } |
| 85 | + } |
| 86 | +
|
| 87 | + // Find specific competitors |
| 88 | + const daqiXhs = xhs.find(s => s.repo.includes('daqi') && s.name.includes('xhs')); |
| 89 | + if (daqiXhs) data.push({ skill_id: 'comp-daqi-xhs', installs: daqiXhs.installs, platform: 'skills.sh' }); |
| 90 | +
|
| 91 | + const compBrainstorm = brainstorm.find(s => s.name === 'brainstorming' || s.name === 'brainstorm'); |
| 92 | + if (compBrainstorm) data.push({ skill_id: 'comp-brainstorming', installs: compBrainstorm.installs, platform: 'skills.sh' }); |
| 93 | +
|
| 94 | + if (data.length === 0) { |
| 95 | + console.log('No data collected, skipping API call'); |
| 96 | + process.exit(0); |
| 97 | + } |
| 98 | +
|
| 99 | + console.log('Submitting data:', JSON.stringify(data, null, 2)); |
| 100 | +
|
| 101 | + fetch(`${process.env.API_URL}/api/stats/collect`, { |
| 102 | + method: 'POST', |
| 103 | + headers: { |
| 104 | + 'Content-Type': 'application/json', |
| 105 | + 'x-api-secret': process.env.API_SECRET, |
| 106 | + }, |
| 107 | + body: JSON.stringify({ data }), |
| 108 | + }) |
| 109 | + .then(r => r.json()) |
| 110 | + .then(r => console.log('API response:', r)) |
| 111 | + .catch(e => console.error('API error:', e)); |
| 112 | + SCRIPT |
0 commit comments