update build

This commit is contained in:
秋云
2025-04-28 22:49:19 +08:00
parent 68a0c10ac9
commit e6078b3bf4
2 changed files with 19 additions and 20 deletions

View File

@@ -28,6 +28,7 @@ jobs:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
@@ -35,7 +36,6 @@ jobs:
- run: node ./build/build.js
- uses: stefanzweifel/git-auto-commit-action@v5
with:
fetch-depth: 0
commit_message: update repo.json
upload:

View File

@@ -16,13 +16,23 @@ function calculateSHA1(filePath) {
function getGitTimestamp(filePath) {
try {
const time = execSync(`git log -1 --format="%ai" -- ${filePath}`).toString().trim();
return time || 'No commit found';
if (!time) {
console.warn(`未找到文件 ${filePath} 的提交记录`);
return null;
}
return time;
} catch (e) {
console.warn(`无法通过 Git 获取时间: ${filePath}`, e);
return null;
}
}
function formatTime(timestamp) {
if (!timestamp) return null;
// 将 "2023-01-01 12:00:00 +0800" 格式化为 "20230101120000"
return timestamp.replace(/[-: ]/g, '').split('+')[0];
}
function convertNewlines(text) {
return text.replace(/\\n/g, '\n');
}
@@ -37,12 +47,8 @@ function extractInfoFromCombatFile(filePath) {
.map(char => char.trim())
.filter(char => char.length > 0 && !char.match(/^[,.]$/)); // 过滤掉单个逗号或句号
let version = getGitTimestamp(filePath);
if (!version) {
version = calculateSHA1(filePath).substring(0, 7);
} else {
version = formatTime(version);
}
const gitTimestamp = getGitTimestamp(filePath);
const version = gitTimestamp ? formatTime(gitTimestamp) : calculateSHA1(filePath).substring(0, 7);
return {
author: authorMatch ? authorMatch[1].trim() : '',
@@ -91,12 +97,9 @@ function extractInfoFromPathingFile(filePath, parentFolders) {
const contentObj = JSON.parse(content);
// 提取版本字段,若不存在则使用上传时间,还不存在就使用 SHA
let version = contentObj.info && contentObj.info.version;
if (!version) {
const gitDate = getGitTimestamp(filePath);
version = gitDate ? formatTime(gitDate) : calculateSHA1(filePath).substring(0, 7);
}
// 优先使用 Git 提交时间作为版本号
const gitTimestamp = getGitTimestamp(filePath);
const version = gitTimestamp ? formatTime(gitTimestamp) : (contentObj.info?.version || calculateSHA1(filePath).substring(0, 7));
let tags = parentFolders.slice(2)
.filter(tag => !tag.includes('@'))
@@ -138,12 +141,8 @@ function extractInfoFromTCGFile(filePath, parentFolder) {
tags = ['酒馆挑战', ...tags];
}
let version = getGitTimestamp(filePath);
if (!version) {
version = calculateSHA1(filePath).substring(0, 7);
} else {
version = formatTime(version);
}
const gitTimestamp = getGitTimestamp(filePath);
const version = gitTimestamp ? formatTime(gitTimestamp) : calculateSHA1(filePath).substring(0, 7);
return {
author: authorMatch ? authorMatch[1].trim() : '',