Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ concurrency:
permissions:
contents: write
pull-requests: write
actions: write

jobs:
bump:
Expand Down Expand Up @@ -62,14 +61,9 @@ jobs:
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "branch=$BRANCH" >> "$GITHUB_OUTPUT"

# GITHUB_TOKEN による push や PR 作成は他のワークフローを起動しない(連鎖を防ぐ仕様)。
# PR のマージに要る必須チェック test を付けるため、CI を明示的に起動する。
# workflow_dispatch だけはこの制限の例外。チェックはコミットに付くので PR 側にも出る。
- name: CI を起動
env:
GH_TOKEN: ${{ github.token }}
BRANCH: ${{ steps.bump.outputs.branch }}
run: gh workflow run ci.yml --ref "$BRANCH"
# 版上げの PR では CI を起動しない。版しか変えておらず、中身は main と同じため。
# GITHUB_TOKEN による push や PR 作成は他のワークフローを起動しないので、ここで何もしなければ CI は走らない。
# main のルールセットに必須のチェックを足したら、マージできなくなるので gh workflow run ci.yml で起動し直す。

# PR の作成はリポジトリ設定「Allow GitHub Actions to create and approve pull requests」が
# 必要。無効なら作れないので、作成用のリンクを実行結果に残して手で開けるようにする。
Expand Down
46 changes: 44 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,35 @@ env:
VULKAN_SDK_VERSION: 1.4.363.0

jobs:
# 版上げ(bump-version.yml の PR)のマージは package.json と package-lock.json の版しか変えず、
# 中身はマージ前の main と同じ。macOS と Windows のランナーで確かめ直さない(Release のビルドも
# 型チェックとテストを回す)。whisper-cli のキャッシュのキーは版に左右されないので作り直す必要もない。
changes:
runs-on: ubuntu-latest
outputs:
code: ${{ steps.check.outputs.code }}
steps:
- uses: actions/checkout@v4
if: github.event_name == 'push'

- name: 版だけの変更かを確かめる
id: check
env:
BEFORE: ${{ github.event.before }}
run: |
# 迷ったら CI を回す。新しいブランチの push(before が 0)や、before が取れないときも回す。
if [ "$GITHUB_EVENT_NAME" = push ] && [ -n "$BEFORE" ] && [ "$BEFORE" != 0000000000000000000000000000000000000000 ] &&
git fetch --quiet --no-tags --depth=1 origin "$BEFORE" &&
[ "$(node scripts/version-bump.mjs only-version "$BEFORE")" = true ]; then
echo "::notice::版だけの変更なので、テストとビルドを飛ばします。"
echo "code=false" >> "$GITHUB_OUTPUT"
else
echo "code=true" >> "$GITHUB_OUTPUT"
fi

test:
needs: changes
if: needs.changes.outputs.code == 'true'
# macOS ランナーが必須。テストは実際の /usr/bin/afconvert を通してエンコードを
# 検証しており、postinstall も PlistBuddy と codesign を使う。
# xcode-27 なのは、Apple のモデルでの要約(FoundationModels)に macOS 27 SDK が要るため。
Expand All @@ -54,12 +82,18 @@ jobs:
# npm ci が CI の半分以上を占めていた。node_modules ごと保存し、lockfile が
# 変わらない限り npm ci を飛ばす。postinstall でパッチ済みの Electron.app も
# そのまま入っている。キーを変えるときは release.yml と揃える。
# キーは lockfile から版を除いた中身で作る。版上げのたびにキャッシュを外さないため(scripts/version-bump.mjs)。
- name: 依存のキーを求める
id: deps
shell: bash
run: node scripts/version-bump.mjs key >> "$GITHUB_OUTPUT"

- name: node_modules のキャッシュを復元
id: node-modules-cache
uses: actions/cache@v4
with:
path: node_modules
key: node-modules-${{ runner.os }}-${{ runner.arch }}-node24-${{ hashFiles('package-lock.json') }}
key: node-modules-${{ runner.os }}-${{ runner.arch }}-node24-${{ steps.deps.outputs.key }}

- name: 依存関係をインストール
if: steps.node-modules-cache.outputs.cache-hit != 'true'
Expand Down Expand Up @@ -104,6 +138,8 @@ jobs:
# Windows 版に向けて、OS に依存しない部分が Windows でも壊れていないことを確かめる(ADR-048)。
# macOS のコマンドを実際に呼ぶテストは tests/platform.ts の notMacOS で飛ばしている。
test-windows:
needs: changes
if: needs.changes.outputs.code == 'true'
runs-on: windows-latest

steps:
Expand All @@ -114,12 +150,18 @@ jobs:
node-version: 24

# キーに runner.os を含むので、macOS の node_modules とは混ざらない。
# キーは lockfile から版を除いた中身で作る。版上げのたびにキャッシュを外さないため(scripts/version-bump.mjs)。
- name: 依存のキーを求める
id: deps
shell: bash
run: node scripts/version-bump.mjs key >> "$GITHUB_OUTPUT"

- name: node_modules のキャッシュを復元
id: node-modules-cache
uses: actions/cache@v4
with:
path: node_modules
key: node-modules-${{ runner.os }}-${{ runner.arch }}-node24-${{ hashFiles('package-lock.json') }}
key: node-modules-${{ runner.os }}-${{ runner.arch }}-node24-${{ steps.deps.outputs.key }}

- name: 依存関係をインストール
if: steps.node-modules-cache.outputs.cache-hit != 'true'
Expand Down
78 changes: 78 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Publish release

# release.yml は Release を Draft で作る。成果物を手で確かめて公開したら、ここで Homebrew の cask を更新する。
# Draft の成果物は公開の URL から落とせないので、Draft の間に cask を進めると brew upgrade が失敗する。
# GITHUB_TOKEN での公開はこのワークフローを起動しないが、公開は手で行う前提なので問題にならない。
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: 'cask を合わせる公開済みのタグ名(例: v0.1.0)'
required: true
type: string

concurrency:
group: homebrew-tap
cancel-in-progress: false

permissions:
contents: read

jobs:
homebrew:
# プレリリースは releases/latest にも出ないので、cask も進めない。
if: ${{ github.event_name == 'workflow_dispatch' || !github.event.release.prerelease }}
runs-on: ubuntu-latest
steps:
# 公式の homebrew/cask は公証されていないアプリを受け付けないので、自前の tap に置く。
# 書き込みは tap だけに効く deploy key で行い、fork など鍵の無い実行では飛ばす。
- name: Homebrew の cask を更新
env:
GH_TOKEN: ${{ github.token }}
TAP_KEY: ${{ secrets.HOMEBREW_TAP_DEPLOY_KEY }}
TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.event.release.tag_name }}
run: |
set -euo pipefail
if [ -z "$TAP_KEY" ]; then
echo "::warning::HOMEBREW_TAP_DEPLOY_KEY が無いため cask を更新しません。"
exit 0
fi

# 手で動かしたときに Draft のタグを渡すと、利用者が落とせない版に cask を進めてしまう。
if [ "$(gh release view "$TAG" -R "$GITHUB_REPOSITORY" --json isDraft -q .isDraft)" = "true" ]; then
echo "::error::$TAG はまだ Draft です。公開してから実行してください。"
exit 1
fi

# cask の sha256 は、利用者が実際に落とす公開済みの dmg から求める(Draft の間に差し替えた場合も合う)。
VERSION="${TAG#v}"
DMG="exolobe-$VERSION-arm64.dmg"
gh release download "$TAG" -R "$GITHUB_REPOSITORY" -p "$DMG" -D dist
SHA=$(sha256sum "dist/$DMG" | cut -d' ' -f1)

# ssh-keyscan の結果を信じると経路上で差し替えられうるので、GitHub が公開している
# ホスト鍵を固定する。
mkdir -p ~/.ssh
echo 'github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl' >> ~/.ssh/known_hosts
eval "$(ssh-agent -s)"
ssh-add - <<<"$TAP_KEY"

git clone --depth 1 git@github.com:eddybean/homebrew-tap.git tap
cd tap
sed -E -i \
-e "s/^ version \".*\"/ version \"$VERSION\"/" \
-e "s/^ sha256 \".*\"/ sha256 \"$SHA\"/" \
Casks/exolobe.rb

# 同じタグで公開し直したときなど、中身が変わらなければ何もしない。
if git diff --quiet; then
echo "cask は既に $VERSION です。"
exit 0
fi
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git commit -am "exolobe $VERSION"
git push origin HEAD
echo "Homebrew の cask を $VERSION に更新しました。" >> "$GITHUB_STEP_SUMMARY"
61 changes: 17 additions & 44 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ env:
jobs:
# macOS と Windows のジョブが並んで走るので、Release は先にここで 1 度だけ作る。各ジョブが
# 「無ければ作る」をすると、両方が同時に作ろうとして片方が落ちる。
# Draft で作り、成果物を手で確かめてから公開する。公開すると publish-release.yml が Homebrew の cask を更新する。
# アプリの新しい版の通知(ADR-044)は releases/latest を見るので、Draft の間は誰にも届かない。
prepare:
runs-on: ubuntu-latest
steps:
Expand All @@ -49,7 +51,7 @@ jobs:
WINDOWS_NOTE=$'\n\n**Windows**(`exolobe-<版>-x64.exe`): Windows 10 バージョン 2004 以降 / x64 向けのインストーラです。\n\n> **注意**: コード署名をしていないため、初回の実行で SmartScreen の「Windows によって PC が保護されました」が出ます。\n> 「詳細情報」を押し、「実行」を選んでください。'

BODY="**macOS**(\`exolobe-<版>-arm64.dmg\`): macOS 14.2 以上 / Apple Silicon 向けのビルドです。${MAC_NOTE}${WINDOWS_NOTE}"
gh release create "$TAG" -R "$GITHUB_REPOSITORY" --title "$TAG" --notes "$BODY" --generate-notes --verify-tag
gh release create "$TAG" -R "$GITHUB_REPOSITORY" --title "$TAG" --notes "$BODY" --generate-notes --verify-tag --draft

build:
needs: prepare
Expand All @@ -69,12 +71,18 @@ jobs:
# タグ上で保存したキャッシュは次のタグから見えないので、main の CI が作った分を
# 読むだけにする(ここで保存しても使われず、後処理の時間だけがかかる)。
# キーは ci.yml と揃える。
# キーは lockfile から版を除いた中身で作る。版上げのたびにキャッシュを外さないため(scripts/version-bump.mjs)。
- name: 依存のキーを求める
id: deps
shell: bash
run: node scripts/version-bump.mjs key >> "$GITHUB_OUTPUT"

- name: node_modules のキャッシュを復元
id: node-modules-cache
uses: actions/cache/restore@v4
with:
path: node_modules
key: node-modules-${{ runner.os }}-${{ runner.arch }}-node24-${{ hashFiles('package-lock.json') }}
key: node-modules-${{ runner.os }}-${{ runner.arch }}-node24-${{ steps.deps.outputs.key }}

- name: 依存関係をインストール
if: steps.node-modules-cache.outputs.cache-hit != 'true'
Expand Down Expand Up @@ -176,47 +184,6 @@ jobs:
TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}
run: gh release upload "$TAG" ./release/*.dmg --clobber

# 公式の homebrew/cask は公証されていないアプリを受け付けないので、自前の tap に置く。
# 書き込みは tap だけに効く deploy key で行い、fork など鍵の無い実行では飛ばす。
- name: Homebrew の cask を更新
env:
TAP_KEY: ${{ secrets.HOMEBREW_TAP_DEPLOY_KEY }}
TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}
run: |
set -euo pipefail
if [ -z "$TAP_KEY" ]; then
echo "::warning::HOMEBREW_TAP_DEPLOY_KEY が無いため cask を更新しません。"
exit 0
fi

VERSION="${TAG#v}"
SHA=$(shasum -a 256 "release/exolobe-$VERSION-arm64.dmg" | cut -d' ' -f1)

# ssh-keyscan の結果を信じると経路上で差し替えられうるので、GitHub が公開している
# ホスト鍵を固定する。
mkdir -p ~/.ssh
echo 'github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl' >> ~/.ssh/known_hosts
eval "$(ssh-agent -s)"
ssh-add - <<<"$TAP_KEY"

git clone --depth 1 git@github.com:eddybean/homebrew-tap.git tap
cd tap
sed -E -i '' \
-e "s/^ version \".*\"/ version \"$VERSION\"/" \
-e "s/^ sha256 \".*\"/ sha256 \"$SHA\"/" \
Casks/exolobe.rb

# 同じタグで Release を作り直したときなど、中身が変わらなければ何もしない。
if git diff --quiet; then
echo "cask は既に $VERSION です。"
exit 0
fi
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git commit -am "exolobe $VERSION"
git push origin HEAD
echo "Homebrew の cask を $VERSION に更新しました。" >> "$GITHUB_STEP_SUMMARY"

# Windows 版(ADR-048)。NSIS のインストーラを作り、prepare が作った Release に添付する。
# 署名はしない(SmartScreen の案内は Release の本文と README にある)。
build-windows:
Expand All @@ -234,12 +201,18 @@ jobs:
node-version: 24

# main の CI(test-windows)が作ったキャッシュを読むだけにする。キーは ci.yml と揃える。
# キーは lockfile から版を除いた中身で作る。版上げのたびにキャッシュを外さないため(scripts/version-bump.mjs)。
- name: 依存のキーを求める
id: deps
shell: bash
run: node scripts/version-bump.mjs key >> "$GITHUB_OUTPUT"

- name: node_modules のキャッシュを復元
id: node-modules-cache
uses: actions/cache/restore@v4
with:
path: node_modules
key: node-modules-${{ runner.os }}-${{ runner.arch }}-node24-${{ hashFiles('package-lock.json') }}
key: node-modules-${{ runner.os }}-${{ runner.arch }}-node24-${{ steps.deps.outputs.key }}

- name: 依存関係をインストール
if: steps.node-modules-cache.outputs.cache-hit != 'true'
Expand Down
8 changes: 6 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@ npx vitest run -t "テスト名の一部"
確かめるときは `npm run build:whisper` のビルドを設定でパス指定する(ADR-007 / ADR-026)。
- リリースは Actions の **Bump version**(手動実行)が版上げの PR を作り、マージで `tag-release.yml` が
タグを打って `release.yml` を起動する(手元からの `v*` タグの push でも動く)。GITHUB_TOKEN の push は
他のワークフローを起動しないため、CI と Release は `gh workflow run` で明示的に起動している。
他のワークフローを起動しないため、Release は `gh workflow run` で明示的に起動している。版上げは版しか変えないので
CI を回さない(PR では起動せず、マージ後の main では `ci.yml` の `changes` が `scripts/version-bump.mjs` で見分けて飛ばす)。
node_modules のキャッシュのキーも、版を除いた lockfile から作る。
whisper-cli と node_modules のキャッシュは **main の CI が作り、Release は読むだけ**(タグの実行が
保存したキャッシュは次のタグから見えない)。キーは `ci.yml` と `release.yml` で揃える。Secrets に
`MAC_CERT_P12_BASE64` / `MAC_CERT_PASSWORD`(署名)と `APPLE_ID` /
`APPLE_APP_SPECIFIC_PASSWORD` / `APPLE_TEAM_ID`(公証)が揃えば正式に署名・公証し、
無ければ ad-hoc 署名になる。Windows の NSIS のインストーラは `release.yml` の `build-windows` が作る(署名なし)。
Release は `prepare` が先に作り、`SHA256SUMS.txt` は `checksums` が両方の OS の成果物からまとめて作る。
Release は `prepare` が先に **Draft** で作り、`SHA256SUMS.txt` は `checksums` が両方の OS の成果物からまとめて作る。
成果物を手で確かめてから GitHub の画面で公開すると、`publish-release.yml` が Homebrew の cask を更新する
(Draft の dmg は公開の URL から落とせないので、cask は公開まで進めない。プレリリースでは更新しない)。
手元で作るときは `npm run package:win`。
- `npm run lint` は **oxlint**(`.oxlintrc.json`)。TypeScript 7 が従来の JS コンパイラ
API を公開しなくなり typescript-eslint が動かないため、ESLint ではなく oxlint を使う。
Expand Down
10 changes: 10 additions & 0 deletions scripts/version-bump.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** 比べる前と後のファイルの中身。消えた・増えたファイルは無い側を空文字にする。 */
export interface FileChange {
readonly path: string
readonly before: string
readonly after: string
}

export declare const isVersionOnlyChange: (changes: readonly FileChange[]) => boolean

export declare const dependencyKey: (lockText: string) => string
Loading
Loading