Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

コード署名する #430

Merged
merged 11 commits into from
Jul 12, 2022
40 changes: 31 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,26 @@ on:
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

env:
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/voicevox_engine
PYTHON_VERSION: "3.8.10"
VOICEVOX_RESOURCE_VERSION: "0.13.0-preview.2"
VOICEVOX_CORE_VERSION: "0.12.2"
VOICEVOX_ENGINE_VERSION:
|- # releaseのときはタグが、それ以外はlatestがバージョン名に
${{ github.event.release.tag_name != '' && github.event.release.tag_name || 'latest' }}
|- # releaseタグ名か、workflow_dispatchでのバージョン名か、latestが入る
${{ github.event.release.tag_name || github.event.inputs.version || 'latest' }}

jobs:
# Build Mac binary (x64 arch only)
Expand Down Expand Up @@ -239,7 +250,7 @@ jobs:
- uses: actions/upload-artifact@v2
# env:
# VERSIONED_ARTIFACT_NAME: |
# ${{ format('{0}-{1}', matrix.artifact_name, (github.event.release.tag_name != '' && github.event.release.tag_name) || github.sha) }}
# ${{ format('{0}-{1}', matrix.artifact_name, (env.VOICEVOX_ENGINE_VERSION != 'latest' && env.VOICEVOX_ENGINE_VERSION) || github.sha) }}
with:
name: ${{ matrix.artifact_name }}
path: build/run.dist/
Expand Down Expand Up @@ -383,12 +394,13 @@ jobs:
- uses: actions/upload-artifact@v2
# env:
# VERSIONED_ARTIFACT_NAME: |
# ${{ format('{0}-{1}', matrix.artifact_name, (github.event.release.tag_name != '' && github.event.release.tag_name) || github.sha) }}
# ${{ format('{0}-{1}', matrix.artifact_name, (env.VOICEVOX_ENGINE_VERSION != 'latest' && env.VOICEVOX_ENGINE_VERSION) || github.sha) }}
with:
name: ${{ matrix.artifact_name }}
path: build/run.dist/

build-windows:
environment: ${{ github.event.inputs.code_signing == 'true' && 'code_signing' }} # コード署名用のenvironment
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
strategy:
matrix:
include:
Expand Down Expand Up @@ -798,6 +810,15 @@ jobs:
# pysoundfile
ln -sf "${{ env.PYTHON_SITE_PACKAGES_DIR }}/_soundfile_data" artifact/

- name: Code signing
if: github.event.inputs.code_signing
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
shell: bash
run: |
bash build_util/codesign.bash "artifact/run.exe"
env:
CERT_BASE64: ${{ secrets.CERT_BASE64 }}
CERT_PASSWORD: ${{ secrets.CERT_PASSWORD }}

# FIXME: versioned name may be useful; but
# actions/download-artifact and dawidd6/download-artifact do not support
# wildcard / forward-matching yet.
Expand All @@ -807,14 +828,14 @@ jobs:
- uses: actions/upload-artifact@v2
# env:
# VERSIONED_ARTIFACT_NAME: |
# ${{ format('{0}-{1}', matrix.artifact_name, (github.event.release.tag_name != '' && github.event.release.tag_name) || github.sha) }}
# ${{ format('{0}-{1}', matrix.artifact_name, (env.VOICEVOX_ENGINE_VERSION != 'latest' && env.VOICEVOX_ENGINE_VERSION) || github.sha) }}
with:
name: ${{ matrix.artifact_name }}
path: |
artifact/

upload-to-release:
if: github.event.release.tag_name != ''
if: (github.event.release.tag_name || github.event.inputs.version) != ''
needs: [build-mac, build-linux, build-windows]
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -854,14 +875,15 @@ jobs:
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref }} # == github.event.release.tag_name
tag: ${{ env.VOICEVOX_ENGINE_VERSION }}
prelease: ${{ github.event.inputs.prerelease }}
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
file_glob: true
file: ${{ matrix.artifact_name }}.7z.*

run-release-test-workflow:
if: github.event.release.tag_name != ''
if: (github.event.release.tag_name || github.event.inputs.version) != ''
needs: [upload-to-release]
uses: ./.github/workflows/release-test.yml
with:
version: ${{ github.event.release.tag_name }}
version: ${{ github.event.release.tag_name || github.event.inputs.version }} # env.VOICEVOX_ENGINE_VERSIONが使えない
repo_url: ${{ format('{0}/{1}', github.server_url, github.repository) }} # このリポジトリのURL
49 changes: 49 additions & 0 deletions build_util/codesign.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# !!! コードサイニング証明書を取り扱うので取り扱い注意 !!!

set -eu

if [ -v "${CERT_BASE64}" ]; then
echo "CERT_BASE64が未定義です"
exit 1
fi
if [ -v "${CERT_PASSWORD}" ]; then
echo "CERT_PASSWORDが未定義です"
exit 1
fi

if [ $# -ne 1 ]; then
echo "引数の数が一致しません"
exit 1
fi
target_file_glob="$1"

# 証明書
CERT_PATH=cert.pfx
echo -n "$CERT_BASE64" | base64 -d - > $CERT_PATH

# 指定ファイルに署名する
function codesign() {
TARGET="$1"
SIGNTOOL=$(find "C:/Program Files (x86)/Windows Kits/10/App Certification Kit" -name "signtool.exe" | sort -V | tail -n 1)
powershell "& '$SIGNTOOL' sign /fd SHA256 /td SHA256 /tr http://timestamp.digicert.com /f $CERT_PATH /p $CERT_PASSWORD '$TARGET'"
}

# 指定ファイルが署名されているか
function is_signed() {
TARGET="$1"
SIGNTOOL=$(find "C:/Program Files (x86)/Windows Kits/10/App Certification Kit" -name "signtool.exe" | sort -V | tail -n 1)
powershell "& '$SIGNTOOL' verify /pa '$TARGET'" || return 1
}

# 署名されていなければ署名
ls $target_file_glob | while read target_file; do
if is_signed "$target_file"; then
echo "署名済み: $target_file"
else
echo "署名: $target_file"
codesign "$target_file"
fi
done

# 証明書を消去
rm $CERT_PATH