update build
This commit is contained in:
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -28,6 +28,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
ref: ${{ github.head_ref }}
|
ref: ${{ github.head_ref }}
|
||||||
|
fetch-depth: 0
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
- name: Use Node.js ${{ matrix.node-version }}
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
@@ -35,7 +36,6 @@ jobs:
|
|||||||
- run: node ./build/build.js
|
- run: node ./build/build.js
|
||||||
- uses: stefanzweifel/git-auto-commit-action@v5
|
- uses: stefanzweifel/git-auto-commit-action@v5
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
|
||||||
commit_message: update repo.json
|
commit_message: update repo.json
|
||||||
|
|
||||||
upload:
|
upload:
|
||||||
|
|||||||
@@ -16,13 +16,23 @@ function calculateSHA1(filePath) {
|
|||||||
function getGitTimestamp(filePath) {
|
function getGitTimestamp(filePath) {
|
||||||
try {
|
try {
|
||||||
const time = execSync(`git log -1 --format="%ai" -- ${filePath}`).toString().trim();
|
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) {
|
} catch (e) {
|
||||||
console.warn(`无法通过 Git 获取时间: ${filePath}`, e);
|
console.warn(`无法通过 Git 获取时间: ${filePath}`, e);
|
||||||
return null;
|
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) {
|
function convertNewlines(text) {
|
||||||
return text.replace(/\\n/g, '\n');
|
return text.replace(/\\n/g, '\n');
|
||||||
}
|
}
|
||||||
@@ -37,12 +47,8 @@ function extractInfoFromCombatFile(filePath) {
|
|||||||
.map(char => char.trim())
|
.map(char => char.trim())
|
||||||
.filter(char => char.length > 0 && !char.match(/^[,.]$/)); // 过滤掉单个逗号或句号
|
.filter(char => char.length > 0 && !char.match(/^[,.]$/)); // 过滤掉单个逗号或句号
|
||||||
|
|
||||||
let version = getGitTimestamp(filePath);
|
const gitTimestamp = getGitTimestamp(filePath);
|
||||||
if (!version) {
|
const version = gitTimestamp ? formatTime(gitTimestamp) : calculateSHA1(filePath).substring(0, 7);
|
||||||
version = calculateSHA1(filePath).substring(0, 7);
|
|
||||||
} else {
|
|
||||||
version = formatTime(version);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
author: authorMatch ? authorMatch[1].trim() : '',
|
author: authorMatch ? authorMatch[1].trim() : '',
|
||||||
@@ -91,12 +97,9 @@ function extractInfoFromPathingFile(filePath, parentFolders) {
|
|||||||
|
|
||||||
const contentObj = JSON.parse(content);
|
const contentObj = JSON.parse(content);
|
||||||
|
|
||||||
// 提取版本字段,若不存在则使用上传时间,还不存在就使用 SHA
|
// 优先使用 Git 提交时间作为版本号
|
||||||
let version = contentObj.info && contentObj.info.version;
|
const gitTimestamp = getGitTimestamp(filePath);
|
||||||
if (!version) {
|
const version = gitTimestamp ? formatTime(gitTimestamp) : (contentObj.info?.version || calculateSHA1(filePath).substring(0, 7));
|
||||||
const gitDate = getGitTimestamp(filePath);
|
|
||||||
version = gitDate ? formatTime(gitDate) : calculateSHA1(filePath).substring(0, 7);
|
|
||||||
}
|
|
||||||
|
|
||||||
let tags = parentFolders.slice(2)
|
let tags = parentFolders.slice(2)
|
||||||
.filter(tag => !tag.includes('@'))
|
.filter(tag => !tag.includes('@'))
|
||||||
@@ -138,12 +141,8 @@ function extractInfoFromTCGFile(filePath, parentFolder) {
|
|||||||
tags = ['酒馆挑战', ...tags];
|
tags = ['酒馆挑战', ...tags];
|
||||||
}
|
}
|
||||||
|
|
||||||
let version = getGitTimestamp(filePath);
|
const gitTimestamp = getGitTimestamp(filePath);
|
||||||
if (!version) {
|
const version = gitTimestamp ? formatTime(gitTimestamp) : calculateSHA1(filePath).substring(0, 7);
|
||||||
version = calculateSHA1(filePath).substring(0, 7);
|
|
||||||
} else {
|
|
||||||
version = formatTime(version);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
author: authorMatch ? authorMatch[1].trim() : '',
|
author: authorMatch ? authorMatch[1].trim() : '',
|
||||||
|
|||||||
Reference in New Issue
Block a user