refactor(calculate-version): 將版本計算邏輯由 bash 改寫為 Node.js 並依功能分檔
保留 entrypoint.sh 作為容器進入點,改為啟動 app/ 下的 Node.js 程式; 依功能拆分為 logger/config/version/releases/output/index,並更新 Dockerfile 改用 node:lts-alpine。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
4983a72524
commit
bd6b6017ab
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
|
||||
const { test, beforeEach, afterEach } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const os = require('node:os');
|
||||
const path = require('node:path');
|
||||
const { writeOutput } = require('../output');
|
||||
|
||||
let workspace;
|
||||
|
||||
beforeEach(() => {
|
||||
workspace = fs.mkdtempSync(path.join(os.tmpdir(), 'calc-version-'));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(workspace, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test('writeOutput 將 name=value 附加寫入輸出檔', () => {
|
||||
const file = path.join(workspace, 'output');
|
||||
writeOutput('version', '1.2.3', file);
|
||||
assert.equal(fs.readFileSync(file, 'utf8'), 'version=1.2.3\n');
|
||||
});
|
||||
|
||||
test('writeOutput 以附加方式保留既有內容', () => {
|
||||
const file = path.join(workspace, 'output');
|
||||
fs.writeFileSync(file, 'existing=1\n');
|
||||
writeOutput('version', '1.2.3', file);
|
||||
assert.equal(fs.readFileSync(file, 'utf8'), 'existing=1\nversion=1.2.3\n');
|
||||
});
|
||||
|
||||
test('writeOutput 在未提供輸出檔時丟出錯誤', () => {
|
||||
assert.throws(() => writeOutput('version', '1.2.3', undefined), /GITHUB_OUTPUT 未設定/);
|
||||
});
|
||||
Reference in New Issue
Block a user