Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
push:
branches:
- main
workflow_run:
workflows: ["Monthly Script Runner"]
types:
- completed

jobs:
build-deploy:
Expand Down
67 changes: 67 additions & 0 deletions .github/workflows/sync-ranking-data-by-month.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Monthly Script Runner

# 触发条件:每月的1号运行
on:
schedule:
- cron: "0 0 0 * *" # 每月一号的00:00 UTC时间运行
workflow_dispatch:

jobs:
run-scripts:
runs-on: ubuntu-latest

steps:
# 检出代码
- name: Checkout repository
uses: actions/checkout@v4

# 设置 Node.js 环境
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20' # 使用 Node.js 18

# 运行第一个脚本 sync_xlab.js,从接口获取最新数据
- name: Run sync_xlab.js
run: node script/sync_xlab.js

# 运行第二个脚本 update_year_user.js, 更新 rankingList.json
- name: Run update_year_user.js
run: node script/update_year_user.js
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# 运行第三个脚本 front-matter.js, 批量创建详情页
- name: Run front-matter.js
run: node script/front-matter.js

# 提交并推送更改到 main 分支
- name: Commit and push changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
git commit -m "chore: Automated data update from scripts"
git push origin main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# # 创建并推送 PR
# - name: Create Pull Request
# id: create_pr
# uses: peter-evans/create-pull-request@v7
# with:
# commit-message: "chore: Updating data from xlab"
# title: "chore: Updating data from xlab"
# body: "Updating data from xlab,and create user homepages"
# branch: update-ranking-data
# base: "main"
# delete-branch: true

# # 启用自动合并
# - name: Enable auto-merge
# uses: peter-evans/enable-pull-request-automerge@v3
# with:
# token: ${{ secrets.GITHUB_TOKEN }}
# pull-request-number: ${{ steps.create_pr.outputs.pull-request-number }}
# merge-method: merge
5 changes: 3 additions & 2 deletions script/front-matter.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ async function updateFrontMatter(login, item) {
}

// 主函数
async function main(year) {
async function main() {
const year = new Date().getFullYear();
try {
const rankingsData = await readRankingData(year);

Expand All @@ -90,4 +91,4 @@ async function main(year) {
}

// 执行主程序
main(2024);
main();
10 changes: 6 additions & 4 deletions script/sync_xlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ async function writeRankingData(data) {
}

// 主函数
async function main(year) {
async function main() {
const year = new Date().getFullYear();
console.log(year);
const rankingData = await readRankingData();
const xlabData = await fetchXlab(year);

Expand All @@ -49,7 +51,7 @@ async function main(year) {
return;
}

const yearIndex = rankingData.findIndex(v => v.year === year);
const yearIndex = rankingData.findIndex(v => Number(v.year) === year);
// 获取当前时间戳
const update = `${new Date().getFullYear()} 年 ${new Date().getMonth() + 1} 月`;
const ranking = {
Expand All @@ -58,7 +60,7 @@ async function main(year) {
annualRanking: xlabData,
};

if (yearIndex > 0) {
if (yearIndex > -1) {
rankingData[yearIndex] = ranking;
} else {
// 插入新的年份数据
Expand All @@ -71,4 +73,4 @@ async function main(year) {
await writeRankingData(rankingData);
}

main(2024);
main();
7 changes: 4 additions & 3 deletions script/update_year_user.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const fs = require('fs').promises;
const path = require('path');

// 运行此脚本 需要配置 github_token 否则会 API 拉取会被 github 限制
const GITHUB_TOKEN = ''; // 替换为你的 GitHub 个人访问令牌
const GITHUB_TOKEN = process.env.GITHUB_TOKEN; // 替换为你的 GitHub 个人访问令牌
// 防止速度过快被 github 限制
const TIME_DELAY = 600;

Expand Down Expand Up @@ -96,7 +96,8 @@ async function enrichRankingData(data) {
}

// 主函数
async function main(year) {
async function main() {
const year = new Date().getFullYear();
try {
const rankingsData = await readRankingData();
const yearData = rankingsData.find(yearData => yearData.year === year);
Expand All @@ -114,4 +115,4 @@ async function main(year) {
}
}

main(2024);
main();