diff --git a/src/index.js b/src/index.js index a833b02..5fad040 100644 --- a/src/index.js +++ b/src/index.js @@ -12,6 +12,8 @@ const taipeiFormatter = new Intl.DateTimeFormat('en-CA', { }); let currentStage = ''; +let cachedTimestampKey = ''; +let cachedTimestampValue = ''; /** * 格式化台灣時區時間,供 log 使用。 @@ -20,6 +22,11 @@ let currentStage = ''; * @returns {string} `yyyy/MM/dd HH:mm:ss` 格式時間字串。 */ function formatTaipeiTimestamp(date = new Date()) { + const timestampKey = date.toISOString().slice(0, 19); + if (timestampKey === cachedTimestampKey) { + return cachedTimestampValue; + } + const parts = taipeiFormatter.formatToParts(date); const lookup = {}; @@ -29,7 +36,9 @@ function formatTaipeiTimestamp(date = new Date()) { } } - return `${lookup.year}/${lookup.month}/${lookup.day} ${lookup.hour}:${lookup.minute}:${lookup.second}`; + cachedTimestampKey = timestampKey; + cachedTimestampValue = `${lookup.year}/${lookup.month}/${lookup.day} ${lookup.hour}:${lookup.minute}:${lookup.second}`; + return cachedTimestampValue; } /** @@ -348,6 +357,10 @@ async function main() { }); } + if (hadFailure) { + throw new Error('至少有一筆 release 或 tag 刪除失敗'); + } + section('刪除未指定 release 的 tag'); const releaseTags = new Set( @@ -388,9 +401,6 @@ async function main() { } }); - if (hadFailure) { - throw new Error('至少有一筆 release 或 tag 刪除失敗'); - } } main().catch((error) => {