From 0bd097d52bd3f4c37d631ad51e540206bb3489df Mon Sep 17 00:00:00 2001 From: Game_Time <108236317+RayBytes@users.noreply.github.com> Date: Sun, 17 Aug 2025 21:59:02 +0500 Subject: [PATCH] Create update-release-assets.yml --- .github/workflows/update-release-assets.yml | 103 ++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 .github/workflows/update-release-assets.yml diff --git a/.github/workflows/update-release-assets.yml b/.github/workflows/update-release-assets.yml new file mode 100644 index 0000000..ea454db --- /dev/null +++ b/.github/workflows/update-release-assets.yml @@ -0,0 +1,103 @@ +name: Update Latest Release Assets + +on: + push: + branches: [ main, master ] + +permissions: + contents: write + +jobs: + build-and-attach: + name: Build (${{ matrix.os }}) and attach to latest release + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ macos-latest, windows-latest ] + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt pyinstaller + + - name: Build app (macOS) + if: startsWith(matrix.os, 'macos') + run: | + python build.py --name ChatMock --entry app_qt.py --dmg + mv dist/ChatMock.dmg dist/ChatMock-macos.dmg + + - name: Build app (Windows) + if: startsWith(matrix.os, 'windows') + shell: pwsh + run: | + python build.py --name ChatMock --entry app_qt.py + if (Test-Path dist/ChatMock-windows.zip) { Remove-Item dist/ChatMock-windows.zip -Force } + Compress-Archive -Path "dist/ChatMock/*" -DestinationPath "dist/ChatMock-windows.zip" + + - name: Set asset variables + id: asset + shell: bash + run: | + if [[ "${{ matrix.os }}" == macos-* ]]; then + echo "name=ChatMock-macos.dmg" >> $GITHUB_OUTPUT + echo "path=dist/ChatMock-macos.dmg" >> $GITHUB_OUTPUT + else + echo "name=ChatMock-windows.zip" >> $GITHUB_OUTPUT + echo "path=dist/ChatMock-windows.zip" >> $GITHUB_OUTPUT + fi + + - name: Get latest release + id: latest_release + uses: actions/github-script@v7 + with: + script: | + const { owner, repo } = context.repo; + try { + const latest = await github.rest.repos.getLatestRelease({ owner, repo }); + core.setOutput('id', latest.data.id.toString()); + core.setOutput('tag', latest.data.tag_name); + core.setOutput('upload_url', latest.data.upload_url); + } catch (e) { + core.warning(`No releases found or error fetching latest release: ${e.message}`); + core.setOutput('id', ''); + core.setOutput('tag', ''); + core.setOutput('upload_url', ''); + } + + - name: Delete prior asset for this platform + if: steps.latest_release.outputs.tag != '' + uses: actions/github-script@v7 + env: + RELEASE_ID: ${{ steps.latest_release.outputs.id }} + ASSET_NAME: ${{ steps.asset.outputs.name }} + with: + script: | + const { owner, repo } = context.repo; + const release_id = Number(process.env.RELEASE_ID); + const assetName = process.env.ASSET_NAME; + const assets = await github.rest.repos.listReleaseAssets({ owner, repo, release_id, per_page: 100 }); + const match = assets.data.find(a => a.name === assetName); + if (match) { + core.info(`Deleting existing asset: ${match.name} (id=${match.id})`); + await github.rest.repos.deleteReleaseAsset({ owner, repo, asset_id: match.id }); + } else { + core.info(`No existing asset named ${assetName} found.`); + } + + - name: Upload new asset to latest release + if: steps.latest_release.outputs.tag != '' + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ steps.latest_release.outputs.tag }} + files: ${{ steps.asset.outputs.path }} +