Skip to content

Build

Build #123

name: Build
on:
push:
branches:
- master
release:
types:
- created
workflow_dispatch:
inputs:
version:
description: "バージョン情報 (A.BB.C / A.BB.C-preview.D)"
required: true
prerelease:
description: "プレリリースかどうか"
type: boolean
default: true
code_signing:
description: "コード署名する"
type: boolean
default: false
upload_artifact:
description: "デバッグ用に成果物を artifact にアップロードするか"
type: boolean
default: false
env:
PYTHON_VERSION: "3.11.9"
defaults:
run:
shell: bash
jobs:
config: # 全 jobs で利用する定数の定義. `env` が利用できないコンテキストでも利用できる.
runs-on: ubuntu-latest
outputs:
version: ${{ steps.vars.outputs.version }}
version_or_latest: ${{ steps.vars.outputs.version_or_latest }}
steps:
- name: <Setup> Declare variables
id: vars
run: |
: # release タグ名, または workflow_dispatch でのバージョン名. リリースでない (push event) 場合は空文字列
echo "version=${{ github.event.release.tag_name || github.event.inputs.version }}" >> "$GITHUB_OUTPUT"
: # release タグ名, または workflow_dispatch でのバージョン名, または 'latest'
echo "version_or_latest=${{ github.event.release.tag_name || github.event.inputs.version || 'latest' }}" >> "$GITHUB_OUTPUT"
build-and-upload:
needs: [config]
environment: ${{ github.event.inputs.code_signing == 'true' && 'code_signing' || '' }} # コード署名用のenvironment
strategy:
matrix:
include:
# Windows x64
- os: windows-2022
architecture: "x64"
target: Windows-x64
# macOS x64 (Intel Mac)
- os: macos-13
architecture: "x64"
target: macOS-x64
# macOS arm64 (Apple Silicon Mac)
- os: macos-14
architecture: "arm64"
target: macOS-arm64
# Linux x64
- os: ubuntu-20.04
architecture: "x64"
target: Linux-x64
runs-on: ${{ matrix.os }}
permissions:
contents: write
env:
# GNUコマンド
sed: ${{ startsWith(matrix.os, 'macos-') && 'gsed' || 'sed' }}
split: ${{ startsWith(matrix.os, 'macos-') && 'gsplit' || 'split' }}
steps:
- name: <Setup> Declare variables
id: vars
run: echo "package_name=AivisSpeech-Engine-${{ matrix.target }}-${{ needs.config.outputs.version }}" >> "$GITHUB_OUTPUT"
- name: <Setup> Check out the repository
uses: actions/checkout@v4
# NOTE: The default 'sed' and 'split' of macOS is BSD 'sed' and 'split'.
# There is a difference in specification between BSD 'sed' and 'split' and GNU 'sed' and 'split',
# so you need to install GNU 'sed' and 'split'.
- name: <Setup> Install dependencies (macOS)
if: startsWith(matrix.os, 'macos-')
run: brew install gnu-sed coreutils
- name: <Setup> Set up MSVC
if: startsWith(matrix.os, 'windows-')
uses: ilammy/msvc-dev-cmd@v1
- name: <Setup> Prepare Python Runtime / Python Dependencies
uses: ./.github/actions/prepare_python
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: ${{ matrix.architecture }}
- name: <Setup> Install Poetry
run: python -m pip install poetry
- name: <Setup> Cache Poetry
uses: actions/cache@v4
with:
path: ~/.cache/pypoetry
key: ${{ runner.os }}-${{ runner.arch }}-poetry-${{ hashFiles('**/poetry.lock') }}
- name: <Setup> Install Python dependencies
run: poetry install --with=build
- name: <Setup> Prepare custom PyInstaller
if: startsWith(matrix.os, 'windows-')
run: ./tools/modify_pyinstaller.bash
- name: <Setup> Create download directory
run: mkdir -p download/
# Build
- name: <Build> Generate licenses.json
run: poetry run task update-licenses
- name: <Build> Build AivisSpeech Engine run.py
run: |
set -eux
jq '.version = "${{ needs.config.outputs.version_or_latest }}"' engine_manifest.json > engine_manifest.json.tmp
mv -f engine_manifest.json.tmp engine_manifest.json
# Replace version & specify dynamic libraries
$sed -i "s/__version__ = \"latest\"/__version__ = \"${{ needs.config.outputs.version_or_latest }}\"/" voicevox_engine/__init__.py
poetry run task build
- name: <Build> Code signing
if: github.event.inputs.code_signing == 'true' && startsWith(matrix.os, 'windows-')
run: bash tools/codesign.bash "dist/run/run.exe"
env:
ESIGNERCKA_USERNAME: ${{ secrets.ESIGNERCKA_USERNAME }}
ESIGNERCKA_PASSWORD: ${{ secrets.ESIGNERCKA_PASSWORD }}
ESIGNERCKA_TOTP_SECRET: ${{ secrets.ESIGNERCKA_TOTP_SECRET }}
- name: <Build> Rename artifact directory to archive
run: mv dist/run/ "${{ matrix.target }}/"
# 7z archives
- name: <Build> Create 7z archives
run: |
# Compress to artifact.7z.001, artifact.7z.002, ...
7z -r -v1900m a "${{ steps.vars.outputs.package_name }}.7z" "${{ matrix.target }}/"
# Output splitted archive list
ls ${{ steps.vars.outputs.package_name }}.7z.* > archives_7z.txt
mv archives_7z.txt "${{ steps.vars.outputs.package_name }}.7z.txt"
- name: <Deploy> Upload 7z archives to artifact
if: github.event.inputs.upload_artifact == 'true'
uses: actions/upload-artifact@v4
with:
name: ${{ steps.vars.outputs.package_name }}-7z
path: |
${{ steps.vars.outputs.package_name }}.7z.*
- name: <Deploy> Upload 7z archives to Release assets
if: needs.config.outputs.version != ''
uses: ncipollo/release-action@v1
with:
allowUpdates: true
prerelease: ${{ github.event.inputs.prerelease }}
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ needs.config.outputs.version }}
artifacts: >
${{ steps.vars.outputs.package_name }}.7z.*
commit: ${{ github.sha }}
- name: <Setup> Clean 7z archives to reduce disk usage
run: rm -f ${{ steps.vars.outputs.package_name }}.7z.*
# VVPP archives
# - name: <Build> Create VVPP archives
# run: |
# # Compress to compressed.zip.001, compressed.zip.002, ...
# # NOTE: 1000th archive will be "compressed.zip.1000" after "compressed.zip.999". This is unconsidered as an extreme case.
# (cd "${{ matrix.target }}" && 7z -r -v1900M a "../compressed.zip")
# # Rename to artifact.001.vvppp, artifact.002.vvppp, ...
# for FILE in compressed.zip.*; do
# NUMBER=${FILE##*.} # 001
# mv "${FILE}" "${{ steps.vars.outputs.package_name }}.${NUMBER}.vvppp"
# done
# # Rename to artifact.vvpp if there are only artifact.001.vvppp
# if [ "$(find ${{ steps.vars.outputs.package_name }}.*.vvppp -maxdepth 1 | wc -l)" -eq 1 ]; then
# mv ${{ steps.vars.outputs.package_name }}.001.vvppp ${{ steps.vars.outputs.package_name }}.vvpp
# fi
# # Output splitted archive list
# ls ${{ steps.vars.outputs.package_name }}*.vvppp ${{ steps.vars.outputs.package_name }}.vvpp > archives_vvpp.txt || true
# mv archives_vvpp.txt "${{ steps.vars.outputs.package_name }}.vvpp.txt"
# - name: <Deploy> Upload VVPP archives to artifact
# if: github.event.inputs.upload_artifact == 'true'
# uses: actions/upload-artifact@v4
# with:
# name: ${{ steps.vars.outputs.package_name }}-vvpp
# path: |
# ${{ steps.vars.outputs.package_name }}.vvpp
# ${{ steps.vars.outputs.package_name }}*.vvppp
# ${{ steps.vars.outputs.package_name }}.vvpp.txt
# - name: <Deploy> Upload VVPP archives to Release assets
# if: needs.config.outputs.version != ''
# uses: ncipollo/release-action@v1
# with:
# allowUpdates: true
# prerelease: ${{ github.event.inputs.prerelease }}
# token: ${{ secrets.GITHUB_TOKEN }}
# tag: ${{ needs.config.outputs.version }}
# artifacts: >
# ${{ steps.vars.outputs.package_name }}.vvpp,
# ${{ steps.vars.outputs.package_name }}*.vvppp,
# ${{ steps.vars.outputs.package_name }}.vvpp.txt
# commit: ${{ github.sha }}
- name: <Deploy> Merge artifacts
if: github.event.inputs.upload_artifact == 'true'
uses: actions/upload-artifact/merge@v4
with:
name: ${{ steps.vars.outputs.package_name }}
pattern: ${{ steps.vars.outputs.package_name }}-*
delete-merged: true
update-tag-to-current-commit:
if: needs.config.outputs.version != ''
needs: [config, build-and-upload]
runs-on: ubuntu-latest
steps:
- name: <Setup> Check out the repository
uses: actions/checkout@v4
- name: <Deploy> Change tag to this commit for refreshing the release # c.f. voicevox_engine#854
run: |
git tag -f ${{ needs.config.outputs.version }}
git push -f --tag
run-release-test-workflow:
if: needs.config.outputs.version != ''
needs: [config, build-and-upload]
uses: ./.github/workflows/test-engine-package.yml
with:
version: ${{ needs.config.outputs.version }}
repo_url: ${{ format('{0}/{1}', github.server_url, github.repository) }} # このリポジトリのURL