diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 255e95a..f84215c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -9,8 +9,9 @@ on: default: '0.0.0' updateRelease: description: 'Update existing release' + type: boolean required: true - default: 'false' + default: false dryRun: description: 'Dry run' required: true @@ -60,7 +61,42 @@ jobs: - build-test - package runs-on: windows-2025 + env: + RELEASE_TAG: v${{ inputs.version }} steps: + - name: Prepare release tag for update + uses: actions/github-script@v8 + if: ${{ inputs.updateRelease && !inputs.dryRun }} + with: + script: | + const tagName = process.env.RELEASE_TAG; + const ref = `tags/${tagName}`; + + try { + await github.rest.git.getRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref, + }); + } catch (error) { + if (error && error.status === 404) { + core.warning(`Tag ${tagName} does not exist yet while updateRelease is enabled; it will be created automatically during release creation at ${context.sha}.`); + return; + } + + throw new Error(`Failed to check ${ref}: ${error?.message ?? String(error)}`); + } + + await github.rest.git.updateRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref, + sha: context.sha, + force: true, + }); + + core.info(`Updated ${ref} to ${context.sha}.`); + - uses: actions/download-artifact@v8 with: pattern: desktopclock-* @@ -71,7 +107,7 @@ jobs: if: ${{ !inputs.dryRun }} uses: ncipollo/release-action@v1.21.0 with: - tag: "v${{ inputs.version }}" + tag: ${{ env.RELEASE_TAG }} artifacts: "release-artifacts/*.zip,release-artifacts/*.msi" generateReleaseNotes: true prerelease: ${{ contains(inputs.version, 'preview') }}