Skip to content

Commit

Permalink
Github Actionsでのビルドのupload/download回数を少なくしてビルド時間を短くする (#668)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroshiba authored Apr 23, 2023
1 parent b6eace3 commit 5bce552
Showing 1 changed file with 44 additions and 98 deletions.
142 changes: 44 additions & 98 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ on:
code_signing:
description: "コード署名する"
type: boolean
upload_artifact:
description: "デバッグ用に成果物をartifactにアップロードするか"
type: boolean
default: false

env:
PYTHON_VERSION: "3.11.3"
Expand All @@ -40,7 +44,7 @@ jobs:
: # release タグ名, または workflow_dispatch でのバージョン名, または 'latest'
echo "version_or_latest=${{ github.event.release.tag_name || github.event.inputs.version || 'latest' }}" >> $GITHUB_OUTPUT
build-all:
build-and-upload:
needs: [config]
environment: ${{ github.event.inputs.code_signing == 'true' && 'code_signing' || '' }} # コード署名用のenvironment
strategy:
Expand Down Expand Up @@ -96,22 +100,20 @@ jobs:
id: vars
shell: bash
run: |
echo "artifact_name=voicevox_engine-${{ matrix.target }}-${{ needs.config.outputs.version_or_latest }}-${{ github.sha }}" >> $GITHUB_OUTPUT
echo "package_name=voicevox_engine-${{ matrix.target }}-${{ needs.config.outputs.version }}" >> $GITHUB_OUTPUT
- uses: actions/checkout@v3

- name: Show disk space (debug info)
shell: bash
run: |
df -h
# 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.
# 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: Install GNU sed on macOS
if: startsWith(matrix.os, 'macos-')
shell: bash
run: brew install gnu-sed
run: |
brew install gnu-sed coreutils
echo "/usr/local/opt/gnu-sed/libexec/gnubin" >> $GITHUB_PATH
echo "/usr/local/opt/coreutils/libexec/gnubin" >> $GITHUB_PATH
# ONNX Runtime providersとCUDA周りをリンクするために使う
- name: Install patchelf
Expand Down Expand Up @@ -166,12 +168,6 @@ jobs:
rm -f download/cuda/bin/libcudart.so.*.*.*
fi
- name: Show disk space (debug info)
if: matrix.cuda_version != ''
shell: bash
run: |
df -h
# Download cuDNN
- name: Export cuDNN url to calc hash
if: matrix.cudnn_url != ''
Expand Down Expand Up @@ -246,12 +242,6 @@ jobs:
mv download/zlib/dll_${{ matrix.architecture }}/zlibwapi.dll download/zlib/zlibwapi.dll
rm -r download/zlib/dll_${{ matrix.architecture }}
- name: Show disk space (debug info)
if: matrix.cudnn_url != ''
shell: bash
run: |
df -h
- name: Setup MSVC
if: startsWith(matrix.os, 'windows-')
uses: ilammy/msvc-dev-cmd@v1
Expand Down Expand Up @@ -363,11 +353,6 @@ jobs:
tar xf "download/onnxruntime.tgz" -C "download/onnxruntime" --strip-components 1
rm download/onnxruntime.tgz
- name: Show disk space (debug info)
shell: bash
run: |
df -h
# Download VOICEVOX RESOURCE
- name: Prepare VOICEVOX RESOURCE cache
uses: actions/cache@v3
Expand Down Expand Up @@ -436,11 +421,6 @@ jobs:
# FIXME: VOICEVOX (editor) cannot build without licenses.json
cp engine_manifest_assets/dependency_licenses.json licenses.json
- name: Show disk space (debug info)
shell: bash
run: |
df -h
- name: Build run.py with PyInstaller
shell: bash
run: |
Expand All @@ -450,30 +430,22 @@ jobs:
mv -f engine_manifest.json.tmp engine_manifest.json
# Replace version & specify dynamic libraries
if [[ ${{ matrix.os }} == macos-* ]]; then
gsed -i "s/__version__ = \"latest\"/__version__ = \"${{ needs.config.outputs.version_or_latest }}\"/" voicevox_engine/__init__.py
sed -i "s/__version__ = \"latest\"/__version__ = \"${{ needs.config.outputs.version_or_latest }}\"/" voicevox_engine/__init__.py
if [[ ${{ matrix.os }} == windows-* ]]; then
LIBCORE_PATH=download/core/voicevox_core.dll
LIBONNXRUNTIME_PATH=download/onnxruntime/lib/onnxruntime.dll
elif [[ ${{ matrix.os }} == macos-* ]]; then
LIBCORE_PATH=download/core/libvoicevox_core.dylib
LIBONNXRUNTIME_PATH=download/onnxruntime/lib/libonnxruntime.dylib
else
sed -i "s/__version__ = \"latest\"/__version__ = \"${{ needs.config.outputs.version_or_latest }}\"/" voicevox_engine/__init__.py
if [[ ${{ matrix.os }} == windows-* ]]; then
LIBCORE_PATH=download/core/voicevox_core.dll
LIBONNXRUNTIME_PATH=download/onnxruntime/lib/onnxruntime.dll
else
LIBCORE_PATH=download/core/libvoicevox_core.so
LIBONNXRUNTIME_PATH=download/onnxruntime/lib/libonnxruntime.so
fi
LIBCORE_PATH=download/core/libvoicevox_core.so
LIBONNXRUNTIME_PATH=download/onnxruntime/lib/libonnxruntime.so
fi
LIBCORE_PATH="$LIBCORE_PATH" \
LIBONNXRUNTIME_PATH="$LIBONNXRUNTIME_PATH" \
pyinstaller --noconfirm run.spec
- name: Show disk space (debug info)
shell: bash
run: |
df -h
- name: Create artifact directory with symlink
if: startsWith(matrix.os, 'windows-')
shell: bash
Expand Down Expand Up @@ -546,56 +518,16 @@ jobs:
CERT_BASE64: ${{ secrets.CERT_BASE64 }}
CERT_PASSWORD: ${{ secrets.CERT_PASSWORD }}

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ${{ steps.vars.outputs.artifact_name }}
path: dist/run/

upload-to-release:
if: needs.config.outputs.version != ''
needs: [config, build-all]
runs-on: ubuntu-latest
strategy:
matrix:
target:
- macos-x64
- linux-cpu
- linux-nvidia
- windows-cpu
- windows-directml
- windows-nvidia
steps:
- name: declare variables
id: vars
- name: Rearchive and split artifact
shell: bash
run: |
echo "package_name=voicevox_engine-${{ matrix.target }}-${{ needs.config.outputs.version }}" >> $GITHUB_OUTPUT
: # this is exactly same as `steps.vars.outputs.artifact_name` in `build-all` job,
: # but since we cannot get the job outputs of matrix builds correctly, we need to redefine here.
echo "artifact_name=voicevox_engine-${{ matrix.target }}-${{ needs.config.outputs.version_or_latest }}-${{ github.sha }}" >> $GITHUB_OUTPUT
- uses: actions/checkout@v3

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
p7zip-full
mv dist/run/ "${{ matrix.target }}/"
- name: Download and extract artifact
uses: actions/download-artifact@v3
with:
name: ${{ steps.vars.outputs.artifact_name }}
path: ${{ matrix.target }}/

- name: Rearchive and split artifact
run: |
# Compress to artifact.7z.001, artifact.7z.002, ...
7z -r -v1900m a "${{ steps.vars.outputs.package_name }}.7z" "${{ matrix.target }}/"
# Compress to artifact.001.vvppp,artifact.002.vvppp, ...
(cd "${{ matrix.target }}" && zip -r - . > ../compressed.zip)
(cd "${{ matrix.target }}" && 7z -r a "../compressed.zip")
split -b 1900M --numeric-suffixes=1 -a 3 --additional-suffix .vvppp ./compressed.zip ./${{ steps.vars.outputs.package_name }}.
# Rename to artifact.vvpp if there are only artifact.001.vvppp
Expand All @@ -609,21 +541,35 @@ jobs:
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: Upload splitted archives to Release assets
uses: softprops/action-gh-release@v1
- name: Upload to artifact
if: github.event.inputs.upload_artifact
uses: actions/upload-artifact@v3
with:
prerelease: ${{ github.event.inputs.prerelease }}
tag_name: ${{ needs.config.outputs.version }}
files: |-
name: ${{ steps.vars.outputs.package_name }}
path: |
${{ steps.vars.outputs.package_name }}.7z.*
${{ steps.vars.outputs.package_name }}.vvpp
${{ steps.vars.outputs.package_name }}*.vvppp
${{ steps.vars.outputs.package_name }}.vvpp.txt
target_commitish: ${{ github.sha }}
- name: Upload 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.*,
${{ steps.vars.outputs.package_name }}.vvpp,
${{ steps.vars.outputs.package_name }}*.vvppp,
${{ steps.vars.outputs.package_name }}.vvpp.txt
commit: ${{ github.sha }}

run-release-test-workflow:
if: needs.config.outputs.version != ''
needs: [config, upload-to-release]
needs: [config, build-and-upload]
uses: ./.github/workflows/release-test.yml
with:
version: ${{ needs.config.outputs.version }}
Expand Down

0 comments on commit 5bce552

Please sign in to comment.