From 888f953c4316ecb6a97d27cc60de429e7551734e Mon Sep 17 00:00:00 2001 From: Tristan Labelle Date: Wed, 24 Jul 2024 22:11:57 -0400 Subject: [PATCH 1/2] Make the release-publish workflow dispatch-triggered --- .github/workflows/release-publish.yml | 58 +++++++++++++++++++-------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/.github/workflows/release-publish.yml b/.github/workflows/release-publish.yml index 80949e06..c43fc9fb 100644 --- a/.github/workflows/release-publish.yml +++ b/.github/workflows/release-publish.yml @@ -1,10 +1,23 @@ -name: Release +name: Release & Publish on: - push: - tags: - - 'v[0-9]+.[0-9]+.[0-9]+' - - 'v[0-9]+.[0-9]+.[0-9]+-*' + workflow_dispatch: + inputs: + git_ref: + description: 'Git ref' + type: string + required: false + default: 'main' + semver: + description: 'Semantic Version (empty defaults to 0.0.0-commit)' + type: string + required: false + default: '' + publish_nuget: + description: 'Publish NuGet package' + type: boolean + required: false + default: false jobs: build-and-publish: @@ -17,19 +30,26 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: ./.github/actions/setup-swift + with: + ref: ${{ github.event.inputs.git_ref }} - name: Compute Version - id: version + id: context shell: pwsh run: | - $TagName = "${{ github.ref_name }}" - if ($TagName.StartsWith("v")) { $SemVer = $TagName.Substring(1) } - else { - $CommitHash = "${{ github.sha }}".Substring(0, 7) - $SemVer = "0.0.0-$CommitHash" + $SemVer = "${{ github.event.inputs.semver }}" + if ($SemVer -eq "") { + $Commit = & git rev-parse --short=8 | Out-String + $SemVer = "0.0.0-$Commit" + } + if (-not $SemVer -matches "^v\d+\.\d+\.\d+(-\w+)?$") { + throw "Unexpected SemVer format: $SemVer" } - echo "::set-output name=semver::$SemVer" + + Write-Output "::set-output name=tag::v$SemVer" + Write-Output "::set-output name=semver::$SemVer" + + - uses: ./.github/actions/setup-swift - name: CMake Configure working-directory: Generator @@ -48,10 +68,16 @@ jobs: $OutputPath = "${{ github.workspace }}\SwiftWinRT.nupkg" & .\Create-NuGetPackage.ps1 ` -NativeExe "build\release\Sources\SwiftWinRT\SwiftWinRT.exe" ` - -Version "${{ steps.version.outputs.semver }}" ` + -Version "${{ steps.context.outputs.semver }}" ` -OutputPath $OutputPath (Get-FileHash $OutputPath).Hash | Out-File -FilePath "$OutputPath.sha256" + - name: Create Git Tag + shell: pwsh + run: | + & git tag "${{ steps.context.outputs.tag }}" + & git push origin "${{ steps.context.outputs.tag }}" + - name: Create GitHub Release if: github.event_name == 'push' shell: pwsh @@ -59,8 +85,8 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | # Create Release - $TagName = "${{ github.ref_name }}" - $SemVer = "${{ steps.version.outputs.semver }}" + $SemVer = "${{ steps.context.outputs.semver }}" + $TagName = "${{ steps.context.outputs.tag }}" $RepositoryUrl = "${{ github.repository }}" $ExtraArgs = @() if ($SemVer.StartsWith("0.") -or $SemVer.Contains("-")) { $ExtraArgs += "--prerelease" } From 9bd62ec14ea5baa4687d4271eeed81c305e329d4 Mon Sep 17 00:00:00 2001 From: Tristan Labelle Date: Wed, 24 Jul 2024 22:13:19 -0400 Subject: [PATCH 2/2] Better comment --- .github/workflows/release-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-publish.yml b/.github/workflows/release-publish.yml index c43fc9fb..a385cb11 100644 --- a/.github/workflows/release-publish.yml +++ b/.github/workflows/release-publish.yml @@ -26,7 +26,7 @@ jobs: timeout-minutes: 15 permissions: contents: - write # Create release + write # Create tag and release steps: - uses: actions/checkout@v3