diff --git a/.gitea/workflows/build-exe.yml b/.gitea/workflows/build-exe.yml index dfb8eb7..053b16a 100644 --- a/.gitea/workflows/build-exe.yml +++ b/.gitea/workflows/build-exe.yml @@ -13,6 +13,10 @@ on: - ".gitea/workflows/build-exe.yml" workflow_dispatch: +env: + WINEPREFIX: ${{ github.workspace }}/wine-prefix + WINEPYTHON: ${{ github.workspace }}/wine-prefix/drive_c/Python312/python.exe + jobs: build: runs-on: ubuntu-latest @@ -24,17 +28,18 @@ jobs: - name: Install Wine run: | sudo dpkg --add-architecture i386 - sudo mkdir -pm /etc/apt/keyrings + sudo mkdir -p /etc/apt/keyrings sudo wget -qO /etc/apt/keyrings/winehq-archive.key \ https://dl.winehq.org/wine-builds/winehq.key - sudo wget -qO /etc/apt/sources.list.d/winehq.list \ - https://dl.winehq.org/wine-builds/ubuntu/dists/jammy/winehq-jammy.sources + # Use the actual Ubuntu codename of the runner + CODENAME=$(lsb_release -cs) + sudo wget -qO /etc/apt/sources.list.d/winehq-${CODENAME}.sources \ + "https://dl.winehq.org/wine-builds/ubuntu/dists/${CODENAME}/winehq-${CODENAME}.sources" sudo apt-get update sudo apt-get install --install-recommends winehq-stable -y - name: Set up Wine prefix run: | - export WINEPREFIX=$HOME/wine-prefix mkdir -p "$WINEPREFIX" wineboot --init @@ -46,7 +51,6 @@ jobs: - name: Install Python in Wine run: | - export WINEPREFIX=$HOME/wine-prefix wine /tmp/python.exe \ /quiet \ InstallAllUsers=1 \ @@ -54,27 +58,22 @@ jobs: Include_test=0 rm /tmp/python.exe - - name: Add Python to PATH - run: | - echo "$HOME/wine-prefix/drive_c/Python312" >> $GITHUB_PATH - echo "$HOME/wine-prefix/drive_c/Python312/Scripts" >> $GITHUB_PATH - - name: Install Python dependencies run: | cd server - python -m pip install --upgrade pip - pip install -r requirements.txt + wine "$WINEPYTHON" -m pip install --upgrade pip + wine "$WINEPYTHON" -m pip install -r requirements.txt - name: Run tests run: | cd server - pip install pytest pytest-asyncio - pytest tests/ -v + wine "$WINEPYTHON" -m pip install pytest pytest-asyncio + wine "$WINEPYTHON" -m pytest tests/ -v - name: Build .exe with PyInstaller run: | cd server - python -m PyInstaller \ + wine "$WINEPYTHON" -m PyInstaller \ tray_wrapper.py \ --name PaperDash \ --onefile \ @@ -89,15 +88,54 @@ jobs: path: server/dist/PaperDash.exe if-no-files-found: error - - name: Update Rolling Draft Release - uses: ncipollo/release-action@v1 - with: - allowUpdates: true - draft: true - tag: rolling-draft - name: "Draft (latest build)" - body: | - Latest PaperDash server build from commit ${{ gitea.sha }}. - Built on Linux via Wine + PyInstaller. - Edit tag, name, and notes before publishing. - artifacts: "server/dist/PaperDash.exe" + - name: Create or update draft release + env: + GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RELEASE_TAG: rolling-draft + run: | + # API base URL (e.g. https://your-gitea.example.com/api/v1) + API="${{ github.api_url }}/repos/${{ github.repository }}" + + # Check if release for this tag already exists + RESPONSE=$(curl -sS -H "Authorization: token $GITEA_TOKEN" \ + "$API/releases/tags/$RELEASE_TAG") + RELEASE_ID=$(echo "$RESPONSE" | jq -r '.id // empty') + + if [ -n "$RELEASE_ID" ]; then + echo "Updating existing draft release (ID $RELEASE_ID)" + # Update draft status and body + curl -sS -X PATCH -H "Authorization: token $GITEA_TOKEN" \ + -H "Content-Type: application/json" \ + -d '{ + "draft": true, + "name": "Draft (latest build)", + "body": "Latest PaperDash server build from commit '"${{ github.sha }}"'. Built on Linux via Wine + PyInstaller. Edit tag, name, and notes before publishing." + }' \ + "$API/releases/$RELEASE_ID" + + # Delete existing assets of this release (so we can upload a fresh one) + ASSETS=$(curl -sS -H "Authorization: token $GITEA_TOKEN" \ + "$API/releases/$RELEASE_ID/assets") + for asset_id in $(echo "$ASSETS" | jq -r '.[].id'); do + curl -sS -X DELETE -H "Authorization: token $GITEA_TOKEN" \ + "$API/releases/$RELEASE_ID/assets/$asset_id" + done + else + echo "Creating new draft release" + RESPONSE=$(curl -sS -X POST -H "Authorization: token $GITEA_TOKEN" \ + -H "Content-Type: application/json" \ + -d '{ + "tag_name": "'"$RELEASE_TAG"'", + "draft": true, + "name": "Draft (latest build)", + "body": "Latest PaperDash server build from commit '"${{ github.sha }}"'. Built on Linux via Wine + PyInstaller. Edit tag, name, and notes before publishing." + }' \ + "$API/releases") + RELEASE_ID=$(echo "$RESPONSE" | jq -r '.id') + fi + + # Upload the .exe as a release asset + echo "Uploading PaperDash.exe to release $RELEASE_ID" + curl -sS -X POST -H "Authorization: token $GITEA_TOKEN" \ + -F "attachment=@server/dist/PaperDash.exe;type=application/vnd.microsoft.portable-executable" \ + "$API/releases/$RELEASE_ID/assets" \ No newline at end of file