2023-11-27 02:27:15 +08:00
name : Get the Package version from a UPM Package.json file
2023-11-27 02:17:47 +08:00
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 :
2023-11-27 02:27:15 +08:00
packageversion :
description : "Returns the version of the UPM package"
value : ${{ jobs.get_package_version.outputs.upmpackageversion }}
2023-11-27 02:17:47 +08:00
jobs :
2023-11-27 02:27:15 +08:00
get_package_version :
name : Get required Package version from UPM Package
2023-11-27 02:17:47 +08:00
runs-on : ${{ inputs.build-host }}
outputs :
2023-11-27 02:27:15 +08:00
upmpackageversion : ${{ steps.getVersion.outputs.packageversion }}
2023-11-27 02:17:47 +08:00
steps :
- name : Script Version
run : |
echo "::group::Script Versioning"
2024-10-04 19:26:05 +08:00
$scriptVersion = "1.0.1"
2023-11-27 02:17:47 +08:00
echo "Build Script Version: $scriptVersion"
echo "::endgroup::"
shell : pwsh
2024-10-04 19:26:05 +08:00
- uses : actions/checkout@v4
2023-11-27 02:17:47 +08:00
with :
submodules : recursive
clean : true
- id : getVersion
2023-11-27 02:27:15 +08:00
name : 'Get Package Version Number'
2023-11-27 02:17:47 +08:00
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::"
2023-11-27 02:27:15 +08:00
echo "::group::Package Version UPM check"
2023-11-27 02:17:47 +08:00
$package_json = Get-Content -Path $versionFile | ConvertFrom-Json
2023-11-27 02:27:15 +08:00
$packageVersion = $package_json.version
2023-11-27 02:17:47 +08:00
2023-11-27 02:27:15 +08:00
if([string]::IsNullOrEmpty($packageVersion)) {
Write-Error "Project.json version number does not exist or is empty"
2023-11-27 02:17:47 +08:00
exit 1
}
2023-11-27 02:27:15 +08:00
echo "packageversion=$packageVersion" >> $env:GITHUB_OUTPUT
2023-11-27 02:17:47 +08:00
2023-11-27 02:27:15 +08:00
echo "Detected version is $packageVersion"
2023-11-27 02:17:47 +08:00
echo "::endgroup::"
shell : pwsh