Build & Release UCP3 backend #379
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 'Build & Release UCP3 backend' | |
on: | |
workflow_dispatch: | |
inputs: | |
release_message: | |
description: 'Message to write in the release' | |
required: true | |
type: string | |
default: '[Changelog](https://github.com/UnofficialCrusaderPatch/UnofficialCrusaderPatch3/wiki/Changelog#)' | |
pre_release: | |
description: 'Pre release?' | |
required: true | |
default: true | |
type: boolean | |
env: | |
# Path to the solution file relative to the root of the project. | |
SOLUTION_FILE_PATH: . | |
RELEASE_BODY: '' | |
jobs: | |
build: | |
runs-on: windows-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
submodules: recursive | |
- name: Add MSBuild to PATH | |
uses: microsoft/[email protected] | |
- name: Prepare signing by exporting secret to file | |
shell: pwsh | |
working-directory: ${{env.GITHUB_WORKSPACE}} | |
env: | |
UCP3_SIGNING_CERTIFICATE_CONTENTS: ${{ secrets.UCP3_SIGNING_CERTIFICATE_CONTENTS }} | |
run: | | |
Set-Content -Value "$env:UCP3_SIGNING_CERTIFICATE_CONTENTS" -Path "$($env:GITHUB_WORKSPACE)\ucp3-module-signing-key.pem" -Force | |
- name: Run build script dev build | |
working-directory: ${{env.GITHUB_WORKSPACE}} | |
env: | |
UCP3_READ_PACKAGES: ${{ secrets.UCP3_READ_PACKAGES }} | |
shell: pwsh | |
run: | | |
.\scripts\build.ps1 -What all -BuildType Release -NugetToken "$env:UCP3_READ_PACKAGES" -Certificate "$($env:GITHUB_WORKSPACE)\ucp3-module-signing-key.pem" | |
- name: Run build script release build | |
working-directory: ${{env.GITHUB_WORKSPACE}} | |
env: | |
UCP3_READ_PACKAGES: ${{ secrets.UCP3_READ_PACKAGES }} | |
shell: pwsh | |
run: | | |
.\scripts\build.ps1 -What all -BuildType ReleaseSecure -NugetToken "$env:UCP3_READ_PACKAGES" -Certificate "$($env:GITHUB_WORKSPACE)\ucp3-module-signing-key.pem" | |
- name: Add UCP3 version to the github environment | |
shell: pwsh | |
run: | | |
Import-Module powershell-yaml | |
$f = Get-Content -Path "version.yml" -Raw | |
$vyml = ConvertFrom-Yaml $f | |
$version_string = "$($vyml.major).$($vyml.minor).$($vyml.patch)"; | |
$env:UCP_VERSION = $version_string | |
echo "UCP_VERSION=$version_string" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
- name: Generate a snapshot UCP3 artifact name | |
shell: pwsh | |
run: | | |
$name = "$env:GITHUB_SHA".SubString(0, 10) | |
$type1 = "DevRelease" | |
$type2 = "Release" | |
$version = $env:UCP_VERSION | |
$env:UCP_NAME_RELEASE = "UCP3-$version-$name" | |
$env:UCP_NAME_DEVRELEASE = "UCP3-$version-$name-Developer" | |
$env:UCP_NAME_NUPKG = "UCP3-$version-$name-nupkg" | |
echo "UCP_NAME_RELEASE=$($env:UCP_NAME_RELEASE)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
echo "UCP_NAME_DEVRELEASE=$($env:UCP_NAME_DEVRELEASE)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
echo "UCP_NAME_NUPKG=$($env:UCP_NAME_NUPKG)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
- name: Upload UCP3 dev release as an artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.UCP_NAME_DEVRELEASE }} | |
path: Release/ucp-package/* | |
retention-days: 1 | |
- name: Upload UCP3 release as an artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.UCP_NAME_RELEASE }} | |
path: ReleaseSecure/ucp-package/* | |
retention-days: 1 | |
- name: Upload UCP3 nupkg for devs as an artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.UCP_NAME_NUPKG }} | |
path: dll/*.nupkg | |
retention-days: 1 | |
- name: Download all workflow run artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
path: artifacts | |
- name: zip artifacts | |
shell: pwsh | |
run: | | |
pushd artifacts | |
$artifactDirs = Get-ChildItem -Directory | |
foreach($artifactDir in $artifactDirs) { | |
$dirName = $artifactDir.name | |
pushd $artifactDir | |
7z a -tzip -m0=Copy "..\$dirName.zip" * | |
popd | |
} | |
popd | |
- name: Create changelog URL | |
run: | | |
$m = "${{ inputs.release_message }}" | |
$t = "[Changelog](https://github.com/UnofficialCrusaderPatch/UnofficialCrusaderPatch3/wiki/Changelog#)" | |
if ( $m.Contains($t) ) { | |
## Get the version | |
$v = $env:UCP_VERSION | |
$vm = $v.Replace(".", "") # Needed this way for pound urls | |
## Create the version URL | |
$url = $t.Replace("#", "#v$vm") | |
$n = $m.Replace($t, $url) | |
## Write the url | |
echo "RELEASE_BODY=$n" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
} else { | |
echo "RELEASE_BODY=$m" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
} | |
shell: pwsh | |
- name: Create latest.json | |
shell: pwsh | |
run: | | |
$url = ${{ steps.auto_update.outputs.upload_url }} | |
$tag = 'v${{ env.UCP_VERSION }}' | |
$baseUrl = "https://github.com/UnofficialCrusaderPatch/UnofficialCrusaderPatch3/releases/download/$($tag)/" | |
$latest = @{ | |
'version' = "$env:UCP_VERSION" | |
'sha' = "$env:GITHUB_SHA" | |
'notes' = "$env:RELEASE_BODY" | |
'pub_date' = Get-Date -Format "o" | |
'build_date' = "$(git log -1 --format=%cd --date=iso-strict)" | |
'base_url' = "$baseUrl" | |
'builds' = @{ | |
'Developer' = @{ | |
'url' = "$($baseUrl)$($env:UCP_NAME_DEVRELEASE).zip" | |
} | |
'Release' = @{ | |
'url' = "$($baseUrl)$($env:UCP_NAME_RELEASE).zip" | |
} | |
} | |
} | |
ConvertTo-Json $latest | Set-Content -Path latest.json | |
- name: Create GitHub release | |
uses: 'marvinpinto/action-automatic-releases@latest' | |
id: auto_update | |
with: | |
repo_token: '${{ secrets.GITHUB_TOKEN }}' | |
automatic_release_tag: 'v${{ env.UCP_VERSION }}' | |
prerelease: ${{ inputs.pre_release }} | |
draft: false | |
title: 'UCP3: v${{ env.UCP_VERSION }}' | |
files: | | |
artifacts/*.zip | |
latest.json | |
- name: Ping UCP3-extensions-repo (create branch for this release) | |
shell: pwsh | |
env: | |
GH_TOKEN: ${{ github.token }} | |
if: false | |
run: | | |
gh repo clone UnofficialCrusaderPatch/UCP3-extensions-store | |
cd UCP3-extensions-store | |
$branchLatest = git branch -a | | |
Where-Object {$_ -match "remotes/origin/[0-9]+[.][0-9]+[.][0-9]+"} | | |
Sort-Object {[semver]( $_.Split("remotes/origin/"))[1]} -Descending | | |
Select-Object -First 1 | | |
ForEach-Object {$_.Split("remotes/origin/")[1]} | |
git checkout -b ${{ env.UCP_VERSION }} origin/$branchLatest | |
git push --set-upstream origin ${{ env.UCP_VERSION }} | |
- name: Push release to auto updater | |
if: ${{ inputs.pre_release == false }} | |
uses: exuanbo/actions-deploy-gist@v1 | |
with: | |
token: '${{ secrets.UCP3_MACHINE_GIST_TOKEN }}' | |
gist_id: 6a7c1de585ed6d60d9ce318c1825d9a7 | |
file_path: latest.json | |
file_type: text |