70 lines
2.4 KiB
YAML
70 lines
2.4 KiB
YAML
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.0"
|
|
echo "Build Script Version: $scriptVersion"
|
|
echo "::endgroup::"
|
|
shell: pwsh
|
|
- uses: actions/checkout@v3
|
|
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 |