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 and Release Python Executable | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-latest, windows-latest, macos-latest] | |
steps: | |
- name: Checkout repository | |
# uses: actions/checkout@v2 | |
run: | | |
git clone https://github.com/RetroCyber/thcrap_patch_mirror.git | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.x' | |
- name: Check for Python changes | |
id: check_python | |
shell: bash | |
run: | | |
cd thcrap_patch_mirror | |
pwd | |
ls -l | |
if git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -q '\.py$' ; then | |
echo "Python files were changed." | |
echo "python_changed=true" >> $GITHUB_OUTPUT | |
else | |
echo "No Python files were changed." | |
echo "python_changed=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Install dependencies | |
if: steps.check_python.outputs.python_changed == 'true' | |
run: | | |
cd thcrap_patch_mirror | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
pip install pyinstaller | |
- name: Build executables | |
if: steps.check_python.outputs.python_changed == 'true' | |
shell: bash | |
run: | | |
cd thcrap_patch_mirror | |
pyinstaller --onefile add_patch.py | |
pyinstaller --onefile mirror_repo.py | |
- name: Package executables on Windows | |
if: runner.os == 'Windows' | |
run: | | |
Compress-Archive -Path 'dist/add_patch.exe', 'dist/mirror_repo.exe' -DestinationPath thpatch_mirror.zip | |
shell: pwsh | |
working-directory: thcrap_patch_mirror | |
- name: Package executables on Linux and macOS | |
if: runner.os != 'Windows' | |
run: | | |
tar -czf thpatch_mirror.tar.gz dist/add_patch dist/mirror_repo | |
shell: bash | |
working-directory: thcrap_patch_mirror | |
- name: Upload Package | |
if: steps.check_python.outputs.python_changed == 'true' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: thpatch_mirror-${{ matrix.os }} | |
path: | | |
thpatch_mirror.zip | |
thpatch_mirror.tar.gz | |
release: | |
runs-on: ubuntu-latest | |
needs: build | |
if: needs.build.outputs.python_changed == 'true' | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ github.sha }} | |
release_name: Release ${{ github.sha }} | |
body: ${{ github.event.head_commit.message }} | |
draft: false | |
prerelease: false | |
- name: Upload Release Assets | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: | | |
thpatch_mirror.zip | |
thpatch_mirror.tar.gz | |
asset_name: ${{ matrix.os }}_thpatch_mirror | |
asset_content_type: application/zip |