🧱
GitHub Actionsでpyファイルをexe化する(ウイルス誤検知対策も)
背景
とあるソフトウェアを作ったものの、リリース前に毎回ビルド→zip→アップロードするのも怠いのでActionsを使おう!!って。
でも検索してもpyinstallerのブートローダーのビルドを行っている例がなくて。
あれやらないとウイルス判定されるので。
んじゃ書くしかねぇ!!ってことで不慣れながら書いてみた。
できたもの
name: Build Windows EXE
on:
workflow_dispatch:
inputs:
version:
description: 'リリースバージョン (例: v1.0.0)'
required: true
default: 'v1.0.0'
release_notes:
description: 'リリースノート'
required: false
default: '新機能と改善点'
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
# 依存関係をいれる
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flet flet-desktop flet-cli
# pyinstallerのインストール
- name: install Pyinstaller
run: |
git clone https://github.com/pyinstaller/pyinstaller.git
cd pyinstaller/bootloader
python ./waf distclean all
cd ..
pip install -e .
# exeファイルにする
- name: Build EXE
run: |
flet pack .\main.py --name MyApp --onedir --icon .\icon.ico --product-name MyApp -y
# zipに圧縮
- name: zip
run: |
Compress-Archive -Path dist/MyApp/* -DestinationPath dist/MyApp-${{ github.event.inputs.version }}.zip
# アップロード
- name: Upload EXE
uses: actions/upload-artifact@v4
with:
name: MyApp
path: dist/MyApp-${{ github.event.inputs.version }}.zip
# リリースの作成
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.event.inputs.version }}
name: MyApp ${{ github.event.inputs.version }}
body: ${{ github.event.inputs.release_notes }}
draft: true
prerelease: false
files: |
dist/MyApp-${{ github.event.inputs.version }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
これは私の環境の例です。細かいところは書き換えてね。
肝
今回のファイルの肝は
...
- name: install Pyinstaller
run: |
git clone https://github.com/pyinstaller/pyinstaller.git
cd pyinstaller/bootloader
python ./waf distclean all
cd ..
pip install -e .
...
ここです。ブートローダーをリビルドしてpyinstallerをインストールします。
これでウイルス対策ソフトに引っかかりにくくさせます。
使ってみて
とても楽ですね。私はgitの使い方下手っぴなので手動でActionsを実行しているのですが、
楽です。すごく。
一回あたり大体3分程度なので無料枠でも十分収まるでしょう。
それでは!!
Discussion