第一步:在需要添加sponsor模块的repo根目录下新建文件sponsorkit.config.js
该文件会自动输出svg,png和json格式的sponsor信息
import { defineConfig, presets } from 'sponsorkit'
export default defineConfig({
// Rendering configs
width: 800,
formats: ['svg', 'png','json'],
tiers: [
// Past sponsors, currently only supports GitHub
{
title: 'Past Sponsors',
monthlyDollars: -1,
preset: presets.xs,
},
// Default tier
{
title: 'Backers',
preset: presets.base,
},
{
title: 'Sponsors',
monthlyDollars: 0.5,
preset: presets.medium,
},
{
title: 'Silver Sponsors',
monthlyDollars: 1,
preset: presets.large,
},
{
title: 'Gold Sponsors',
monthlyDollars: 5,
preset: presets.xl,
},
],
})
第二步:目录添加package.json文件
{
"type": "module",
"packageManager": "[email protected]",
"scripts": {
"build": "sponsorkit"
},
"devDependencies": {
"@types/node": "^20.12.11",
"sponsorkit": "^0.14.0"
}
}
第三步:获取token
SPONSORKIT_GITHUB_TOKEN在头像->Settings->Developer settings->Personal->Tokens添加,需要有read:user
and read:org
权限
其它Token的获取地址请参考这里
第四步:添加Token
打开repo -> Settings -> Secrets and variables -> Actions, 点击New repository secret
添加你需要的token:
第五步:添加Github action
也就是在.github/workflows文件夹下新建scheduler.yml文件
name: Scheduler
on:
workflow_dispatch:
schedule:
- cron: '30 5,17 * * *'
push:
branches: [main]
jobs:
update-sponsors:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
- name: Set node
uses: actions/setup-node@v4
with:
node-version: lts/*
- run: corepack enable && pnpm i
- name: Update sponsors
run: pnpm exec sponsorkit --dir .
env:
SPONSORKIT_GITHUB_LOGIN: versun
SPONSORKIT_GITHUB_TOKEN: ${{ secrets.SPONSORKIT_GITHUB_TOKEN }}
SPONSORKIT_AFDIAN_USER_ID: ${{ secrets.SPONSORKIT_AFDIAN_USER_ID }}
SPONSORKIT_AFDIAN_TOKEN: ${{ secrets.SPONSORKIT_AFDIAN_TOKEN }}
SPONSORKIT_OPENCOLLECTIVE_KEY: ${{ secrets.SPONSORKIT_OPENCOLLECTIVE_KEY }}
SPONSORKIT_OPENCOLLECTIVE_SLUG: ${{ secrets.SPONSORKIT_OPENCOLLECTIVE_SLUG }}
SPONSORKIT_OPENCOLLECTIVE_TYPE: collective
SPONSORKIT_POLAR_TOKEN: ${{ secrets.SPONSORKIT_POLAR_TOKEN }}
- name: Commit
uses: EndBug/add-and-commit@v5
with:
message: 'chore: update sponsors.svg'
add: 'sponsors.*'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
最后,授予Action写权限:
打开Repo -> Settings -> Actions -> General
在最后的Workflow permissions勾选“Read and write permissions”即可。
完成,你现在可以去Actions运行workflow,正常情况下会把输出的svg等文件提交到根目录的sponsorkit文件夹下
发表回复