From a11eff0f510f339803c662423632b4ec342b4888 Mon Sep 17 00:00:00 2001 From: "Simon (Darkside) Jackson" Date: Sun, 26 Nov 2023 18:17:47 +0000 Subject: [PATCH] Add missing workflow --- .../workflows/getunityversionfrompackage.yml | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 .github/workflows/getunityversionfrompackage.yml diff --git a/.github/workflows/getunityversionfrompackage.yml b/.github/workflows/getunityversionfrompackage.yml new file mode 100644 index 0000000..55bfe79 --- /dev/null +++ b/.github/workflows/getunityversionfrompackage.yml @@ -0,0 +1,72 @@ +name: Get the Unity version required 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: + unityversion: + description: "Returns the version of Unity the UPM package requires" + value: ${{ jobs.get_unity_version.outputs.upmunityversion }} + +jobs: + get_unity_version: + name: Get required Unity version from UPM Package + runs-on: ${{ inputs.build-host }} + outputs: + upmunityversion: ${{ steps.getVersion.outputs.packageunityversion }} + 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: + submodules: recursive + clean: true + - id: getVersion + name: 'Get Unity 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::Unity Version UPM check" + + $package_json = Get-Content -Path $versionFile | ConvertFrom-Json + $unityVersion = $package_json.unity + + if($unityVersion.Length -lt 6) { + echo "Error - Detected version is $unityVersion" + echo "Unity version is too short, please check your UPM package Unity setting" + exit 1 + } + + echo "packageunityversion=$unityVersion" >> $env:GITHUB_OUTPUT + + echo "Detected version is $unityVersion" + echo "::endgroup::" + + shell: pwsh \ No newline at end of file