From 9a823060a792a7f3c0bc270183ddd6c22bbcf8c8 Mon Sep 17 00:00:00 2001 From: SimonDarksideJ Date: Thu, 5 Oct 2023 20:35:32 +0100 Subject: [PATCH] Update workflows --- ...=> development-buildandtestupmrelease.yml} | 15 +- .github/workflows/development-publish.yml | 26 +++ .github/workflows/main-publish.yml | 91 +++++++++ .github/workflows/refreshbranch.yml | 43 +++++ .../workflows/rununitybuildmultiversion.yml | 30 +-- .github/workflows/rununitysinglebuild.yml | 17 +- .github/workflows/tagrelease.yml | 131 ++++--------- .github/workflows/upversionandtagrelease.yml | 181 ++++++++++++++++++ 8 files changed, 400 insertions(+), 134 deletions(-) rename .github/workflows/{buildupmpackages.yml => development-buildandtestupmrelease.yml} (65%) create mode 100644 .github/workflows/development-publish.yml create mode 100644 .github/workflows/main-publish.yml create mode 100644 .github/workflows/refreshbranch.yml create mode 100644 .github/workflows/upversionandtagrelease.yml diff --git a/.github/workflows/buildupmpackages.yml b/.github/workflows/development-buildandtestupmrelease.yml similarity index 65% rename from .github/workflows/buildupmpackages.yml rename to .github/workflows/development-buildandtestupmrelease.yml index 01e1795..a61beba 100644 --- a/.github/workflows/buildupmpackages.yml +++ b/.github/workflows/development-buildandtestupmrelease.yml @@ -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 @@ -26,12 +27,4 @@ jobs: Run-Full-Unit-Tests: 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 + uses: ./.github/workflows/rununitybuildmultiversion.yml \ No newline at end of file diff --git a/.github/workflows/development-publish.yml b/.github/workflows/development-publish.yml new file mode 100644 index 0000000..a770e9d --- /dev/null +++ b/.github/workflows/development-publish.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/main-publish.yml b/.github/workflows/main-publish.yml new file mode 100644 index 0000000..9120cb9 --- /dev/null +++ b/.github/workflows/main-publish.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/refreshbranch.yml b/.github/workflows/refreshbranch.yml new file mode 100644 index 0000000..fb8a021 --- /dev/null +++ b/.github/workflows/refreshbranch.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/rununitybuildmultiversion.yml b/.github/workflows/rununitybuildmultiversion.yml index bd98ccf..ffd309c 100644 --- a/.github/workflows/rununitybuildmultiversion.yml +++ b/.github/workflows/rununitybuildmultiversion.yml @@ -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,10 +152,9 @@ 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}" - + $InstalledUnityVersions = unity-hub editors $editorRootPath = unity-hub ip -g echo "Installed unity versions are {$InstalledUnityVersions}" @@ -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 { @@ -456,4 +456,4 @@ jobs: if: always() with: name: unity-build-log - path: Logs/** \ No newline at end of file + path: Logs/** \ No newline at end of file diff --git a/.github/workflows/rununitysinglebuild.yml b/.github/workflows/rununitysinglebuild.yml index 58404ce..d6ba283 100644 --- a/.github/workflows/rununitysinglebuild.yml +++ b/.github/workflows/rununitysinglebuild.yml @@ -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) { @@ -421,4 +420,4 @@ jobs: if: always() with: name: unity-build-log - path: Logs/** \ No newline at end of file + path: Logs/** \ No newline at end of file diff --git a/.github/workflows/tagrelease.yml b/.github/workflows/tagrelease.yml index c690863..d572d76 100644 --- a/.github/workflows/tagrelease.yml +++ b/.github/workflows/tagrelease.yml @@ -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 + version: required: true type: string - build-type: - required: false - default: 'pre-release' - 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 + shell: pwsh + - 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 + $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 } - - $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" - 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 \ No newline at end of file + 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 \ No newline at end of file diff --git a/.github/workflows/upversionandtagrelease.yml b/.github/workflows/upversionandtagrelease.yml new file mode 100644 index 0000000..4e630ba --- /dev/null +++ b/.github/workflows/upversionandtagrelease.yml @@ -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 \ No newline at end of file