From 20e9374154e599d059ed6b77b908cea45706d3f5 Mon Sep 17 00:00:00 2001 From: Ludwig Lehnert Date: Mon, 29 Jun 2026 13:23:01 +0000 Subject: [PATCH] fix workflow --- .github/workflows/release.yml | 59 +++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a5a9123..6e7accc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -38,14 +38,53 @@ jobs: (cd package && zip -r "../${archive}" LICENSE setup.ps1 PolicyDefinitions) - name: Create or update release + uses: actions/github-script@v7 env: - GH_TOKEN: ${{ github.token }} - run: | - if gh release view "${SHORT_SHA}" >/dev/null 2>&1; then - gh release upload "${SHORT_SHA}" "${ARCHIVE}" --clobber - else - gh release create "${SHORT_SHA}" "${ARCHIVE}" \ - --target "${GITHUB_SHA}" \ - --title "${SHORT_SHA}" \ - --notes "Automated build for ${GITHUB_SHA}." - fi + SHORT_SHA: ${{ env.SHORT_SHA }} + ARCHIVE: ${{ env.ARCHIVE }} + with: + script: | + const fs = require('fs'); + const path = require('path'); + + const owner = context.repo.owner; + const repo = context.repo.repo; + const tag = process.env.SHORT_SHA; + const archive = process.env.ARCHIVE; + + let release; + try { + const existing = await github.rest.repos.getReleaseByTag({ owner, repo, tag }); + release = existing.data; + } catch (error) { + if (error.status !== 404) throw error; + const created = await github.rest.repos.createRelease({ + owner, + repo, + tag_name: tag, + target_commitish: context.sha, + name: tag, + body: `Automated build for ${context.sha}.`, + }); + release = created.data; + } + + const assetName = path.basename(archive); + for (const asset of release.assets || []) { + if (asset.name === assetName) { + await github.rest.repos.deleteReleaseAsset({ owner, repo, asset_id: asset.id }); + } + } + + const data = fs.readFileSync(archive); + await github.rest.repos.uploadReleaseAsset({ + owner, + repo, + release_id: release.id, + name: assetName, + data, + headers: { + 'content-type': 'application/zip', + 'content-length': data.length, + }, + });