Skip to content

Release & Publish

Release & Publish #12

name: Release & Publish
on:
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:
name: Build and Publish
runs-on: windows-2022
timeout-minutes: 15
permissions:
contents:
write # Create tag and release
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.git_ref }}
- name: Compute Version
id: context
shell: pwsh
run: |
$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"
}
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
shell: pwsh
run: cmake --preset release
- name: CMake Build
working-directory: Generator
shell: pwsh
run: cmake --build --preset release
- name: Create NuGet Package
working-directory: Generator
shell: pwsh
run: |
$OutputPath = "${{ github.workspace }}\SwiftWinRT.nupkg"
& .\Create-NuGetPackage.ps1 `
-NativeExe "build\release\Sources\SwiftWinRT\SwiftWinRT.exe" `
-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
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Create Release
$SemVer = "${{ steps.context.outputs.semver }}"
$TagName = "${{ steps.context.outputs.tag }}"
$RepositoryUrl = "${{ github.repository }}"
$ExtraArgs = @()
if ($SemVer.StartsWith("0.") -or $SemVer.Contains("-")) { $ExtraArgs += "--prerelease" }
& gh release create $TagName --repo $RepositoryUrl --title $SemVer --generate-notes @ExtraArgs
& gh release upload $TagName SwiftWinRT.nupkg --repo $RepositoryUrl
& gh release upload $TagName SwiftWinRT.nupkg.sha256 --repo $RepositoryUrl