Update workflows

pull/458/head
SimonDarksideJ 2023-10-05 20:35:32 +01:00
parent d2b10980e3
commit 9a823060a7
8 changed files with 400 additions and 134 deletions

View File

@ -1,10 +1,10 @@
name: Build and test UPM packages for platforms on all available Unity Versions
name: Build and test UPM packages for platforms, all branches except main
on:
pull_request:
branches-ignore:
- 'release'
# Ignore PRs targetting main
# Ignore PRs targeting main
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
@ -14,6 +14,7 @@ concurrency:
cancel-in-progress: true
jobs:
# Check Unity version required by the package
# Run Unity build unit tests defined in the package for a single version for feature branches
Run-Partial-Unit-Tests:
name: Run Unity Unit Tests
@ -27,11 +28,3 @@ jobs:
name: Run Unity Unit Tests
if: github.ref == 'refs/heads/development'
uses: ./.github/workflows/rununitybuildmultiversion.yml
# Update the package release version
Update-Version:
name: Update Package Version
uses: ./.github/workflows/tagrelease.yml
with:
build-target: windows
secrets: inherit

View File

@ -0,0 +1,26 @@
name: Publish development branch on Merge
on:
pull_request:
types:
- closed
branches:
- development
# On close of PR targeting development
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
release_on_merge:
if: github.event.pull_request.merged == true
name: Tag and Publish UPM package
uses: ./.github/workflows/upversionandtagrelease.yml
with:
build-host: ubuntu-latest
build-type: pre-release
secrets: inherit

91
.github/workflows/main-publish.yml vendored Normal file
View File

@ -0,0 +1,91 @@
name: Publish main branch and increment version
on:
pull_request:
types:
- closed
branches:
- main
jobs:
# Get Version to tag and release the branch, no up-version - [no-ver] included in PR title
validate-environment:
if: github.event.pull_request.merged == true && contains(github.event.pull_request.title, 'no-ver')
name: Get Version from UPM package
uses: ./.github/workflows/getpackageversionfrompackage.yml
with:
build-host: ubuntu-latest
# Perform tagging
release-Package-only:
needs: validate-environment
name: Release package only, no upversion
uses: ./.github/workflows/tagrelease.yml
with:
build-host: ubuntu-latest
version: ${{ needs.validate-environment.outputs.packageversion }}
secrets: inherit
# Up version the release and publish major release
upversion-major-Package:
if: github.event.pull_request.merged == true && contains(github.event.pull_request.title, 'no-ver') == false && contains(github.event.pull_request.title, 'major-release')
name: Major Version package and release
uses: ./.github/workflows/upversionandtagrelease.yml
with:
build-host: ubuntu-latest
build-type: major
secrets: inherit
# Up version the release and publish minor release
upversion-minor-Package:
if: github.event.pull_request.merged == true && contains(github.event.pull_request.title, 'no-ver') == false && contains(github.event.pull_request.title, 'minor-release')
name: Minor Version package and release
uses: ./.github/workflows/upversionandtagrelease.yml
with:
build-host: ubuntu-latest
build-type: minor
secrets: inherit
# Up version the release and publish patch release (default)
upversion-patch-Package:
if: github.event.pull_request.merged == true && contains(github.event.pull_request.title, 'no-ver') == false && contains(github.event.pull_request.title, 'minor-release') == false && contains(github.event.pull_request.title, 'major-release') == false
name: Patch Version package and release
uses: ./.github/workflows/upversionandtagrelease.yml
with:
build-host: ubuntu-latest
build-type: patch-release
secrets: inherit
release-Complete:
if: ${{ always() }}
needs: [upversion-major-Package, upversion-minor-Package, upversion-patch-Package, release-Package-only]
name: Release complete
runs-on: ubuntu-latest
steps:
- name: Script Version
run: echo "Release done, updating Development"
# Refresh the development branch with the main publish
refresh-development:
if: ${{ always() }}
needs: [release-Complete]
name: Refresh development branch
uses: ./.github/workflows/refreshbranch.yml
with:
build-host: ubuntu-latest
target-branch: development
source-branch: main
secrets: inherit
# Up version the development branch ready for future development
upversion-development:
if: ${{ always() }}
needs: [refresh-development]
name: UpVersion the development branch for the next release
uses: ./.github/workflows/upversionandtagrelease.yml
with:
build-host: ubuntu-latest
build-type: patch
target-branch: development
createTag: false
secrets: inherit

43
.github/workflows/refreshbranch.yml vendored Normal file
View File

@ -0,0 +1,43 @@
name: Refresh branch
on:
workflow_call:
inputs:
build-host:
required: true
type: string
target-branch:
required: true
type: string
source-branch:
required: true
type: string
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
packageRelease:
name: Refresh ${{ inputs.target-branch }} branch from ${{ inputs.source-branch }} branch
runs-on: ${{ inputs.build-host }}
steps:
- name: Script Version
run: |
echo "::group::Script Versioning"
$scriptVersion = "1.0.1"
echo "Build Script Version: $scriptVersion"
echo "::endgroup::"
shell: pwsh
- uses: actions/checkout@v3
with:
ref: ${{ inputs.target-branch }}
clean: true
token: ${{ secrets.GIT_PAT }}
- name: Refresh from Source Branch
run: |
git pull origin ${{ inputs.source-branch }}
git commit -m "Branch ${{ inputs.target-branch }} updated with changes from ${{ inputs.source-branch }} [skip ci]"
git push origin ${{ inputs.target-branch }}
echo "Branch ${{ inputs.target-branch }} updated with changes from ${{ inputs.source-branch }}"
shell: pwsh

View File

@ -18,7 +18,7 @@ jobs:
- os: windows
unityVersion: 2019.4
build-target: Android
- os: macos
- os: macOS
unityVersion: 2019.4
build-target: iOS
- os: windows
@ -30,7 +30,7 @@ jobs:
- os: windows
unityVersion: 2020.3
build-target: Android
- os: macos
- os: macOS
unityVersion: 2020.3
build-target: iOS
- os: windows
@ -42,7 +42,7 @@ jobs:
- os: windows
unityVersion: 2021.3
build-target: Android
- os: macos
- os: macOS
unityVersion: 2021.3
build-target: iOS
- os: windows
@ -54,7 +54,7 @@ jobs:
- os: windows
unityVersion: 2022.2
build-target: Android
- os: macos
- os: macOS
unityVersion: 2022.2
build-target: iOS
- os: windows
@ -80,7 +80,7 @@ jobs:
name: 'Run Unity Builds'
run: |
echo "::group::Set Hub and editor locations"
$unityVersion = ${{ matrix.unityVersion }}
$unityVersion = '${{ matrix.unityVersion }}'
echo "::group::Set Hub and editor locations"
@ -90,6 +90,7 @@ jobs:
$hubPath = "C:\Program Files\Unity Hub\Unity Hub.exe"
$editorRootPath = "C:\Program Files\Unity\Hub\Editor\"
$editorFileEx = "\Editor\Unity.exe"
$directorySeparatorChar = "\"
#"Unity Hub.exe" -- --headless help
#. 'C:\Program Files\Unity Hub\Unity Hub.exe' -- --headless help
@ -100,11 +101,12 @@ jobs:
}
elseif ( $global:PSVersionTable.OS.Contains("Darwin") )
{
$hubPath = "/Applications/Unity Hub.app/Contents/MacOS/Unity Hub"
$hubPath = "/Applications/Unity Hub.app/Contents/macOS/Unity Hub"
$editorRootPath = "/Applications/Unity/Hub/Editor/"
$editorFileEx = "/Unity.app/Contents/MacOS/Unity"
$editorFileEx = "/Unity.app/Contents/macOS/Unity"
$directorySeparatorChar = "/"
# /Applications/Unity\ Hub.app/Contents/MacOS/Unity\ Hub -- --headless help
# /Applications/Unity\ Hub.app/Contents/macOS/Unity\ Hub -- --headless help
function unity-hub
{
& $hubPath -- --headless $args.Split(" ") | Out-String -NoNewline
@ -115,6 +117,7 @@ jobs:
$hubPath = "$HOME/Unity Hub/UnityHub.AppImage"
$editorRootPath = "$HOME/Unity/Hub/Editor/"
$editorFileEx = "/Editor/Unity"
$directorySeparatorChar = "/"
# /UnityHub.AppImage --headless help
# xvfb-run --auto-servernum "$HOME/Unity Hub/UnityHub.AppImage" --headless help
@ -126,8 +129,6 @@ jobs:
echo "::endgroup::"
echo "::group::Get String function to query a string for a value"
function GetString($InputString, $InputPattern, $MatchIndex)
@ -151,7 +152,6 @@ jobs:
echo "::endgroup::"
echo "::group::Get Installed Unity version based on Matrix"
echo 'Script Start'
echo "Unity hub path is {$hubPath}"
echo "Requested unity version is {$unityVersion}"
@ -171,7 +171,7 @@ jobs:
$queryUnityVersion = GetString $InstalledUnityVersions "$unityVersion" -MatchIndex 0
}
echo "Found unity version is {$queryUnityVersion}"
echo "Found unity version is {$queryUnityVersion} for input {$unityVersion}"
if ($queryUnityVersion -ne 0)
{
@ -218,7 +218,7 @@ jobs:
}
elseif ( $global:PSVersionTable.OS.Contains("Darwin") ) {
echo 'Building using Mac'
$editorFileEx = "/Unity.app/Contents/MacOS/Unity"
$editorFileEx = "/Unity.app/Contents/macOS/Unity"
$editorrunpath = Join-Path $editorRootPath $unityVersion $editorFileEx
function unity-editor {

View File

@ -19,7 +19,7 @@ jobs:
strategy:
matrix:
include:
- os: macos
- os: macOS
build-target: iOS
- os: windows
build-target: Android
@ -40,12 +40,11 @@ jobs:
with:
submodules: recursive
clean: true
- id: build
name: 'Run Unity Builds'
run: |
echo "::group::Set Hub and editor locations"
$unityVersion = ${{ inputs.unityVersion }}
$unityVersion = '${{ inputs.unityVersion }}'
echo "::group::Set Hub and editor locations"
@ -55,6 +54,7 @@ jobs:
$hubPath = "C:\Program Files\Unity Hub\Unity Hub.exe"
$editorRootPath = "C:\Program Files\Unity\Hub\Editor\"
$editorFileEx = "\Editor\Unity.exe"
$directorySeparatorChar = "\"
#"Unity Hub.exe" -- --headless help
#. 'C:\Program Files\Unity Hub\Unity Hub.exe' -- --headless help
@ -68,6 +68,7 @@ jobs:
$hubPath = "/Applications/Unity Hub.app/Contents/MacOS/Unity Hub"
$editorRootPath = "/Applications/Unity/Hub/Editor/"
$editorFileEx = "/Unity.app/Contents/MacOS/Unity"
$directorySeparatorChar = "/"
# /Applications/Unity\ Hub.app/Contents/MacOS/Unity\ Hub -- --headless help
function unity-hub
@ -80,6 +81,7 @@ jobs:
$hubPath = "$HOME/Unity Hub/UnityHub.AppImage"
$editorRootPath = "$HOME/Unity/Hub/Editor/"
$editorFileEx = "/Editor/Unity"
$directorySeparatorChar = "/"
# /UnityHub.AppImage --headless help
# xvfb-run --auto-servernum "$HOME/Unity Hub/UnityHub.AppImage" --headless help
@ -91,8 +93,6 @@ jobs:
echo "::endgroup::"
echo "::group::Get String function to query a string for a value"
function GetString($InputString, $InputPattern, $MatchIndex)
@ -115,8 +115,7 @@ jobs:
}
echo "::endgroup::"
echo "::group::Get Installed Unity version based on Matrix"
echo 'Script Start'
echo "::group::Find Installed Unity version based on input"
echo "Unity hub path is {$hubPath}"
echo "Requested unity version is {$unityVersion}"
@ -136,7 +135,7 @@ jobs:
$queryUnityVersion = GetString $InstalledUnityVersions "$unityVersion" -MatchIndex 0
}
echo "Found unity version is {$queryUnityVersion}"
echo "Found unity version is {$queryUnityVersion} for input {$unityVersion}"
if ($queryUnityVersion -ne 0)
{

View File

@ -1,33 +1,26 @@
name: Package UPM project and deploy
name: Tag Release
on:
workflow_call:
inputs:
build-target:
build-host:
required: true
type: string
build-type:
required: false
default: 'pre-release'
version:
required: true
type: string
# options:
# - major
# - minor
# - patch
# - pre-release
# - build
outputs:
packageversion:
description: "Returns the version of Unity the UPM package requires"
value: ${{ jobs.packageRelease.outputs.packageversion }}
secrets:
GIT_USER_NAME:
required: false
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
packageRelease:
name: Package UPM Project and tag
runs-on: ${{ inputs.build-target }}
runs-on: ${{ inputs.build-host }}
outputs:
packageversion: ${{ steps.getpackageversion.outputs.packageversion }}
steps:
@ -40,6 +33,7 @@ jobs:
shell: pwsh
- uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: recursive
clean: true
token: ${{ secrets.GIT_PAT }}
@ -60,87 +54,26 @@ jobs:
$gitUser = "${{ secrets.GIT_USER_NAME }}"
$gitEmail = "$gitUser@users.noreply.github.com"
}
echo "email $gitUser@users.noreply.github.com"
git config --global user.email "$gitUser@users.noreply.github.com"
git config --global user.name "$gitUser"
shell: pwsh
- id: getpackageversion
name: Bump UPM Package version
- name: Check if Tag Exists
run: |
function UpdateProjectVersionJSON {
param (
[Parameter(Mandatory)]
$type,
$packageFile = 'package.json'
)
<#
Type of build can be one of the following
- 'build' # Build release - 1.0.0-pre-release.0+1
- 'pre-release' # Pre-Release release - 1.0.0-pre-release.1
- 'patch' # Patch release - 1.0.1
- 'minor' # Minor release - 1.1.0
- 'major' # Major release - 2.0.0
#>
if ( -not (Test-Path -Path $packageFile) ) {
Write-Error "Failed to find a valid project manifest at `"$packageFile`""
return $null
}
$packageInfo = (Get-Content $packageFile -Raw) | ConvertFrom-Json
Write-Host "Detected Project Version:" $packageInfo.version
function IfNull($a, $b, $c) { if ($null -eq $a) { return $b } else { return $c } }
$packageSemVer = [System.Management.Automation.SemanticVersion]$packageInfo.version
$majorVersion = if($null -eq $packageSemVer.Major) {0} else {$packageSemVer.Major}
$minorVersion = if($null -eq $packageSemVer.Minor) {0} else {$packageSemVer.Minor}
$patchVersion = if($null -eq $packageSemVer.Patch) {0} else {$packageSemVer.Patch}
$prereleaseVersion = if($null -eq $packageSemVer.PreReleaseLabel) {0} else {$packageSemVer.PreReleaseLabel.Replace('pre-release.','')}
$buildVersion = if($null -eq $packageSemVer.BuildLabel) {0} else {$packageSemVer.BuildLabel}
# work out new version
switch ($type) {
'build' {
[int]$buildVersion += 1
$newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, $patchVersion, "pre-release." + $prereleaseVersion, $buildVersion)
}
'pre-release' {
[int]$prereleaseVersion += 1
$newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, $patchVersion, "pre-release." + $prereleaseVersion)
}
'patch' {
[int]$patchVersion += 1
$newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, $patchVersion)
}
'minor' {
[int]$minorVersion += 1
$newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, 0)
}
'major' {
[int]$majorVersion += 1
$newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, 0, 0)
}
}
Write-Host "Upgrading project version [$packageSemVer] to [$newPackageSemVer]"
# Write out updated package info
$packageInfo.version = $newPackageSemVer.ToString()
$packageInfo | ConvertTo-Json | Set-Content $packageFile
return $packageInfo.version
}
$packageFile = 'package.json'
$result = UpdateProjectVersionJSON("${{ inputs.build-type }}","$packageFile")
if([string]::IsNullOrEmpty($result)) {
echo "Version patch failed"
$tagVersion = "${{ inputs.version }}"
$tags = git tag
echo "Tags found are [$tags], searching for [$tagVersion]"
foreach ($tag in $tags)
{
if($tag.Trim() -eq "$tagVersion")
{
Write-Error "$tagVersion tag already exists"
exit 1
}
echo "packageversion=$result" >> $env:GITHUB_OUTPUT
git add "$packageFile"
git commit -m "Auto increment pre-release version to $result [skip ci]"
git tag -fa "$result" "${GITHUB_SHA}" -m "$result Release"
git push origin --force
}
shell: pwsh
- name: Create tag and push
run: |
$tagVersion = "${{ inputs.version }}"
git tag -fa "v$tagVersion" "${GITHUB_SHA}" -m "v$tagVersion Release [skip ci]"
git push origin "v$tagVersion" --force
shell: pwsh

View File

@ -0,0 +1,181 @@
name: UpVersion Package UPM project and create new tag
on:
workflow_call:
inputs:
build-host:
required: true
type: string
build-type:
required: false
default: 'pre-release'
type: string
# options:
# - major
# - minor
# - patch
# - patch-release
# - pre-release
# - build
target-branch:
required: false
type: string
default: ${{ github.ref }}
createTag:
required: false
type: boolean
default: true
outputs:
packageversion:
description: "Returns the version of Unity the UPM package requires"
value: ${{ jobs.packageRelease.outputs.packageversion }}
secrets:
GIT_PAT:
required: true
jobs:
packageRelease:
name: Package UPM Project and tag
runs-on: ${{ inputs.build-host }}
outputs:
packageversion: ${{ steps.getpackageversion.outputs.packageversion }}
steps:
- name: Script Version
run: |
echo "::group::Script Versioning"
$scriptVersion = "1.0.2"
echo "Build Script Version: $scriptVersion"
echo "::endgroup::"
shell: pwsh
- uses: actions/checkout@v3
with:
ref: ${{ inputs.target-branch }}
fetch-depth: 0
submodules: recursive
clean: true
token: ${{ secrets.GIT_PAT }}
- uses: actions/setup-node@v3
- name: Set Github vars
run: |
if([string]::IsNullOrEmpty('${{ secrets.GIT_USER_NAME }}')){
if([string]::IsNullOrEmpty('${{ secrets.GIT_USER_NAME }}')){
$gitUser = "action"
$gitEmail = "action@github.com"
}
else {
$gitUser = "${GITHUB_ACTOR}"
$gitEmail = "$gitUser@users.noreply.github.com"
}
}
else {
$gitUser = "${{ secrets.GIT_USER_NAME }}"
$gitEmail = "$gitUser@users.noreply.github.com"
}
git config --global user.email "$gitUser@users.noreply.github.com"
git config --global user.name "$gitUser"
shell: pwsh
- id: getpackageversion
name: Bump UPM Package version
run: |
function UpdateProjectVersionJSON {
param (
[Parameter(Mandatory)]
$type,
$packageFile = 'package.json'
)
<#
Type of build can be one of the following
- 'build' # Build release - 1.0.0-pre.0+1
- 'pre-release' # Pre-Release - 1.0.0-pre.1
- 'patch-release' # Patch release - 1.0.1 (reset preview version to current patch, no increase)
- 'patch' # Patch release - 1.0.1
- 'minor' # Minor release - 1.1.0
- 'major' # Major release - 2.0.0
#>
if ( -not (Test-Path -Path $packageFile) ) {
Write-Error "Failed to find a valid project manifest at `"$packageFile`""
return $null
}
$packageInfo = (Get-Content $packageFile -Raw) | ConvertFrom-Json
Write-Host "Detected Project Version:" $packageInfo.version
function IfNull($a, $b, $c) { if ($null -eq $a) { return $b } else { return $c } }
$packageSemVer = [System.Management.Automation.SemanticVersion]$packageInfo.version
$majorVersion = if($null -eq $packageSemVer.Major) {0} else {$packageSemVer.Major}
$minorVersion = if($null -eq $packageSemVer.Minor) {0} else {$packageSemVer.Minor}
$patchVersion = if($null -eq $packageSemVer.Patch) {0} else {$packageSemVer.Patch}
$prereleaseVersion = if($null -eq $packageSemVer.PreReleaseLabel) {0} else {$packageSemVer.PreReleaseLabel.Replace('pre.','')}
$buildVersion = if($null -eq $packageSemVer.BuildLabel) {0} else {$packageSemVer.BuildLabel}
# work out new version
switch ($type) {
'build' {
[int]$buildVersion += 1
$newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, $patchVersion, "pre." + $prereleaseVersion, $buildVersion)
}
'pre-release' {
[int]$prereleaseVersion += 1
$newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, $patchVersion, "pre." + $prereleaseVersion)
}
'patch-release' {
$newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, $patchVersion)
}
'patch' {
[int]$patchVersion += 1
$newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, $patchVersion)
}
'minor' {
[int]$minorVersion += 1
$newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, $minorVersion, 0)
}
'major' {
[int]$majorVersion += 1
$newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($majorVersion, 0, 0)
}
}
Write-Host "Upgrading project version [$packageSemVer] to [$newPackageSemVer]"
# Write out updated package info
$packageInfo.version = $newPackageSemVer.ToString()
$packageInfo | ConvertTo-Json | Set-Content $packageFile
return $packageInfo.version
}
$packageFile = 'package.json'
$result = UpdateProjectVersionJSON("${{ inputs.build-type }}","$packageFile")
if([string]::IsNullOrEmpty($result)) {
echo "Version patch failed"
exit 1
}
git add "$packageFile"
git commit -m "Auto increment pre-release version to $result [skip ci]"
git push origin
echo "packageversion=$result" >> $env:GITHUB_OUTPUT
shell: pwsh
- name: Check if Tag Exists
run: |
$tagVersion = '${{steps.getpackageversion.outputs.packageversion }}'
$tags = git tag
echo "Tags found are [$tags], searching for [$tagVersion]"
foreach ($tag in $tags)
{
if($tag.Trim() -eq "$tagVersion")
{
Write-Error "$tagVersion tag already exists"
exit 1
}
}
shell: pwsh
- name: Publish package tag
if: ${{inputs.createTag == true}}
run: |
$outputVersion = '${{steps.getpackageversion.outputs.packageversion }}'
git tag -fa "v$outputVersion" "${GITHUB_SHA}" -m "v$outputVersion Release"
git push origin "v$outputVersion" --force --tags
shell: pwsh