192 lines
6.0 KiB
YAML
192 lines
6.0 KiB
YAML
name: Build Windows EXE
|
|
|
|
on:
|
|
push:
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
APP_NAME: Shortcut_Sync_PotPlayer
|
|
PACKAGE_NAME: shortcut-sync-potplayer
|
|
PYTHON_VERSION: "3.9.1"
|
|
PYTHON_DIR: 'C:\Python391'
|
|
PYTHON_EXE: 'C:\Python391\python.exe'
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-22.04
|
|
|
|
steps:
|
|
- name: Verify workspace
|
|
shell: bash
|
|
run: |
|
|
pwd
|
|
ls -la
|
|
test -f main.py || {
|
|
echo "main.py not found in workspace."
|
|
echo "If your runner does not auto-check out the repository, add a local mirror for checkout or clone the repo before running this workflow."
|
|
exit 1
|
|
}
|
|
|
|
- name: Setup Wine
|
|
shell: bash
|
|
run: |
|
|
WINEPREFIX="$RUNNER_TEMP/wine"
|
|
echo "WINEPREFIX=$WINEPREFIX" >> "$GITHUB_ENV"
|
|
echo "WINEDEBUG=-all" >> "$GITHUB_ENV"
|
|
export WINEPREFIX
|
|
export WINEDEBUG=-all
|
|
|
|
sudo dpkg --add-architecture i386
|
|
sudo apt-get update
|
|
sudo apt-get install -y --no-install-recommends \
|
|
wine64 \
|
|
wine32 \
|
|
curl \
|
|
ca-certificates \
|
|
jq \
|
|
xvfb \
|
|
zip
|
|
|
|
xvfb-run -a wine64 wineboot --init
|
|
wineserver -w
|
|
wine64 --version
|
|
|
|
- name: Install Windows Python
|
|
shell: bash
|
|
run: |
|
|
curl -fsSL \
|
|
"https://www.python.org/ftp/python/${PYTHON_VERSION}/python-${PYTHON_VERSION}-amd64.exe" \
|
|
-o /tmp/python-installer.exe
|
|
|
|
xvfb-run -a wine64 /tmp/python-installer.exe \
|
|
/quiet \
|
|
InstallAllUsers=1 \
|
|
PrependPath=1 \
|
|
Include_pip=1 \
|
|
Include_test=0 \
|
|
SimpleInstall=1 \
|
|
"TargetDir=${PYTHON_DIR}"
|
|
|
|
wineserver -w
|
|
rm -f /tmp/python-installer.exe
|
|
xvfb-run -a wine64 "${PYTHON_EXE}" --version
|
|
|
|
- name: Install dependencies
|
|
shell: bash
|
|
run: |
|
|
xvfb-run -a wine64 "${PYTHON_EXE}" -m pip install --upgrade pip setuptools wheel
|
|
|
|
if [ -f requirements.txt ]; then
|
|
xvfb-run -a wine64 "${PYTHON_EXE}" -m pip install --no-cache-dir -r requirements.txt
|
|
fi
|
|
|
|
xvfb-run -a wine64 "${PYTHON_EXE}" -m pip install --no-cache-dir \
|
|
pyinstaller \
|
|
keyboard \
|
|
pywin32
|
|
|
|
xvfb-run -a wine64 "${PYTHON_EXE}" -c "import keyboard, win32api, win32gui; print('dependencies ok')"
|
|
|
|
- name: Build EXE
|
|
shell: bash
|
|
run: |
|
|
xvfb-run -a wine64 "${PYTHON_EXE}" -m PyInstaller \
|
|
--noconfirm \
|
|
--clean \
|
|
--onefile \
|
|
--windowed \
|
|
--name "${APP_NAME}" \
|
|
main.py
|
|
|
|
test -f "dist/${APP_NAME}.exe"
|
|
|
|
- name: Package build
|
|
id: package
|
|
shell: bash
|
|
run: |
|
|
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
|
|
version="$GITHUB_REF_NAME"
|
|
else
|
|
version="run-${GITHUB_RUN_NUMBER}-${GITHUB_SHA::7}"
|
|
fi
|
|
|
|
archive_name="${APP_NAME}-${version}-windows-x64.zip"
|
|
archive_path="dist/${archive_name}"
|
|
|
|
zip -j "$archive_path" "dist/${APP_NAME}.exe"
|
|
|
|
echo "version=${version}" >> "$GITHUB_OUTPUT"
|
|
echo "archive_name=${archive_name}" >> "$GITHUB_OUTPUT"
|
|
echo "archive_path=${archive_path}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Upload package to Gitea Packages
|
|
id: publish_package
|
|
shell: bash
|
|
env:
|
|
ACTIONS_TOKEN: ${{ github.token }}
|
|
run: |
|
|
owner="${GITHUB_REPOSITORY%%/*}"
|
|
package_url="${GITHUB_SERVER_URL}/api/packages/${owner}/generic/${PACKAGE_NAME}/${{ steps.package.outputs.version }}/${{ steps.package.outputs.archive_name }}"
|
|
|
|
curl --fail-with-body --silent --show-error \
|
|
-X PUT \
|
|
-H "Authorization: token ${ACTIONS_TOKEN}" \
|
|
-H "Content-Type: application/zip" \
|
|
--upload-file "${{ steps.package.outputs.archive_path }}" \
|
|
"$package_url"
|
|
|
|
echo "package_url=${package_url}" >> "$GITHUB_OUTPUT"
|
|
if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then
|
|
echo "Built package: ${package_url}" >> "$GITHUB_STEP_SUMMARY"
|
|
fi
|
|
|
|
- name: Create release on tag
|
|
if: startsWith(github.ref, 'refs/tags/')
|
|
shell: bash
|
|
env:
|
|
ACTIONS_TOKEN: ${{ github.token }}
|
|
run: |
|
|
api_url="${GITHUB_API_URL:-${GITHUB_SERVER_URL}/api/v1}"
|
|
releases_url="${api_url}/repos/${GITHUB_REPOSITORY}/releases"
|
|
tag_name="${GITHUB_REF_NAME}"
|
|
release_name="${tag_name}"
|
|
body="Windows build package: ${{ steps.publish_package.outputs.package_url }}"
|
|
|
|
existing_release_id="$(
|
|
curl --silent \
|
|
-H "Authorization: token ${ACTIONS_TOKEN}" \
|
|
"${releases_url}" | jq -r --arg tag "$tag_name" '.[] | select(.tag_name == $tag) | .id' | head -n 1
|
|
)"
|
|
|
|
if [ -n "$existing_release_id" ] && [ "$existing_release_id" != "null" ]; then
|
|
echo "Release already exists for ${tag_name}, skipping creation."
|
|
exit 0
|
|
fi
|
|
|
|
payload="$(
|
|
jq -n \
|
|
--arg tag_name "$tag_name" \
|
|
--arg target_commitish "$GITHUB_SHA" \
|
|
--arg name "$release_name" \
|
|
--arg body "$body" \
|
|
'{
|
|
tag_name: $tag_name,
|
|
target_commitish: $target_commitish,
|
|
name: $name,
|
|
body: $body,
|
|
draft: false,
|
|
prerelease: false
|
|
}'
|
|
)"
|
|
|
|
curl --fail-with-body --silent --show-error \
|
|
-X POST \
|
|
-H "Authorization: token ${ACTIONS_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$payload" \
|
|
"$releases_url" > /dev/null
|
|
|
|
if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then
|
|
echo "Release created for ${tag_name}" >> "$GITHUB_STEP_SUMMARY"
|
|
fi
|