diff --git a/.github/workflows/development-buildandtestupmrelease.yml b/.github/workflows/development-buildandtestupmrelease.yml index 4cd985c..e2133b9 100644 --- a/.github/workflows/development-buildandtestupmrelease.yml +++ b/.github/workflows/development-buildandtestupmrelease.yml @@ -1,9 +1,9 @@ name: Build and test UPM packages for platforms, all branches except main on: - # pull_request: - # branches-ignore: - # - 'release' + pull_request: + branches-ignore: + - 'main' # Ignore PRs targeting main # Allows you to run this workflow manually from the Actions tab @@ -13,18 +13,79 @@ concurrency: group: ${{ github.ref }} cancel-in-progress: true +# Ensure default token scopes and inherit org-level secrets via env mapping +permissions: + contents: write + packages: read + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GIT_PAT: ${{ secrets.GIT_PAT }} + 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 - if: github.ref != 'refs/heads/development' - uses: ./.github/workflows/rununitysinglebuild.yml - with: - unityversion: 2020.3 - - # Run Unity multi-version build unit tests defined in the package for the development branch - Run-Full-Unit-Tests: - name: Run Unity Unit Tests - if: github.ref == 'refs/heads/development' - uses: ./.github/workflows/rununitybuildmultiversion.yml \ No newline at end of file + test-unity-build: + name: Test Unity UPM Build + runs-on: ${{ matrix.os }} + if: always() + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + unity-version: + - 2019 + - 2020 + - 2021 + - 2022 + - 6000.0.x + - 6000 + include: + - os: ubuntu-latest + build-targets: StandaloneLinux64, Android + - os: windows-latest + build-targets: StandaloneWindows64 + - os: macos-latest + build-targets: StandaloneOSX, iOS + steps: + - uses: buildalon/unity-setup@v2 + id: unity-setup + with: + version-file: "None" + unity-version: ${{ matrix.unity-version }} # overrides version in version-file + build-targets: ${{ matrix.build-targets }} + + - run: | + echo "Step Outputs:" + echo "steps.unity-setup.unity-hub-path: '${{ steps.unity-setup.outputs.unity-hub-path }}'" + echo "steps.unity-setup.unity-editors: '${{ steps.unity-setup.outputs.unity-editors }}'" + echo "steps.unity-setup.unity-editor-path: '${{ steps.unity-setup.outputs.unity-editor-path }}'" + echo "steps.unity-setup.unity-project-path: '${{ steps.unity-setup.outputs.unity-project-path }}'" + + echo "Environment Variables:" + echo "UNITY_HUB_PATH: '${{ env.UNITY_HUB_PATH }}'" + echo "UNITY_EDITORS: '${{ env.UNITY_EDITORS }}'" + echo "UNITY_EDITOR_PATH: '${{ env.UNITY_EDITOR_PATH }}'" + echo "UNITY_PROJECT_PATH: '${{ env.UNITY_PROJECT_PATH }}'" + + - uses: buildalon/activate-unity-license@v2 + if: runner.environment == 'github-hosted' + with: + license: "Personal" # Choose license type to use [ Personal, Professional, Floating ] + username: ${{ secrets.UNITY_USER}} + password: ${{ secrets.UNITY_ACC}} + + - uses: buildalon/create-unity-project@v2 + id: create-unity-project + with: + project-name: P + + - name: Setup Unity UPM Build + uses: realitycollective/reality-collective-actions/setup-unity-upm-build@v1 + with: + unity-project-path: ${{ steps.create-unity-project.outputs.project-path }} + + - name: Run Unity Build + uses: realitycollective/reality-collective-actions/run-unity-multitarget-build@v1 + with: + unity-editor-path: ${{ steps.unity-setup.outputs.unity-editor-path }} + unity-project-path: ${{ steps.create-unity-project.outputs.project-path }} + build-targets: ${{ matrix.build-targets }} \ No newline at end of file diff --git a/.github/workflows/development-publish.yml b/.github/workflows/development-publish.yml deleted file mode 100644 index a770e9d..0000000 --- a/.github/workflows/development-publish.yml +++ /dev/null @@ -1,26 +0,0 @@ -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/getpackageversionfrompackage.yml b/.github/workflows/getpackageversionfrompackage.yml deleted file mode 100644 index 30d93ae..0000000 --- a/.github/workflows/getpackageversionfrompackage.yml +++ /dev/null @@ -1,70 +0,0 @@ -name: Get the Package version from a UPM Package.json file - -on: - workflow_call: - inputs: - build-host: - required: true - type: string - version-file-path: - description: 'Optional, specify a path to search for the upm package.json file. Use this if validation fails to find a valid package.json file.\n **Note, Version file MUST contain the attribute "Unity" with the full Unity version expected, e.g. "2020.2.3f1"' - type: string - required: false - outputs: - packageversion: - description: "Returns the version of the UPM package" - value: ${{ jobs.get_package_version.outputs.upmpackageversion }} - -jobs: - get_package_version: - name: Get required Package version from UPM Package - runs-on: ${{ inputs.build-host }} - outputs: - upmpackageversion: ${{ steps.getVersion.outputs.packageversion }} - 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@v4 - with: - submodules: recursive - clean: true - - id: getVersion - name: 'Get Package Version Number' - run: | - echo "::group::Validating input" - - $versionFile = "${{ inputs.version-file-path }}" - if([string]::IsNullOrEmpty($versionFile)) - { - echo 'version input was empty, using default' - $versionFile = 'package.json' - } - echo 'Checking for project json at $versionFile' - - if ( -not (Test-Path -Path $versionFile) ) { - Write-Error "Failed to find a valid package.json file" - exit 1 - } - - echo "::endgroup::" - - echo "::group::Package Version UPM check" - - $package_json = Get-Content -Path $versionFile | ConvertFrom-Json - $packageVersion = $package_json.version - - if([string]::IsNullOrEmpty($packageVersion)) { - Write-Error "Project.json version number does not exist or is empty" - exit 1 - } - - echo "packageversion=$packageVersion" >> $env:GITHUB_OUTPUT - - echo "Detected version is $packageVersion" - echo "::endgroup::" - shell: pwsh \ No newline at end of file diff --git a/.github/workflows/main-publish.yml b/.github/workflows/main-publish.yml deleted file mode 100644 index f667dc6..0000000 --- a/.github/workflows/main-publish.yml +++ /dev/null @@ -1,91 +0,0 @@ -name: Publish main branch and increment version - -on: - pull_request: - types: - - closed - branches: - - release - -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 deleted file mode 100644 index fb8a021..0000000 --- a/.github/workflows/refreshbranch.yml +++ /dev/null @@ -1,43 +0,0 @@ -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 deleted file mode 100644 index 50e88d7..0000000 --- a/.github/workflows/rununitybuildmultiversion.yml +++ /dev/null @@ -1,486 +0,0 @@ -name: Run Unity Builds - -on: - workflow_call: - inputs: - dependencies: - description: "json array of dependencies and their targets" - required: false - type: string - -jobs: - run_build: - name: Run Unity Build process - runs-on: ${{ matrix.os }} - strategy: - matrix: - include: - - os: windows - unityVersion: 2019.4 - build-target: Android - - os: macOS - unityVersion: 2019.4 - build-target: iOS - - os: windows - unityVersion: 2019.4 - build-target: StandaloneWindows64 - - os: windows - unityVersion: 2019.4 - build-target: WSAPlayer - - os: windows - unityVersion: 2020.3 - build-target: Android - - os: macOS - unityVersion: 2020.3 - build-target: iOS - - os: windows - unityVersion: 2020.3 - build-target: StandaloneWindows64 - - os: windows - unityVersion: 2020.3 - build-target: WSAPlayer - - os: windows - unityVersion: 2021.3 - build-target: Android - - os: macOS - unityVersion: 2021.3 - build-target: iOS - - os: windows - unityVersion: 2021.3 - build-target: StandaloneWindows64 - - os: windows - unityVersion: 2021.3 - build-target: WSAPlayer - - os: windows - unityVersion: 2022.3 - build-target: Android - - os: macOS - unityVersion: 2022.3 - build-target: iOS - - os: windows - unityVersion: 2022.3 - build-target: StandaloneWindows64 - - os: windows - unityVersion: 2022.3 - build-target: WSAPlayer - - os: windows - unityVersion: 6000.0 - build-target: Android - - os: windows - unityVersion: 6000.0 - build-target: StandaloneWindows64 - - os: windows - unityVersion: 6000.0 - build-target: WSAPlayer - - os: macos - unityVersion: 6000.0 - build-target: iOS - - os: macos - unityVersion: 6000.0 - build-target: StandaloneOSX - - 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@v4 - with: - submodules: recursive - clean: true - - - id: build - name: 'Run Unity Builds' - run: | - $unityVersion = '${{ matrix.unityVersion }}' - $unityMajorVersion = $unityVersion.Substring(0, 4) - - echo "::group::Set Hub and editor locations" - - ## Set Hub and editor locations - if ( (-not $global:PSVersionTable.Platform) -or ($global:PSVersionTable.Platform -eq "Win32NT") ) - { - $hubPath = "C:\Program Files\Unity Hub\Unity Hub.exe" - - #"Unity Hub.exe" -- --headless help - #. 'C:\Program Files\Unity Hub\Unity Hub.exe' -- --headless help - function unity-hub - { - & $hubPath -- --headless $args.Split(" ") | Out-String - } - function unity-hub-raw - { - & $hubPath -- --headless $args.Split(" ") | Out-String -NoNewline - } - } - elseif ( $global:PSVersionTable.OS.Contains("Darwin") ) - { - $hubPath = "/Applications/Unity Hub.app/Contents/MacOS/Unity Hub" - - # /Applications/Unity\ Hub.app/Contents/MacOS/Unity\ Hub -- --headless help - function unity-hub - { - & $hubPath -- --headless $args.Split(" ") | Out-String - } - function unity-hub-raw - { - & $hubPath -- --headless $args.Split(" ") | Out-String -NoNewline - } - } - elseif ( $global:PSVersionTable.OS.Contains("Linux") ) - { - $hubPath = "$HOME/Unity Hub/UnityHub.AppImage" - - # /UnityHub.AppImage --headless help - # xvfb-run --auto-servernum "$HOME/Unity Hub/UnityHub.AppImage" --headless help - function unity-hub - { - xvfb-run --auto-servernum "$hubPath" --headless $args.Split(" ") - } - function unity-hub-raw - { - xvfb-run --auto-servernum "$hubPath" --headless $args.Split(" ") - } - } - - echo "::endgroup::" - - echo "::group::Get String function to query a string for a value" - - function GetString($InputString, $InputPattern, $MatchIndex) - { - $regExResult = $InputString | Select-String -Pattern $InputPattern - if($regExResult.Length -gt 0) - { - return $regExResult.Matches[$MatchIndex].Value - } - else - { - return 0 - } - } - - function Get-LetterCount - { - Param ([string]$string) - return $string.Length - } - echo "::endgroup::" - - echo "::group::Get Installed Unity version based on Matrix" - echo "Unity hub path is {$hubPath}" - echo "Requested unity version is {$unityVersion}" - - $InstalledUnityVersions = unity-hub editors - $editorRootPath = unity-hub-raw ip -g - echo "Installed unity versions are {$InstalledUnityVersions}" - echo "Unity install path is {$editorRootPath}" - - $versionLength = Get-LetterCount $unityVersion - if ($versionLength -eq 4) { - $queryUnityVersion = GetString $InstalledUnityVersions "$unityVersion.{4,7}" -MatchIndex 0 - } - elseif ($versionLength -eq 6) { - $queryUnityVersion = GetString $InstalledUnityVersions "$unityVersion.{4,5}" -MatchIndex 0 - } - else { - $queryUnityVersion = GetString $InstalledUnityVersions "$unityVersion" -MatchIndex 0 - } - - echo "Found unity version is {$queryUnityVersion} for input {$unityVersion}" - - if ($queryUnityVersion -ne 0) - { - $unityVersion = $queryUnityVersion.Trim(","," ").Trim() - echo "Long Unity version is $unityVersion" - } - else - { - echo "Unity $unityVersion not found on this machine, skipping" - exit 0 - } - - echo "::endgroup::" - - echo "::group::Search for Editor if not found" - $checkPath = Join-Path $editorRootPath $unityVersion - echo "Testing for editor at $checkPath" - while (-not (Test-Path "$checkPath")) { - $source = $unityVersion.Replace("f1","") - $newversion = $source.Split(".") - $newversion[2] = [int]$newversion[2] - 1 - if ([int]$newversion[2] -lt 1) { - echo "Unity ${{ matrix.unityVersion }} not found on this machine, skipping" - exit 0 - } - $newunityVersion = "{0}.{1}.{2}f1" -f $newversion[0],$newversion[1],$newversion[2] - echo "Unity $unityVersion not found on this machine, trying $newunityVersion" - $unityVersion = $newunityVersion - $checkPath = Join-Path $editorRootPath $unityVersion - } - echo "::endgroup::" - - echo "::group::Set editor locations" - - if ( (-not $global:PSVersionTable.Platform) -or ($global:PSVersionTable.Platform -eq "Win32NT") ) { - echo 'Building using Windows' - $editorFileEx = "/Editor/Unity.exe" - $editorrunpath = Join-Path $editorRootPath $unityVersion $editorFileEx - - function unity-editor { - #$p = Start-Process -Verbose -NoNewWindow -PassThru -Wait -FilePath "$editorrunpath" -ArgumentList (@(' -batchmode') + $args.Split(" ")) - & $editorrunpath -batchmode $args.Split(" ") | Out-String - } - } - elseif ( $global:PSVersionTable.OS.Contains("Darwin") ) { - echo 'Building using Mac' - $editorFileEx = "/Unity.app/Contents/MacOS/Unity" - $editorrunpath = Join-Path $editorRootPath $unityVersion $editorFileEx - - function unity-editor { - #$p = Start-Process -Verbose -NoNewWindow -PassThru -Wait -FilePath "$editorrunpath" -ArgumentList (@(' -batchmode') + $args.Split(" ")) - & $editorrunpath -batchmode $args.Split(" ") | Out-String - } - } - elseif ( $global:PSVersionTable.OS.Contains("Linux") ) { - echo 'Building using Linux' - $editorFileEx = "/Editor/Unity" - $editorrunpath = Join-Path $editorRootPath $unityVersion $editorFileEx - - function unity-editor { - xvfb-run --auto-servernum "$editorrunpath" -batchmode $args.Split(" ") - } - } - else - { - echo 'Unknown build platform' - } - - echo "::endgroup::" - - echo "::group::Test Unity version is installed" - - if ( -not (Test-Path "$editorrunpath") ) - { - Write-Error "Editor not Found for $unityVersion" - exit 1 - } - else { - echo "Editor Path is {$editorrunpath}" - } - - echo "::endgroup::" - - echo "::group::Setup logging and run Unit tests" - - # Log detail - $logDirectory = "Logs" - if (Test-Path -Path $logDirectory) { - echo "Clearing logs from a previous run" - Remove-item $logDirectory -recurse - } - - $logDirectory = New-Item -ItemType Directory -Force -Path $logDirectory | Select-Object - - echo "Log Directory: $logDirectory" - $date = Get-Date -Format "yyyyMMddTHHmmss" - - # If run manually, the Refname is actually blank, so just use date - if([string]::IsNullOrEmpty(${GITHUB_REF_NAME})) { - $logName = Join-Path $logDirectory $date - }else { - $logName = Join-Path $logDirectory ${GITHUB_REF_NAME}-$date - } - - $logPath = "$unityMajorVersion_${{ matrix.build-target }}_$logName.log" - $testsLogPath = "$unityMajorVersion_${{ matrix.build-target }}_$logName-tests.xml" - - echo "Logpath [$logPath]" - echo "TestsPath [$testsLogPath]" - echo "::endgroup::" - - echo "::group::Grouping Package in a UPM folder" - - $UPMFolderName = 'u' - - if ( -not (Test-Path '$UPMFolderName') ) - { - New-Item $UPMFolderName -ItemType Directory - } - - Move-Item -Path * -Destination $UPMFolderName -exclude $UPMFolderName - - echo "::endgroup::" - - echo "::group::Creating Temp Unity project" - - $TempUnityProjectName = 'P' - - unity-editor '-createProject' $TempUnityProjectName '-logFile' $logPath '-quit' - - if ( -not (Test-Path "$TempUnityProjectName") ) - { - $ProjectPath = Get-Location - Write-Error "Editor failed to create project not Found $ProjectPath/$TempUnityProjectName" - exit 1 - } - else { - $ProjectPath = Get-Location - echo "Editor project created at $ProjectPath/$TempUnityProjectName" - } - - $destinationPath = Join-Path $TempUnityProjectName 'packages' - Move-Item -Path $UPMFolderName -Destination $destinationPath - - echo "::endgroup::" - - echo "::group::If required, clone dependencies in to test project" - - <# Dependency option requires specific inputs - - * A dependency input string in json format, listing each dependency by name and git url, e.g. - $dependencies = '[{"ASADependencies": "github.com/SimonDarksideJ/upmGithubActionsTests.git"}]' - *Note, remove the https:// portion to allow using a PAT to access the repo - The Name of the dependency should ALSO MATCH the name of the branch on the repo where the dependency is held (files intended for the packages folder) - - * Additionally, if Manifest entries are required, then a manifest file with those dependencies (and ONLY the new dependancies) should also be in the dependency branch named the same as the branch name - e.g. "ASADependencies.json" - keep the same structure, but only the dependancy entries - - !!Does NOT support additional scoped registries at this time! #> - - echo "---------------------------------------------" - echo "Read dependancy input value" - if([string]::IsNullOrEmpty('${{ inputs.dependencies }}')) - { - echo "No dependencies provided" - echo "input ${{ inputs.dependencies }}" - echo "------------------------------" - } - else { - echo "dependencies provided, validating" - - # Read dependancy input value - $dependencies = '${{ inputs.dependencies }}' - - if([string]::IsNullOrEmpty('${{ github.actor }}') -or [string]::IsNullOrEmpty('${{ secrets.GITHUB_TOKEN }}')){ - echo "" - echo "Insufficient credentials supplied to activate the workflow" - exit 1 - } - - echo "---------------------------------------------" - echo "Read dependancy input values as json" - $JSONdependencies = $dependencies | ConvertFrom-Json - - echo $JSONdependencies - - # Read current Manifest json - $manifestPath = Join-Path $destinationPath 'manifest.json' - $projectManifest = Get-Content -Path $manifestPath | ConvertFrom-Json - $strArray = $projectManifest.dependencies.PsObject.Properties | ForEach-Object {"$($_.Name)@$($_.Value),"} - - echo "---------------------------------------------" - echo "Loop through new dependancies and add them to the project Manifest" - foreach($dependency in $JSONdependencies){ - $dependency.PsObject.Properties | ForEach-Object -Process { - $dependencyName = $_.Name - $dependencyPath = $dependencyName.Replace("/","_") - $dependencyURL = $_.Value - echo "---------------------------------------------" - echo "Cloning dependency - Name [$dependencyName] - Path [$dependencyPath] - URL [$dependencyURL]" - $cloneURL = "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@$dependencyURL" - - echo "cloning $dependencyName from $dependencyURL and moving to $destinationPath" - echo "git path - $cloneURL" - - # Clone Dependancy repo to destination folder - git clone -b $dependencyName --single-branch $cloneURL $dependencyPath - - if( -not (Test-Path -Path "$dependencyPath")){ - echo "Unable to clone $dependencyName from $dependencyURL" - exit 1 - } - - # Move files from clone path into packages folder, if the dependency contains a UPM package then move the entire folder and not just its contents - if (Test-Path -Path "$dependencyPath/package.json") { - $package_json = Get-Content -Path $dependencyPath/package.json | ConvertFrom-Json - $packageName = $package_json.name - Rename-Item $dependencyPath $packageName - echo "Moving whole $packageName UPM package to $destinationPath" - Move-Item -Path "$packageName" -Destination $destinationPath - } - else { - echo "Moving the contents of $dependencyName into the $destinationPath folder" - Move-Item -Path "$dependencyPath/*" -Destination $destinationPath - } - - # Get Dependency manifest entries (if applicable) - if (Test-Path -Path "$destinationPath/$dependencyName.json") { - $dependencyManifest = Get-Content -Path "$destinationPath/$dependencyName.json" | ConvertFrom-Json - $dependencyManifest.dependencies.PsObject.Properties | ForEach-Object { - $strArray += "$($_.Name)@$($_.Value)," - } - } - else{ - echo "No denendency json found called $destinationPath/$dependencyName.json, skipping adding additional manifest entries" - } - } - } - echo "---------------------------------------------" - - # Reformat combined dependancies list - $strArray = $strArray.Trim(",") | ConvertTo-Json - $strArray = $strArray.Replace("@",'":"').Replace("[","{").Replace("]","}") - $strArrayObject = $strArray | ConvertFrom-Json - - # Save manifest back to project - $projectManifest.dependencies = $strArrayObject - $projectManifest | ConvertTo-Json | Set-Content -Path "$destinationPath/manifest.json" - - echo "Project updated with the following dependencies" - echo "-----------------------------------------------" - echo $projectManifest - } - - echo "::endgroup::" - - echo "::group::Run build" - - echo "---------------------------------------------" - echo "Start Testing" - echo "Unity Command\n[unity-editor -projectPath $TempUnityProjectName -logfile $logPath -batchmode -nographics -quit -buildTarget ${{ matrix.build-target }}]" - - unity-editor -projectPath $TempUnityProjectName -logfile $logPath -batchmode -nographics -quit -buildTarget ${{ matrix.build-target }} - - echo "---------------------------------------------" - echo "::group::Unity Unit tests Results" - if (Test-Path $testsLogPath) { - echo "Test Run results for ${GITHUB_REPOSITORY} Branch ${GITHUB_REF}" - echo "" - Select-Xml -Path $testsLogPath -XPath '/test-run/test-suite' | ForEach-Object { "Name: " +$_.Node.name, ", Result: " + $_.Node.result, ", Total Tests: " + $_.Node.total, ", Passed: " + $_.Node.passed, ", Failed: " + $_.Node.failed, ", Skipped: " + $_.Node.skipped } - } - else { - echo "No test results found for ${GITHUB_REPOSITORY} Branch ${GITHUB_REF} at $testsLogPath" - echo "" - } - echo "::endgroup::" - - if($LASTEXITCODE -ne '0'){ - echo "::group::Unity Unit tests errors" - $exitCode = $testResult.ExitCode - Get-Content $logPath - echo "Build failed due to errors ($LASTEXITCODE), please check the log at $logPath" - echo "::endgroup::" - - exit $LASTEXITCODE - } - - shell: pwsh - - uses: actions/upload-artifact@v3 - if: always() - with: - name: unity-build-log-${{ matrix.unityVersion }}-${{ matrix.build-target }} - path: Logs/** \ No newline at end of file diff --git a/.github/workflows/rununitysinglebuild.yml b/.github/workflows/rununitysinglebuild.yml deleted file mode 100644 index 7d792f4..0000000 --- a/.github/workflows/rununitysinglebuild.yml +++ /dev/null @@ -1,424 +0,0 @@ -name: Run Limited Unity Builds - -on: - workflow_call: - inputs: - unityVersion: - description: "The version of Unity to validate on" - required: true - type: string - dependencies: - description: "json array of dependencies and their targets" - required: false - type: string - -jobs: - run_build: - name: Run Unity Build process - runs-on: ${{ matrix.os }} - strategy: - matrix: - include: - - os: macOS - build-target: iOS - - os: windows - build-target: Android - - os: windows - build-target: StandaloneWindows64 - - os: windows - build-target: WSAPlayer - - 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@v4 - with: - submodules: recursive - clean: true - - id: build - name: 'Run Unity Builds' - run: | - $unityVersion = '${{ inputs.unityVersion }}' - - echo "::group::Set Hub and editor locations" - - ## Set Hub and editor locations - if ( (-not $global:PSVersionTable.Platform) -or ($global:PSVersionTable.Platform -eq "Win32NT") ) - { - $hubPath = "C:\Program Files\Unity Hub\Unity Hub.exe" - $editorRootPath = "C:\Program Files\Unity\Hub\Editor\" - - #"Unity Hub.exe" -- --headless help - #. 'C:\Program Files\Unity Hub\Unity Hub.exe' -- --headless help - function unity-hub - { - & $hubPath -- --headless $args.Split(" ") | Out-String -NoNewline - } - } - elseif ( $global:PSVersionTable.OS.Contains("Darwin") ) - { - $hubPath = "/Applications/Unity Hub.app/Contents/MacOS/Unity Hub" - $editorRootPath = "/Applications/Unity/Hub/Editor/" - - # /Applications/Unity\ Hub.app/Contents/MacOS/Unity\ Hub -- --headless help - function unity-hub - { - & $hubPath -- --headless $args.Split(" ") | Out-String -NoNewline - } - } - elseif ( $global:PSVersionTable.OS.Contains("Linux") ) - { - $hubPath = "$HOME/Unity Hub/UnityHub.AppImage" - $editorRootPath = "$HOME/Unity/Hub/Editor/" - - # /UnityHub.AppImage --headless help - # xvfb-run --auto-servernum "$HOME/Unity Hub/UnityHub.AppImage" --headless help - function unity-hub - { - xvfb-run --auto-servernum "$hubPath" --headless $args.Split(" ") - } - } - - echo "::endgroup::" - - echo "::group::Get String function to query a string for a value" - - function GetString($InputString, $InputPattern, $MatchIndex) - { - $regExResult = $InputString | Select-String -Pattern $InputPattern - if($regExResult.Length -gt 0) - { - return $regExResult.Matches[$MatchIndex].Value - } - else - { - return 0 - } - } - - function Get-LetterCount - { - Param ([string]$string) - return $string.Length - } - echo "::endgroup::" - - echo "::group::Find Installed Unity version based on input" - 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}" - echo "Unity install path is {$editorRootPath}" - - $versionLength = Get-LetterCount $unityVersion - if ($versionLength -eq 4) { - $queryUnityVersion = GetString $InstalledUnityVersions "$unityVersion.{4,7}" -MatchIndex 0 - } - elseif ($versionLength -eq 6) { - $queryUnityVersion = GetString $InstalledUnityVersions "$unityVersion.{4,5}" -MatchIndex 0 - } - else { - $queryUnityVersion = GetString $InstalledUnityVersions "$unityVersion" -MatchIndex 0 - } - - echo "Found unity version is {$queryUnityVersion} for input {$unityVersion}" - - if ($queryUnityVersion -ne 0) - { - $unityVersion = $queryUnityVersion.Trim(","," ").Trim() - echo "Long Unity version is $unityVersion" - } - else - { - echo "Unity $unityVersion not found on this machine, skipping" - exit 0 - } - - echo "::endgroup::" - - echo "::group::Search for Editor if not found" - $checkPath = Join-Path $editorRootPath $unityVersion - echo "Testing for editor at $checkPath" - while (-not (Test-Path "$checkPath")) { - $source = $unityVersion.Replace("f1","") - $newversion = $source.Split(".") - $newversion[2] = [int]$newversion[2] - 1 - if ([int]$newversion[2] -lt 1) { - echo "Unity ${{ inputs.unityVersion }} not found on this machine, skipping" - exit 0 - } - $newunityVersion = "{0}.{1}.{2}f1" -f $newversion[0],$newversion[1],$newversion[2] - echo "Unity $unityVersion not found on this machine, trying $newunityVersion" - $unityVersion = $newunityVersion - $checkPath = Join-Path $editorRootPath $unityVersion - } - echo "::endgroup::" - - echo "::group::Set editor locations" - - if ( (-not $global:PSVersionTable.Platform) -or ($global:PSVersionTable.Platform -eq "Win32NT") ) { - echo 'Building using Windows' - $editorFileEx = "/Editor/Unity.exe" - $editorrunpath = Join-Path $editorRootPath $unityVersion $editorFileEx - - function unity-editor { - #$p = Start-Process -Verbose -NoNewWindow -PassThru -Wait -FilePath "$editorrunpath" -ArgumentList (@(' -batchmode') + $args.Split(" ")) - & $editorrunpath -batchmode $args.Split(" ") | Out-String - } - } - elseif ( $global:PSVersionTable.OS.Contains("Darwin") ) { - echo 'Building using Mac' - $editorFileEx = "/Unity.app/Contents/MacOS/Unity" - $editorrunpath = Join-Path $editorRootPath $unityVersion $editorFileEx - - function unity-editor { - #$p = Start-Process -Verbose -NoNewWindow -PassThru -Wait -FilePath "$editorrunpath" -ArgumentList (@(' -batchmode') + $args.Split(" ")) - & $editorrunpath -batchmode $args.Split(" ") | Out-String - } - } - elseif ( $global:PSVersionTable.OS.Contains("Linux") ) { - echo 'Building using Linux' - $editorFileEx = "/Editor/Unity" - $editorrunpath = Join-Path $editorRootPath $unityVersion $editorFileEx - - function unity-editor { - xvfb-run --auto-servernum "$editorrunpath" -batchmode $args.Split(" ") - } - } - else - { - echo 'Unknown build platform' - } - - echo "::endgroup::" - - echo "::group::Test Unity version is installed" - - if ( -not (Test-Path "$editorrunpath") ) - { - Write-Error "Editor not Found for $unityVersion" - exit 1 - } - else { - echo "Editor Path is {$editorrunpath}" - } - - echo "::endgroup::" - - echo "::group::Setup logging and run Unit tests" - - # Log detail - $logDirectory = "Logs" - if (Test-Path -Path $logDirectory) { - echo "Clearing logs from a previous run" - Remove-item $logDirectory -recurse - } - - $logDirectory = New-Item -ItemType Directory -Force -Path $logDirectory | Select-Object - - echo "Log Directory: $logDirectory" - $date = Get-Date -Format "yyyyMMddTHHmmss" - - # If run manually, the Refname is actually blank, so just use date - if([string]::IsNullOrEmpty(${GITHUB_REF_NAME})) { - $logName = Join-Path $logDirectory $date - }else { - $logName = Join-Path $logDirectory ${GITHUB_REF_NAME}-$date - } - - $logPath = "$logName.log" - $testsLogPath = "$logName-tests.xml" - - echo "Logpath [$logPath]" - echo "TestsPath [$testsLogPath]" - echo "::endgroup::" - - echo "::group::Grouping Package in a UPM folder" - - $UPMFolderName = 'u' - - if ( -not (Test-Path '$UPMFolderName') ) - { - New-Item $UPMFolderName -ItemType Directory - } - - Move-Item -Path * -Destination $UPMFolderName -exclude $UPMFolderName - - echo "::endgroup::" - - echo "::group::Creating Temp Unity project" - - $TempUnityProjectName = 'P' - - unity-editor '-createProject' $TempUnityProjectName '-logFile' $logPath '-quit' - - if ( -not (Test-Path "$TempUnityProjectName") ) - { - $ProjectPath = Get-Location - Write-Error "Editor failed to create project not Found $ProjectPath/$TempUnityProjectName" - exit 1 - } - else { - $ProjectPath = Get-Location - echo "Editor project created at $ProjectPath/$TempUnityProjectName" - } - - $destinationPath = Join-Path $TempUnityProjectName 'packages' - Move-Item -Path $UPMFolderName -Destination $destinationPath - - echo "::endgroup::" - - echo "::group::If required, clone dependencies in to test project" - - <# Dependency option requires specific inputs - - * A dependency input string in json format, listing each dependency by name and git url, e.g. - $dependencies = '[{"ASADependencies": "github.com/SimonDarksideJ/upmGithubActionsTests.git"}]' - *Note, remove the https:// portion to allow using a PAT to access the repo - The Name of the dependency should ALSO MATCH the name of the branch on the repo where the dependency is held (files intended for the packages folder) - - * Additionally, if Manifest entries are required, then a manifest file with those dependencies (and ONLY the new dependancies) should also be in the dependency branch named the same as the branch name - e.g. "ASADependencies.json" - keep the same structure, but only the dependancy entries - - !!Does NOT support additional scoped registries at this time! #> - - echo "---------------------------------------------" - echo "Read dependancy input value" - if([string]::IsNullOrEmpty('${{ inputs.dependencies }}')) - { - echo "No dependencies provided" - echo "input ${{ inputs.dependencies }}" - echo "------------------------------" - } - else { - echo "dependencies provided, validating" - - # Read dependancy input value - $dependencies = '${{ inputs.dependencies }}' - - if([string]::IsNullOrEmpty('${{ github.actor }}') -or [string]::IsNullOrEmpty('${{ secrets.GITHUB_TOKEN }}')){ - echo "" - echo "Insufficient credentials supplied to activate the workflow" - exit 1 - } - - echo "---------------------------------------------" - echo "Read dependancy input values as json" - $JSONdependencies = $dependencies | ConvertFrom-Json - - echo $JSONdependencies - - # Read current Manifest json - $manifestPath = Join-Path $destinationPath 'manifest.json' - $projectManifest = Get-Content -Path $manifestPath | ConvertFrom-Json - $strArray = $projectManifest.dependencies.PsObject.Properties | ForEach-Object {"$($_.Name)@$($_.Value),"} - - echo "---------------------------------------------" - echo "Loop through new dependancies and add them to the project Manifest" - foreach($dependency in $JSONdependencies){ - $dependency.PsObject.Properties | ForEach-Object -Process { - $dependencyName = $_.Name - $dependencyPath = $dependencyName.Replace("/","_") - $dependencyURL = $_.Value - echo "---------------------------------------------" - echo "Cloning dependency - Name [$dependencyName] - Path [$dependencyPath] - URL [$dependencyURL]" - $cloneURL = "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@$dependencyURL" - - echo "cloning $dependencyName from $dependencyURL and moving to $destinationPath" - echo "git path - $cloneURL" - - # Clone Dependancy repo to destination folder - git clone -b $dependencyName --single-branch $cloneURL $dependencyPath - - if( -not (Test-Path -Path "$dependencyPath")){ - echo "Unable to clone $dependencyName from $dependencyURL" - exit 1 - } - - # Move files from clone path into packages folder, if the dependency contains a UPM package then move the entire folder and not just its contents - if (Test-Path -Path "$dependencyPath/package.json") { - $package_json = Get-Content -Path $dependencyPath/package.json | ConvertFrom-Json - $packageName = $package_json.name - Rename-Item $dependencyPath $packageName - echo "Moving whole $packageName UPM package to $destinationPath" - Move-Item -Path "$packageName" -Destination $destinationPath - } - else { - echo "Moving the contents of $dependencyName into the $destinationPath folder" - Move-Item -Path "$dependencyPath/*" -Destination $destinationPath - } - - # Get Dependency manifest entries (if applicable) - if (Test-Path -Path "$destinationPath/$dependencyName.json") { - $dependencyManifest = Get-Content -Path "$destinationPath/$dependencyName.json" | ConvertFrom-Json - $dependencyManifest.dependencies.PsObject.Properties | ForEach-Object { - $strArray += "$($_.Name)@$($_.Value)," - } - } - else{ - echo "No denendency json found called $destinationPath/$dependencyName.json, skipping adding additional manifest entries" - } - } - } - echo "---------------------------------------------" - - # Reformat combined dependancies list - $strArray = $strArray.Trim(",") | ConvertTo-Json - $strArray = $strArray.Replace("@",'":"').Replace("[","{").Replace("]","}") - $strArrayObject = $strArray | ConvertFrom-Json - - # Save manifest back to project - $projectManifest.dependencies = $strArrayObject - $projectManifest | ConvertTo-Json | Set-Content -Path "$destinationPath/manifest.json" - - echo "Project updated with the following dependencies" - echo "-----------------------------------------------" - echo $projectManifest - } - - echo "::endgroup::" - - echo "::group::Run build" - - echo "---------------------------------------------" - echo "Start Testing" - echo "Unity Command\n[unity-editor -projectPath $TempUnityProjectName -logfile $logPath -batchmode -nographics -quit -buildTarget ${{ matrix.build-target }}]" - - unity-editor -projectPath $TempUnityProjectName -logfile $logPath -batchmode -nographics -quit -buildTarget ${{ matrix.build-target }} - - echo "---------------------------------------------" - echo "::group::Unity Unit tests Results" - if (Test-Path $testsLogPath) { - echo "Test Run results for ${GITHUB_REPOSITORY} Branch ${GITHUB_REF}" - echo "" - Select-Xml -Path $testsLogPath -XPath '/test-run/test-suite' | ForEach-Object { "Name: " +$_.Node.name, ", Result: " + $_.Node.result, ", Total Tests: " + $_.Node.total, ", Passed: " + $_.Node.passed, ", Failed: " + $_.Node.failed, ", Skipped: " + $_.Node.skipped } - } - else { - echo "No test results found for ${GITHUB_REPOSITORY} Branch ${GITHUB_REF} at $testsLogPath" - echo "" - } - echo "::endgroup::" - - if($LASTEXITCODE -ne '0'){ - echo "::group::Unity Unit tests errors" - $exitCode = $testResult.ExitCode - Get-Content $logPath - echo "Build failed due to errors ($LASTEXITCODE), please check the log at $logPath" - echo "::endgroup::" - - exit $LASTEXITCODE - } - - shell: pwsh - - uses: actions/upload-artifact@v4 - if: always() - with: - name: unity-build-log-${{ matrix.build-target }} - path: Logs/** \ No newline at end of file diff --git a/.github/workflows/tagrelease.yml b/.github/workflows/tagrelease.yml deleted file mode 100644 index fddc382..0000000 --- a/.github/workflows/tagrelease.yml +++ /dev/null @@ -1,79 +0,0 @@ -name: Tag Release - -on: - workflow_call: - inputs: - build-host: - required: true - type: string - version: - required: true - type: string - - # 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-host }} - outputs: - packageversion: ${{ steps.getpackageversion.outputs.packageversion }} - steps: - - name: Script Version - run: | - echo "::group::Script Versioning" - $scriptVersion = "1.0.3" - echo "Build Script Version: $scriptVersion" - echo "::endgroup::" - shell: pwsh - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - submodules: recursive - clean: true - token: ${{ secrets.GIT_PAT }} - - uses: actions/setup-node@v4 - - 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 - - name: Check if Tag Exists - run: | - $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 - } - } - shell: pwsh - - name: Create tag and push - run: | - $tagVersion = "${{ inputs.version }}" - git tag -fa "v$tagVersion" -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 deleted file mode 100644 index 8c8882b..0000000 --- a/.github/workflows/upversionandtagrelease.yml +++ /dev/null @@ -1,181 +0,0 @@ -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_USER_NAME: - required: false - -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.3" - echo "Build Script Version: $scriptVersion" - echo "::endgroup::" - shell: pwsh - - uses: actions/checkout@v4 - with: - ref: ${{ inputs.target-branch }} - fetch-depth: 0 - submodules: recursive - clean: true - token: ${{ secrets.GIT_PAT }} - - uses: actions/setup-node@v4 - - 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" -m "v$outputVersion Release" - git push origin "v$outputVersion" --force --tags - shell: pwsh \ No newline at end of file