Skip to content

Commit 306954a

Browse files
committed
🔨 Mapの構造変更と、workflow追加
1 parent 82934c7 commit 306954a

20 files changed

+700
-509
lines changed

.github/workflows/auto_release.yml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: Release on Version Change
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: リポジトリをチェックアウト
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 2 # 差分を取るために1つ前のコミットも取る
17+
18+
- name: 変更されたか確認
19+
id: version_check
20+
run: |
21+
if git diff --name-only HEAD^ HEAD | grep -q "^package\.json$"; then
22+
echo "package.json changed"
23+
24+
OLD_VERSION=$(git show HEAD^:package.json | jq -r .version)
25+
NEW_VERSION=$(jq -r .version package.json)
26+
echo "Old version: $OLD_VERSION"
27+
echo "New version: $NEW_VERSION"
28+
29+
old="${OLD_VERSION#v}"
30+
new="${NEW_VERSION#v}"
31+
IFS='.' read -r -a o <<< "$old"
32+
IFS='.' read -r -a n <<< "$new"
33+
34+
is_newer=false
35+
changed_higher_digit=false
36+
37+
for i in 0 1 2; do
38+
o=${old_parts[i]:-0}
39+
n=${new_parts[i]:-0}
40+
if (( n > o )); then
41+
changed_higher_digit=true
42+
is_newer=true
43+
break
44+
elif (( n < o )); then
45+
# ダウングレードはNG
46+
exit 0
47+
fi
48+
done
49+
50+
# 一番下の桁だけチェック(3番目のインデックス)
51+
o=${old_parts[3]:-0}
52+
n=${new_parts[3]:-0}
53+
if [ "$changed_higher_digit" = false ] && (( n > o )); then
54+
is_newer=true
55+
fi
56+
57+
if [ "$is_newer" = true ]; then
58+
echo "version_changed=true" >> $GITHUB_OUTPUT
59+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
60+
echo "old_version=$OLD_VERSION" >> $GITHUB_OUTPUT
61+
echo "changed_higher_digit=$changed_higher_digit" >> $GITHUB_OUTPUT
62+
else
63+
echo "No version upgrade"
64+
fi
65+
else
66+
echo "package.json not changed"
67+
fi
68+
69+
- name: 旧リリースのpre-release状態を切り替え
70+
if: steps.version_check.outputs.version_changed == 'true'
71+
env:
72+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73+
OLD_VERSION: ${{ steps.version_check.outputs.old_version }}
74+
CHANGED_HIGHER_DIGIT: ${{ steps.version_check.outputs.changed_higher_digit }}
75+
run: |
76+
# GitHub APIで旧リリース情報取得
77+
release_info=$(curl -s \
78+
-H "Authorization: token $GITHUB_TOKEN" \
79+
"https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/tags/$OLD_VERSION")
80+
81+
release_id=$(echo "$release_info" | jq -r '.id')
82+
83+
if [ "$release_id" != "null" ]; then
84+
if [ "$CHANGED_HIGHER_DIGIT" = "true" ]; then
85+
# pre-release解除
86+
pre_release=false
87+
else
88+
# pre-release化
89+
pre_release=true
90+
fi
91+
92+
# 旧リリースをPATCH
93+
curl -X PATCH \
94+
-H "Authorization: token $GITHUB_TOKEN" \
95+
-H "Content-Type: application/json" \
96+
-d "{\"prerelease\": $pre_release}" \
97+
"https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/$release_id"
98+
else
99+
echo "旧リリースが見つかりません。スキップ"
100+
fi
101+
102+
- name: 新リリース作成(latestタグ付き)
103+
if: steps.version_check.outputs.version_changed == 'true'
104+
uses: softprops/action-gh-release@v2
105+
with:
106+
tag_name: ${{ steps.version_check.outputs.new_version }}
107+
name: ${{ steps.version_check.outputs.new_version }}
108+
body: ""
109+
draft: false
110+
prerelease: false
111+
112+
env:
113+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

dev/build.js

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const exorcist = require("exorcist");
33
const fs = require("node:fs");
44
const path = require("node:path");
55
const { minify } = require("terser");
6+
const { execSync } = require("node:child_process");
67

78
const generateIndex = require("./generateIndex.js");
89
const CL = require("./libs/ColorLogger.js");
@@ -43,7 +44,7 @@ function formatSize(bytes) {
4344
// ファイルサイズ取得
4445
function showFileSize(filePath) {
4546
const stat = fs.statSync(filePath);
46-
console.log(`📦 ${CL.brightWhite(path.basename(filePath))}: ${CL.brightGreen(formatSize(stat.size))}`);
47+
console.log(`📦 ${CL.brightWhite(path.basename(filePath))}: ${CL.brightGreen(formatSize(stat.size))}`);
4748
}
4849

4950
// Browserifyでバンドル
@@ -95,28 +96,41 @@ async function minifyCode(code) {
9596
}
9697

9798
(async () => {
99+
const debug = true;
98100
try {
101+
const start = performance.now();
102+
console.log(`🎉 ${CL.brightYellow("ビルド開始")}`);
99103
//
100-
console.log(`🔁 ${CL.brightWhite("index.js自動生成開始...")}`);
104+
console.log(`🔁 ${CL.brightWhite("index.js自動生成開始...")}`);
101105
generateIndex(entryDir);
102-
console.log(`🌱 ${CL.brightWhite("自動生成完了")}`);
106+
console.log(`┃┗🌱 ${CL.brightWhite("自動生成完了")}`);
103107
//
104-
console.log(`🗑️ ${CL.brightWhite("distフォルダリセット")}`);
108+
console.log(`🗑️ ${CL.brightWhite("distフォルダリセット")}`);
105109
prepareDist();
106110
//
107-
console.log(`🗂️ ${CL.brightWhite("バンドル中...")}`);
111+
console.log(`🗂️ ${CL.brightWhite("バンドル中...")}`);
108112
const code = await bundle();
109-
console.log(` ${CL.brightWhite("バンドル完了")}: ${getRelativePath(bundlePath)}`);
110-
console.log(`🗺️ ${CL.brightWhite("ソースマップ生成")}: ${getRelativePath(bundleMapPath)}`);
111-
112-
console.log(`🔧 ${CL.brightWhite("Minify中...")}`);
113+
console.log(`┃┣✅ ${CL.brightWhite("バンドル完了")}: ${getRelativePath(bundlePath)}`);
114+
console.log(`┃┗🗺️ ${CL.brightWhite("ソースマップ生成")}: ${getRelativePath(bundleMapPath)}`);
115+
//
116+
console.log(`🔧 ${CL.brightWhite("Minify中...")}`);
113117
await minifyCode(code);
114-
console.log(`✅ ${CL.brightWhite("Minify完了:")} ${getRelativePath(minPath)}`);
115-
console.log(`🗺️ ${CL.brightWhite("ソースマップ生成[min]")}: ${getRelativePath(minMapPath)}`);
118+
console.log(`┃┣${CL.brightWhite("Minify完了:")} ${getRelativePath(minPath)}`);
119+
console.log(`┃┗🗺️ ${CL.brightWhite("ソースマップ生成[min]")}: ${getRelativePath(minMapPath)}`);
116120
showFileSize(bundlePath);
117121
showFileSize(minPath);
122+
//
123+
if (debug) {
124+
console.log(`┃🗒️ ${CL.brightWhite("TypeScriptコンパイル中...")}`);
125+
execSync("npx tsc", { stdio: "inherit" });
126+
console.log(`┃┗✅ ${CL.brightWhite("TypeScriptコンパイル完了")}`);
127+
}
128+
129+
console.log(`┣🎉 ${CL.brightYellow("ビルド完了")}`);
130+
const end = performance.now() - start;
131+
console.log(`┗🕒 ${CL.brightWhite("ビルド時間")}: ${CL.brightGreen(end.toFixed(2))} ms`);
118132
} catch (e) {
119-
console.error("❌ ビルド失敗:", e);
133+
console.error("❌ ビルド失敗:", e);
120134
process.exit(1);
121135
}
122136
})();

dev/generateIndex.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function generateIndex(dir, baseDir = dir) {
6666
// index.jsを書き込み
6767
fs.writeFileSync(path.join(dir, "index.js"), content, "utf8");
6868

69-
console.log(`📜 Generated index.js in ${CL.brightBlue(path.relative(path.dirname(baseDir), dir))}`);
69+
console.log(`┃┣📜 Generated index.js in ${CL.brightBlue(path.relative(path.dirname(baseDir), dir))}`);
7070
}
7171

7272
module.exports = generateIndex;

0 commit comments

Comments
 (0)