diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 064dedd..88b7c9e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,6 +1,10 @@ name: Release -# Push a tag like v1.3.0 (stable) or v1.3.0-beta.2 (pre-release) to publish a release. +# Two ways to publish a release (a version with a hyphen, like 1.6.0-alpha.3, is a pre-release): +# - Actions > Release > Run workflow on main, with the version and "publish" ticked: the tag and the +# release are created here, from main. +# - Push a tag like v1.3.0 (stable) or v1.3.0-beta.2 (pre-release). +# With "publish" unticked the workflow only builds and uploads the files as an artifact. # The app's update check (UpdateService) reads these releases and looks for the # ConsoleMode-Setup-*.exe / ConsoleMode-Portable-*.exe assets built here. on: @@ -10,8 +14,12 @@ on: workflow_dispatch: inputs: version: - description: "Version to build without publishing (e.g. 1.3.0-beta.2)" + description: "Version (e.g. 1.6.0-alpha.3). A hyphen makes it a pre-release." required: true + publish: + description: "Publish: create the tag and the GitHub release (only from main). Unticked, just build." + type: boolean + default: false permissions: contents: write @@ -19,6 +27,10 @@ permissions: jobs: build: runs-on: windows-latest + outputs: + version: ${{ steps.version.outputs.version }} + prerelease: ${{ steps.version.outputs.prerelease }} + publish: ${{ steps.version.outputs.publish }} steps: - name: Checkout uses: actions/checkout@v4 @@ -34,16 +46,25 @@ jobs: env: EVENT_NAME: ${{ github.event_name }} REF_NAME: ${{ github.ref_name }} + REF: ${{ github.ref }} INPUT_VERSION: ${{ github.event.inputs.version }} + INPUT_PUBLISH: ${{ github.event.inputs.publish }} run: | $v = if ($env:EVENT_NAME -eq "push") { $env:REF_NAME } else { $env:INPUT_VERSION } $v = $v.TrimStart("v") if ($v -notmatch '^\d+\.\d+\.\d+(-[0-9A-Za-z.\-]+)?$') { throw "Versão inválida: $v" } + $publish = ($env:EVENT_NAME -eq "push") -or ($env:INPUT_PUBLISH -eq "true") + if ($publish -and $env:EVENT_NAME -ne "push") { + # Publishing by hand creates the tag here: only from main, and never over a tag that exists. + if ($env:REF -ne "refs/heads/main") { throw "Só dá para publicar a partir da main (rodando em $($env:REF))." } + if (git ls-remote --tags origin "refs/tags/v$v") { throw "A tag v$v já existe." } + } "version=$v" >> $env:GITHUB_OUTPUT "prerelease=$($v.Contains('-').ToString().ToLower())" >> $env:GITHUB_OUTPUT + "publish=$($publish.ToString().ToLower())" >> $env:GITHUB_OUTPUT - name: Prepare release notes (English, with a link to the Portuguese changelog) - if: github.event_name == 'push' + if: steps.version.outputs.publish == 'true' shell: pwsh env: VERSION: ${{ steps.version.outputs.version }} @@ -93,10 +114,10 @@ jobs: # Code signing (docs/CODE_SIGNING.md). Off until the SignPath repository variables exist: # SIGNPATH_ORGANIZATION_ID, SIGNPATH_PROJECT_SLUG, SIGNPATH_POLICY_SLUG, plus the - # SIGNPATH_API_TOKEN secret. Only tag pushes are signed; each request waits for manual approval. + # SIGNPATH_API_TOKEN secret. Only published releases are signed; each request waits for manual approval. - name: Upload unsigned build for signing id: unsigned - if: github.event_name == 'push' && vars.SIGNPATH_ORGANIZATION_ID != '' + if: steps.version.outputs.publish == 'true' && vars.SIGNPATH_ORGANIZATION_ID != '' uses: actions/upload-artifact@v4 with: name: unsigned-${{ steps.version.outputs.version }} @@ -106,7 +127,7 @@ jobs: if-no-files-found: error - name: Sign with SignPath - if: github.event_name == 'push' && vars.SIGNPATH_ORGANIZATION_ID != '' + if: steps.version.outputs.publish == 'true' && vars.SIGNPATH_ORGANIZATION_ID != '' uses: signpath/github-action-submit-signing-request@v2 with: api-token: ${{ secrets.SIGNPATH_API_TOKEN }} @@ -119,7 +140,7 @@ jobs: output-artifact-directory: dist-signed - name: Use the signed files - if: github.event_name == 'push' && vars.SIGNPATH_ORGANIZATION_ID != '' + if: steps.version.outputs.publish == 'true' && vars.SIGNPATH_ORGANIZATION_ID != '' shell: pwsh run: | foreach ($name in "ConsoleMode-Setup-x64.exe", "ConsoleMode-Portable-x64.exe") { @@ -139,9 +160,12 @@ jobs: if-no-files-found: error - name: Publish GitHub release - if: github.event_name == 'push' + if: steps.version.outputs.publish == 'true' uses: softprops/action-gh-release@v2 with: + # Pushed tag: it already exists. Run by hand: it is created here, on the commit that was built. + tag_name: v${{ steps.version.outputs.version }} + target_commitish: ${{ github.sha }} name: Console Mode ${{ steps.version.outputs.version }} prerelease: ${{ steps.version.outputs.prerelease }} fail_on_unmatched_files: true @@ -159,7 +183,7 @@ jobs: # account that owns the lippdev/winget-pkgs fork. winget: needs: build - if: github.event_name == 'push' && !contains(github.ref_name, '-') + if: needs.build.outputs.publish == 'true' && needs.build.outputs.prerelease == 'false' runs-on: ubuntu-latest env: WINGET_TOKEN: ${{ secrets.WINGET_TOKEN }} @@ -169,7 +193,7 @@ jobs: uses: vedantmgoyal9/winget-releaser@v2 with: identifier: lippdev.ConsoleMode - release-tag: ${{ github.ref_name }} + release-tag: v${{ needs.build.outputs.version }} installers-regex: 'ConsoleMode-Setup-x64\.exe$' fork-user: lippdev token: ${{ env.WINGET_TOKEN }} diff --git a/AGENTS.md b/AGENTS.md index 6846c56..6aef845 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -26,7 +26,9 @@ Xbox mode, and restores the desk setup afterwards. - `src/ConsoleMode/Native`: P/Invoke (Win32, CCD display config). - `src/ConsoleMode/Views`, `ViewModels`, `Controls`: UI (MVVM with CommunityToolkit.Mvvm). - `build/`: publish script and Inno Setup installer. `.github/workflows/release.yml` - publishes a release when a `v*` tag is pushed. **Never create or push tags.** + publishes a release when a `v*` tag is pushed, or when it is run by hand (Actions → Release → Run + workflow, on `main`) with "publish" ticked, which creates the tag itself. **Never create or push tags + and never run it with "publish" ticked unless the owner explicitly asks for a release.** ## Conventions diff --git a/docs/GUIDE.md b/docs/GUIDE.md index 3b60cd4..a9bfddd 100644 --- a/docs/GUIDE.md +++ b/docs/GUIDE.md @@ -73,7 +73,7 @@ Requires [Visual Studio 2022](https://visualstudio.microsoft.com/) with the **Wi Output: `dist\ConsoleMode-Portable-x64.exe` and `dist\ConsoleMode-Setup-x64.exe` (the installer needs [Inno Setup 6](https://jrsoftware.org/isinfo.php): `winget install JRSoftware.InnoSetup`). Open `ConsoleMode.sln` to debug. -To release, push a tag like `v1.4.0` (or `v1.4.0-beta.2` for a pre-release): the `Release` workflow builds both files and publishes them, and the app picks them up as an update. +To release, merge the release PR into `main`, then run Actions → **Release** → Run workflow on `main` with the version (like `1.4.0`, or `1.4.0-beta.2` for a pre-release) and **publish** ticked: the workflow creates the tag and the GitHub release, builds both files and publishes them, and the app picks them up as an update. Without "publish" it only builds and uploads the files as an artifact. Pushing a `v*` tag still works and does the same. The previous PowerShell + WPF implementation (1.2 and earlier) lives on the [`legacy`](https://github.com/lippdev/consolemode/tree/legacy) branch and is not used by the WinUI app. diff --git a/docs/GUIDE.pt-BR.md b/docs/GUIDE.pt-BR.md index ee7a86f..f5c5863 100644 --- a/docs/GUIDE.pt-BR.md +++ b/docs/GUIDE.pt-BR.md @@ -73,6 +73,6 @@ Precisa do [Visual Studio 2022](https://visualstudio.microsoft.com/) com a workl Saída: `dist\ConsoleMode-Portable-x64.exe` e `dist\ConsoleMode-Setup-x64.exe` (o instalador precisa do [Inno Setup 6](https://jrsoftware.org/isinfo.php): `winget install JRSoftware.InnoSetup`). Abra `ConsoleMode.sln` para depurar. -Para lançar uma versão, faça push de uma tag como `v1.4.0` (ou `v1.4.0-beta.2` para pré-release): o workflow `Release` gera e publica os dois arquivos, e o app oferece a atualização. +Para lançar uma versão, faça o merge do PR de release na `main` e rode Actions → **Release** → Run workflow na `main` com a versão (como `1.4.0`, ou `1.4.0-beta.2` para pré-release) e **publish** marcado: o workflow cria a tag e a release no GitHub, gera os dois arquivos e os publica, e o app oferece a atualização. Sem "publish" ele só gera e guarda os arquivos como artefato. Fazer push de uma tag `v*` continua funcionando e faz o mesmo. A implementação antiga em PowerShell + WPF (1.2 e anteriores) fica na branch [`legacy`](https://github.com/lippdev/consolemode/tree/legacy) e não é usada pelo app WinUI.