Build EXE & Create Release #19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build EXE & Create Release | |
on: | |
workflow_dispatch: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: windows-latest | |
steps: | |
# ۱. Checkout Repository | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
# ۲. نصب Python 3.11 | |
- name: Set up Python 3.11 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.11' | |
# ۳. نصب وابستگیها | |
- name: Install dependencies | |
run: | | |
pip install -r requirements.txt | |
pip install pyinstaller | |
# ۴. خواندن متغیر VERSION از main.py | |
- name: Extract Version | |
id: get_version | |
run: | | |
version=$(grep -oP 'VERSION\s*=\s*"\K[^"]+' main.py) | |
echo "Detected version: $version" | |
echo "version=$version" >> $GITHUB_ENV | |
# ۵. بررسی مقدار `version` قبل از ذخیره | |
- name: Debug extracted version | |
run: | | |
echo "Extracted version: ${{ env.version }}" | |
if [ -z "${{ env.version }}" ]; then | |
echo "No version detected. Exiting." | |
exit 1 | |
fi | |
# ۶. ذخیره `version.txt` به عنوان artifact | |
- name: Save version to file | |
run: | | |
echo "${{ env.version }}" > version.txt | |
# ۷. ذخیره `version.txt` به عنوان artifact | |
- name: Upload version as artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: version | |
path: ./version.txt | |
# ۸. ساخت فایل EXE با PyInstaller | |
- name: Build with PyInstaller | |
run: | | |
pyinstaller --noconfirm --onefile --windowed --icon "./assets/icon.ico" \ | |
--name "PhotoSlicer-v${{ env.version }}" \ | |
--add-data "engine.py;." \ | |
--add-data "./assets;assets/" \ | |
"./main.py" | |
# ۹. ذخیره EXE به Artifact | |
- name: Upload Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: photo_slicer_build | |
path: ./dist/ | |
release: | |
needs: build | |
runs-on: windows-latest | |
steps: | |
# ۰. دانلود `version.txt` از Artifact | |
- name: Download version artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: version | |
path: ./ | |
# ۰.۵ خواندن متغیر version از فایل | |
- name: Read version from file | |
id: read_version | |
run: | | |
version=$(cat version.txt) | |
echo "Version read from file: $version" | |
echo "version=$version" >> $GITHUB_ENV | |
# ۱. ساخت Release در GitHub | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
with: | |
tag_name: v${{ env.version }} | |
release_name: Release v${{ env.version }} | |
draft: false | |
prerelease: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# ۲. دانلود EXE از Artifact | |
- name: Download build artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: photo_slicer_build | |
path: ./dist/ | |
# ۳. آپلود فایل EXE در Release | |
- name: Upload Release Asset | |
uses: actions/upload-release-asset@v1 | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./dist/PhotoSlicer-v${{ env.version }}.exe | |
asset_name: PhotoSlicer-v${{ env.version }}-windows-x64.exe | |
asset_content_type: application/octet-stream | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |