Skip to content

Commit

Permalink
macOS用アプリケーションとdmgファイル、zipファイルの自動ビルド (#570)
Browse files Browse the repository at this point in the history
* add build steps for macOS to build-noengine-prepackage

* run build.yml on every push (for test-build)

* sedコマンドに与える正規表現を修正

* 大きいサイズのアイコンをmacOS向けに用意

512x512より小さいサイズのアイコンをmacOSビルドで使うと
electron-builderがエラーを出力するため

* fix artifact_path of macOS

* add build steps for macOS to build-engine-prepackage

* fix app.asar path of macOS

* change each version of npm and electron-builder for macOS

* npmのダウングレードのタイミングを変更

* npmとelectron-builderのバージョン変更をコメントアウト

* clear cache for test

* 実行権限を付与するファイルを追加

* make the distribution for macOS

* fix quote

* macos_executable_nameの設定し忘れを修正

* trivial change

* dmgの名前にバージョン番号を追加

* キャッシュの設定をもとに戻す

* build-engine-prepackageにおいてmacOS向けバイナリへの実行権限付与をしない

Linux版と異なり、tar.gzファイルを配布しないため

* run build.yml on main push

* macOSにおいてBSD sedではなくGNU sedを使用

* vue.config.jsのmacOS向けの設定についてコメントを追加

* trivial change

* Merge licenses.jsonのstepを全OSで共通化

* run build.yml on every push (for test)

* add shell option setting for alias

* aliasがうまく働かないのでsedのコマンド名の設定に変数を使う

* trivial change

* macOS向けにzipを作成

* mac向けzipの名前を変更

* macOS向けzipをReleasesのassetsにアップロード

* fix comment

* run build.yml on main push

* fix comment
  • Loading branch information
PickledChair authored Dec 12, 2021
1 parent c257aea commit c27970a
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 11 deletions.
181 changes: 170 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,46 +28,86 @@ jobs:
- linux-noengine-cpu-prepackage
- windows-noengine-prepackage
- windows-noengine-cpu-prepackage
- macos-noengine-cpu-prepackage
include:
# Linux NVIDIA GPU
- artifact_name: linux-noengine-prepackage
artifact_path: dist_electron/linux-unpacked
package_name: voicevox
linux_artifact_name: 'VOICEVOX.${ext}'
linux_executable_name: voicevox
sed_name: sed
os: ubuntu-18.04
# Linux CPU
- artifact_name: linux-noengine-cpu-prepackage
artifact_path: dist_electron/linux-unpacked
package_name: voicevox-cpu
linux_artifact_name: 'VOICEVOX.${ext}'
linux_executable_name: voicevox
sed_name: sed
os: ubuntu-18.04
# Windows NVIDIA GPU
- artifact_name: windows-noengine-prepackage
artifact_path: dist_electron/win-unpacked
package_name: voicevox
nsis_web_artifact_name: 'VOICEVOX Web Setup ${version}.${ext}'
sed_name: sed
os: windows-2019
# Windows CPU
- artifact_name: windows-noengine-cpu-prepackage
artifact_path: dist_electron/win-unpacked
package_name: voicevox-cpu
nsis_web_artifact_name: 'VOICEVOX-CPU Web Setup ${version}.${ext}'
sed_name: sed
os: windows-2019
# macOS CPU
- artifact_name: macos-noengine-cpu-prepackage
artifact_path: dist_electron/mac
package_name: voicevox-cpu
macos_artifact_name: 'VOICEVOX.${ext}'
sed_name: gsed
os: macos-11

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@master

# NOTE: The default sed of macOS is BSD sed.
# There is a difference in specification between BSD sed and GNU sed,
# so you need to install GNU sed.
- name: Install GNU sed on macOS
if: startsWith(matrix.os, 'macos-')
shell: bash
run: |
brew install gnu-sed
# Rename executable file
- name: Replace package name
shell: bash
run: |
# GPU: "name": "voicevox" => "name": "voicevox"
# CPU: "name": "voicevox" => "name": "voicevox-cpu"
sed -i 's/"name": "voicevox"/"name": "${{ matrix.package_name }}"/' package.json
# sed -i 's/productName: "VOICEVOX"/productName: "${{ matrix.product_name }}"/' vue.config.js
"${{ matrix.sed_name }}" -i 's/"name": "voicevox"/"name": "${{ matrix.package_name }}"/' package.json
# "${{ matrix.sed_name }}" -i 's/productName: "VOICEVOX"/productName: "${{ matrix.product_name }}"/' vue.config.js
# NOTE: The extraFiles of electron-builder uses VOICEVOX.app/Contents/ as the file copy destination.
# However, since the executable file is located in VOICEVOX.app/Contents/MacOS/,
# it is inappropriate to copy the extraFiles to the VOICEVOX.app/Contents/ directory.
# Fix it so that it is copied to the VOICEVOX.app/Contents/MacOS/ directory.
# cf. https://k-hyoda.hatenablog.com/entry/2021/10/23/000349#%E8%BF%BD%E5%8A%A0%E5%B1%95%E9%96%8B%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E5%85%88%E3%81%AE%E8%A8%AD%E5%AE%9A
- name: Replace the extraFiles setting in vue.config.js for macOS
if: startsWith(matrix.os, 'macos-')
shell: bash
run: |
"${{ matrix.sed_name }}" -i 's/from: "build\/README.txt", to: "README.txt"/from: "build\/README.txt", to: "MacOS\/README.txt"/' vue.config.js
"${{ matrix.sed_name }}" -i 's/from: ".env.production", to: ".env"/from: ".env.production", to: "MacOS\/.env"/' vue.config.js
# In order to replace two lines with sed, we need to replace LF with \n and treat it as one line. Finally, undo it.
# cf. https://deep.tacoskingdom.com/blog/15
str_config=$(cat vue.config.js)
str_config_2=${str_config//$'\n'/\\n}
echo $str_config_2 | "${{ matrix.sed_name }}" -e 's/from: VOICEVOX_ENGINE_DIR,\\n[ ]*to: ""/from: VOICEVOX_ENGINE_DIR, to: "MacOS\/"/' -e s/'\\n'/\\$'\n'/g > vue.config.js
cat vue.config.js
- name: Set output Node version
id: node-version
Expand Down Expand Up @@ -112,8 +152,8 @@ jobs:
run: |
df -h
- name: Overwrite .env.production for Linux
if: startsWith(matrix.os, 'ubuntu-')
- name: Overwrite .env.production for Linux and macOS
if: startsWith(matrix.os, 'ubuntu-') || startsWith(matrix.os, 'macos-')
shell: bash
run: |
echo "ENGINE_PATH=./run" > .env.production
Expand Down Expand Up @@ -186,6 +226,7 @@ jobs:
NSIS_WEB_ARTIFACT_NAME: ${{ matrix.nsis_web_artifact_name }}
LINUX_ARTIFACT_NAME: ${{ matrix.linux_artifact_name }}
LINUX_EXECUTABLE_NAME: ${{ matrix.linux_executable_name }}
MACOS_ARTIFACT_NAME: ${{ matrix.macos_artifact_name }}
run: npm run electron:build_pnever -- --dir

- name: Upload NoEngine Prepackage
Expand Down Expand Up @@ -215,27 +256,39 @@ jobs:
- linux-cpu-prepackage
- windows-nvidia-prepackage
- windows-cpu-prepackage
- macos-cpu-prepackage
include:
# Linux NVIDIA GPU
- artifact_name: linux-nvidia-prepackage
noengine_artifact_name: linux-noengine-prepackage
voicevox_engine_asset_name: linux-nvidia
linux_executable_name: voicevox
targz_name: VOICEVOX
app_asar_dir: prepackage/resources
# Linux CPU
- artifact_name: linux-cpu-prepackage
noengine_artifact_name: linux-noengine-cpu-prepackage
voicevox_engine_asset_name: linux-cpu
linux_executable_name: voicevox
targz_name: VOICEVOX-CPU
app_asar_dir: prepackage/resources
# Windows NVIDIA GPU
- artifact_name: windows-nvidia-prepackage
noengine_artifact_name: windows-noengine-prepackage
voicevox_engine_asset_name: windows-nvidia
app_asar_dir: prepackage/resources
# Windows CPU
- artifact_name: windows-cpu-prepackage
noengine_artifact_name: windows-noengine-cpu-prepackage
voicevox_engine_asset_name: windows-cpu
app_asar_dir: prepackage/resources
# macOS CPU
- artifact_name: macos-cpu-prepackage
noengine_artifact_name: macos-noengine-cpu-prepackage
voicevox_engine_asset_name: macos-x64
macos_executable_name: VOICEVOX
zip_name: voicevox-cpu-macos-x64
app_asar_dir: prepackage/VOICEVOX.app/Contents/Resources

runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -326,22 +379,30 @@ jobs:
shell: bash
run: |
# Unpack asar
asar extract prepackage/resources/app.asar prepackage/resources/app
rm prepackage/resources/app.asar
asar extract "${{ matrix.app_asar_dir }}/app.asar" "${{ matrix.app_asar_dir }}/app"
rm "${{ matrix.app_asar_dir }}/app.asar"
mv voicevox_engine/voicevox_engine/licenses.json engine_licenses.json
npm run license:merge -- -o prepackage/resources/app/licenses.json -i engine_licenses.json -i prepackage/resources/app/licenses.json
npm run license:merge -- -o "${{ matrix.app_asar_dir }}/app/licenses.json" -i engine_licenses.json -i "${{ matrix.app_asar_dir }}/app/licenses.json"
# Repack asar
asar pack prepackage/resources/app prepackage/resources/app.asar
rm -rf prepackage/resources/app
asar pack "${{ matrix.app_asar_dir }}/app" "${{ matrix.app_asar_dir }}/app.asar"
rm -rf "${{ matrix.app_asar_dir }}/app"
- name: Merge VOICEVOX ENGINE into prepackage/
if: startsWith(matrix.artifact_name, 'windows-') || startsWith(matrix.artifact_name, 'linux-')
shell: bash
run: |
mv voicevox_engine/voicevox_engine/* prepackage/
rm -rf voicevox_engine
- name: Merge VOICEVOX ENGINE into prepackage/VOICEVOX.app/Contents/MacOS/
if: startsWith(matrix.artifact_name, 'macos-')
shell: bash
run: |
mv voicevox_engine/voicevox_engine/* prepackage/VOICEVOX.app/Contents/MacOS/
rm -rf voicevox_engine
- name: Show disk space (debug info)
shell: bash
run: |
Expand All @@ -361,6 +422,17 @@ jobs:
chmod +x "prepackage/${{ matrix.linux_executable_name }}"
chmod +x "prepackage/run"
- name: Recover file permissions for macOS build
if: startsWith(matrix.artifact_name, 'macos-') # macOS
shell: bash
run: |
chmod +x "prepackage/VOICEVOX.app/Contents/MacOS/${{ matrix.macos_executable_name }}"
chmod +x "prepackage/VOICEVOX.app/Contents/MacOS/run"
chmod +x "prepackage/VOICEVOX.app/Contents/Frameworks/VOICEVOX Helper (GPU).app/Contents/MacOS/VOICEVOX Helper (GPU)"
chmod +x "prepackage/VOICEVOX.app/Contents/Frameworks/VOICEVOX Helper (Plugin).app/Contents/MacOS/VOICEVOX Helper (Plugin)"
chmod +x "prepackage/VOICEVOX.app/Contents/Frameworks/VOICEVOX Helper (Renderer).app/Contents/MacOS/VOICEVOX Helper (Renderer)"
chmod +x "prepackage/VOICEVOX.app/Contents/Frameworks/VOICEVOX Helper.app/Contents/MacOS/VOICEVOX Helper"
- name: Set BUILD_IDENTIFIER env var
if: startsWith(matrix.artifact_name, 'linux-') # linux
shell: bash
Expand Down Expand Up @@ -400,6 +472,20 @@ jobs:
name: ${{ matrix.artifact_name }}-targz
path: "${{ matrix.targz_name }}-${{ env.BUILD_IDENTIFIER }}.tar.gz"

- name: Create macOS zip
if: startsWith(matrix.artifact_name, 'macos-')
shell: bash
run: |
mv prepackage VOICEVOX
zip "${{ matrix.zip_name }}.zip" -r VOICEVOX
- name: Upload macOS zip artifact
if: startsWith(matrix.artifact_name, 'macos-')
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.artifact_name }}-zip
path: "${{ matrix.zip_name }}.zip"


build-distributable:
if: github.event.release.tag_name != '' # If release
Expand All @@ -417,38 +503,60 @@ jobs:
- linux-cpu-appimage
- windows-nvidia-nsis-web
- windows-cpu-nsis-web
- macos-cpu-dmg
include:
# Linux NVIDIA GPU
- artifact_name: linux-nvidia-appimage
engine_artifact_name: linux-nvidia-prepackage
package_name: voicevox
linux_artifact_name: 'VOICEVOX.${ext}'
linux_executable_name: voicevox
sed_name: sed
os: ubuntu-18.04
# Linux CPU
- artifact_name: linux-cpu-appimage
engine_artifact_name: linux-cpu-prepackage
package_name: voicevox-cpu
linux_artifact_name: 'VOICEVOX.${ext}'
linux_executable_name: voicevox
sed_name: sed
os: ubuntu-18.04
# Windows NVIDIA GPU
- artifact_name: windows-nvidia-nsis-web
engine_artifact_name: windows-nvidia-prepackage
package_name: voicevox
nsis_web_artifact_name: 'VOICEVOX Web Setup ${version}.${ext}'
sed_name: sed
os: windows-2019
# Windows CPU
- artifact_name: windows-cpu-nsis-web
engine_artifact_name: windows-cpu-prepackage
package_name: voicevox-cpu
nsis_web_artifact_name: 'VOICEVOX-CPU Web Setup ${version}.${ext}'
sed_name: sed
os: windows-2019
# macOS CPU
- artifact_name: macos-cpu-dmg
engine_artifact_name: macos-cpu-prepackage
package_name: voicevox-cpu
macos_artifact_name: 'VOICEVOX ${version}.${ext}'
macos_executable_name: VOICEVOX
sed_name: gsed
os: macos-11

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@master

# NOTE: The default sed of macOS is BSD sed.
# There is a difference in specification between BSD sed and GNU sed,
# so you need to install GNU sed.
- name: Install GNU sed on macOS
if: startsWith(matrix.os, 'macos-')
shell: bash
run: |
brew install gnu-sed
# NOTE: If the CPU/GPU builds have the same package name,
# the NSIS installers and the 7z files have duplicate names.
# For Linux, If they have the same product name,
Expand All @@ -460,8 +568,8 @@ jobs:
run: |
# GPU: "name": "voicevox" => "name": "voicevox"
# CPU: "name": "voicevox" => "name": "voicevox-cpu"
sed -i 's/"name": "voicevox"/"name": "${{ matrix.package_name }}"/' package.json
# sed -i 's/productName: "VOICEVOX"/productName: "${{ matrix.product_name }}"/' vue.config.js
"${{ matrix.sed_name }}" -i 's/"name": "voicevox"/"name": "${{ matrix.package_name }}"/' package.json
# "${{ matrix.sed_name }}" -i 's/productName: "VOICEVOX"/productName: "${{ matrix.product_name }}"/' vue.config.js
- name: Download and extract engine-prepackage artifact
uses: actions/download-artifact@v2
Expand All @@ -476,6 +584,17 @@ jobs:
chmod +x "prepackage/${{ matrix.linux_executable_name }}"
chmod +x "prepackage/run"
- name: Recover file permissions for macOS build
if: endsWith(matrix.artifact_name, '-dmg') # macOS
shell: bash
run: |
chmod +x "prepackage/VOICEVOX.app/Contents/MacOS/${{ matrix.macos_executable_name }}"
chmod +x "prepackage/VOICEVOX.app/Contents/MacOS/run"
chmod +x "prepackage/VOICEVOX.app/Contents/Frameworks/VOICEVOX Helper (GPU).app/Contents/MacOS/VOICEVOX Helper (GPU)"
chmod +x "prepackage/VOICEVOX.app/Contents/Frameworks/VOICEVOX Helper (Plugin).app/Contents/MacOS/VOICEVOX Helper (Plugin)"
chmod +x "prepackage/VOICEVOX.app/Contents/Frameworks/VOICEVOX Helper (Renderer).app/Contents/MacOS/VOICEVOX Helper (Renderer)"
chmod +x "prepackage/VOICEVOX.app/Contents/Frameworks/VOICEVOX Helper.app/Contents/MacOS/VOICEVOX Helper"
- name: Show disk space (debug info)
shell: bash
run: |
Expand Down Expand Up @@ -526,13 +645,21 @@ jobs:
# NOTE: prepackage can be removed before splitting nsis-web archive
- name: Build Electron
if: endsWith(matrix.artifact_name, '-nsis-web') || endsWith(matrix.artifact_name, '-appimage') # windows and linux
shell: bash
env:
NSIS_WEB_ARTIFACT_NAME: ${{ matrix.nsis_web_artifact_name }}
LINUX_ARTIFACT_NAME: ${{ matrix.linux_artifact_name }}
LINUX_EXECUTABLE_NAME: ${{ matrix.linux_executable_name }}
run: npm run electron:build_pnever -- --prepackaged "prepackage/"

- name: Build Electron (for macOS)
if: endsWith(matrix.artifact_name, '-dmg') # macOS
shell: bash
env:
MACOS_ARTIFACT_NAME: ${{ matrix.macos_artifact_name }}
run: npm run electron:build_pnever -- --prepackaged "prepackage/VOICEVOX.app"

- name: Show disk space (debug info)
shell: bash
run: |
Expand All @@ -546,6 +673,14 @@ jobs:
path: |
dist_electron/*.AppImage
- name: Upload macOS dmg artifact
if: endsWith(matrix.artifact_name, '-dmg')
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.artifact_name }}
path: |
dist_electron/*.dmg
- name: Create Windows NSIS Web artifact directory
if: endsWith(matrix.artifact_name, '-nsis-web')
shell: bash
Expand Down Expand Up @@ -586,13 +721,17 @@ jobs:
- linux-cpu-appimage
- windows-nvidia-nsis-web
- windows-cpu-nsis-web
- macos-cpu-dmg
- macos-cpu-prepackage-zip
include:
- artifact_name: linux-nvidia-appimage
appimage_7z_name: VOICEVOX.AppImage
- artifact_name: linux-cpu-appimage
appimage_7z_name: VOICEVOX-CPU.AppImage
- artifact_name: windows-nvidia-nsis-web
- artifact_name: windows-cpu-nsis-web
- artifact_name: macos-cpu-dmg
- artifact_name: macos-cpu-prepackage-zip

runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -680,3 +819,23 @@ jobs:
tag: ${{ github.ref }} # == github.event.release.tag_name
file_glob: true
file: artifact/*.exe

# macOS dmg
- name: Upload macOS dmg to Release assets
if: endsWith(matrix.artifact_name, '-dmg')
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref }} # == github.event.release.tag_name
file_glob: true
file: artifact/*.dmg

# macOS zip
- name: Upload macOS zip to Release assets
if: startsWith(matrix.artifact_name, 'macos-') && endsWith(matrix.artifact_name, '-zip')
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref }} # == github.event.release.tag_name
file_glob: true
file: artifact/*.zip
Binary file added public/icon-mac.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c27970a

Please sign in to comment.