Skip to content

Commit

Permalink
Merge pull request #1057 from arturcic/main
Browse files Browse the repository at this point in the history
#1502 - set tool install version range check
  • Loading branch information
arturcic authored Mar 3, 2024
2 parents 75715f5 + 4fc7295 commit e6586dc
Show file tree
Hide file tree
Showing 25 changed files with 655 additions and 994 deletions.
18 changes: 5 additions & 13 deletions .azure/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ variables:
value: 'true'
- name: DOTNET_CLI_TELEMETRY_OPTOUT
value: 'true'
- name: INPUT_VERSIONSPEC
value: '5.x'
- name: INPUT_INCLUDEPRERELEASE
value: 'false'
- name: INPUT_IGNOREFAILEDSOURCES
value: 'true'
- name: INPUT_PREFERLATESTVERSION
value: 'false'

jobs:
- job: build
Expand Down Expand Up @@ -44,10 +36,10 @@ jobs:
displayName: 'Build code'
- pwsh: |
# set the inputs for the 'gitversion/setup' action
$env:INPUT_VERSIONSPEC = "$(INPUT_VERSIONSPEC)"
$env:INPUT_INCLUDEPRERELEASE = "$(INPUT_INCLUDEPRERELEASE)"
$env:INPUT_IGNOREFAILEDSOURCES = "$(INPUT_IGNOREFAILEDSOURCES)"
$env:INPUT_PREFERLATESTVERSION = "$(INPUT_PREFERLATESTVERSION)"
$env:INPUT_VERSIONSPEC = '5.x'
$env:INPUT_INCLUDEPRERELEASE = 'false'
$env:INPUT_IGNOREFAILEDSOURCES = 'true'
$env:INPUT_PREFERLATESTVERSION = 'false'
# run the 'gitversion/setup' action
node ./gitversion/setup/bundle.js
Expand All @@ -57,7 +49,7 @@ jobs:
# set the inputs for the 'gitversion/execute' action
$env:INPUT_TARGETPATH = './'
$env:INPUT_DISABLECACHE = 'true'
$env:INPUT_DISABLENORMALIZATION = 'true'
$env:INPUT_DISABLENORMALIZATION = 'false'
$env:INPUT_OVERRIDECONFIG = '
next-version=1.0.0
update-build-number=false'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
with:
targetPath: './'
disableCache: true
disableNormalization: true
disableNormalization: false
overrideConfig: |
next-version=1.0.0
update-build-number=false
Expand Down
84 changes: 33 additions & 51 deletions dist/azure/gitreleasemanager/addasset/bundle.js

Large diffs are not rendered by default.

84 changes: 33 additions & 51 deletions dist/azure/gitreleasemanager/close/bundle.js

Large diffs are not rendered by default.

84 changes: 33 additions & 51 deletions dist/azure/gitreleasemanager/create/bundle.js

Large diffs are not rendered by default.

84 changes: 33 additions & 51 deletions dist/azure/gitreleasemanager/discard/bundle.js

Large diffs are not rendered by default.

84 changes: 33 additions & 51 deletions dist/azure/gitreleasemanager/open/bundle.js

Large diffs are not rendered by default.

84 changes: 33 additions & 51 deletions dist/azure/gitreleasemanager/publish/bundle.js

Large diffs are not rendered by default.

84 changes: 33 additions & 51 deletions dist/azure/gitreleasemanager/setup/bundle.js

Large diffs are not rendered by default.

84 changes: 33 additions & 51 deletions dist/azure/gitversion/execute/bundle.js

Large diffs are not rendered by default.

84 changes: 33 additions & 51 deletions dist/azure/gitversion/setup/bundle.js

Large diffs are not rendered by default.

86 changes: 34 additions & 52 deletions dist/github/gitreleasemanager/addasset/bundle.js

Large diffs are not rendered by default.

86 changes: 34 additions & 52 deletions dist/github/gitreleasemanager/close/bundle.js

Large diffs are not rendered by default.

86 changes: 34 additions & 52 deletions dist/github/gitreleasemanager/create/bundle.js

Large diffs are not rendered by default.

86 changes: 34 additions & 52 deletions dist/github/gitreleasemanager/discard/bundle.js

Large diffs are not rendered by default.

86 changes: 34 additions & 52 deletions dist/github/gitreleasemanager/open/bundle.js

Large diffs are not rendered by default.

86 changes: 34 additions & 52 deletions dist/github/gitreleasemanager/publish/bundle.js

Large diffs are not rendered by default.

86 changes: 34 additions & 52 deletions dist/github/gitreleasemanager/setup/bundle.js

Large diffs are not rendered by default.

86 changes: 34 additions & 52 deletions dist/github/gitversion/execute/bundle.js

Large diffs are not rendered by default.

86 changes: 34 additions & 52 deletions dist/github/gitversion/setup/bundle.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions docs/versions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
| GitTools/actions | GitVersion | GitReleaseManager |
|------------------|-------------------|--------------------|
| v1.0.0 | `>=5.10.0 <6.1.0` | `>=0.10.0 <0.17.0` |
| v2.0.0 | `>=6.x` | `>=0.17.0` |
| v3.0.0 | `>=7.x` | `>=0.17.0` |
85 changes: 34 additions & 51 deletions src/core/dotnet-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ISetupSettings } from '../tools/common/models'

export interface IDotnetTool {
disableTelemetry(): void
toolInstall(toolName: string, setupSettings: ISetupSettings): Promise<string>
toolInstall(toolName: string, versionRange: string, setupSettings: ISetupSettings): Promise<string>
}

@injectable()
Expand All @@ -37,76 +37,59 @@ export class DotnetTool implements IDotnetTool {
return this.buildAgent.exec(cmd, args)
}

public async toolInstall(toolName: string, setupSettings: ISetupSettings): Promise<string> {
public async toolInstall(toolName: string, versionRange: string, setupSettings: ISetupSettings): Promise<string> {
let version: string | null = this.versionManager.cleanVersion(setupSettings.versionSpec) || setupSettings.versionSpec
console.log('')
console.log('--------------------------')
console.log(`Acquiring ${toolName} version spec: ${setupSettings.versionSpec}`)
console.log(`Acquiring ${toolName} version spec: ${version}`)
console.log('--------------------------')

let version: string
let checkLatest = setupSettings.preferLatestVersion
if (this.versionManager.isExplicitVersion(setupSettings.versionSpec)) {
checkLatest = false // check latest doesn't make sense when explicit version
version = setupSettings.versionSpec
if (!this.versionManager.isExplicitVersion(version)) {
version = await this.queryLatestMatch(toolName, version, setupSettings.includePrerelease)
if (!version) {
throw new Error(`Unable to find ${toolName} version '${version}'.`)
}
}

if (!this.versionManager.satisfies(version, versionRange)) {
throw new Error(
`Version spec '${setupSettings.versionSpec}' resolved as '${version}' does not satisfy the range '${versionRange}'.` +
'Check https://raw.githubusercontent.com/GitTools/actions/main/docs/versions.md for more information'
)
}

let toolPath: string
if (!checkLatest) {
//
// Let's try and resolve the version spec locally first
//
let toolPath: string | null = null
if (!setupSettings.preferLatestVersion) {
toolPath = this.buildAgent.find(toolName, setupSettings.versionSpec)
if (toolPath) {
console.log('--------------------------')
console.log(`${toolName} version: ${version} found in local cache at ${toolPath}.`)
console.log('--------------------------')
}
}

if (!toolPath) {
if (this.versionManager.isExplicitVersion(setupSettings.versionSpec)) {
//
// Explicit version was specified. No need to query for list of versions.
//
version = setupSettings.versionSpec
} else {
//
// Let's query and resolve the latest version for the versionSpec.
// If the version is an explicit version (1.1.1 or v1.1.1) then no need to query.
// If your tool doesn't offer a mechanism to query,
// then it can only support exact version inputs.
//
version = await this.queryLatestMatch(toolName, setupSettings.versionSpec, setupSettings.includePrerelease)
if (!version) {
throw new Error(`Unable to find ${toolName} version '${setupSettings.versionSpec}'.`)
}

//
// Check the cache for the resolved version.
//
toolPath = this.buildAgent.find(toolName, version)
}
if (!toolPath) {
//
// Download, extract, cache
//
toolPath = await this.acquireTool(toolName, version, setupSettings.ignoreFailedSources)
}
toolPath = await this.acquireTool(toolName, version, setupSettings.ignoreFailedSources)
console.log('--------------------------')
console.log(`${toolName} version: ${version} installed.`)
console.log('--------------------------')
}

console.log('--------------------------')
console.log(`${toolName} version: ${version} installed.`)
console.log('--------------------------')
//
// Prepend the tools path. This prepends the PATH for the current process and
// instructs the agent to prepend for each task that follows.
//
this.buildAgent.debug(`toolPath: ${toolPath}`)

await this.setDotnetRoot()
this.buildAgent.addPath(toolPath)

return toolPath
}

protected async setDotnetRoot(): Promise<void> {
if (os.platform() !== 'win32' && !this.buildAgent.getVariable('DOTNET_ROOT')) {
let dotnetPath = await this.buildAgent.which('dotnet')
dotnetPath = fs.readlinkSync(dotnetPath) || dotnetPath
const dotnetRoot = path.dirname(dotnetPath)
this.buildAgent.setVariable('DOTNET_ROOT', dotnetRoot)
}
this.buildAgent.addPath(toolPath)

return toolPath
}

private async queryLatestMatch(toolName: string, versionSpec: string, includePrerelease: boolean): Promise<string> {
Expand Down
5 changes: 5 additions & 0 deletions src/core/versionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface IVersionManager {
isExplicitVersion(versionSpec: string): boolean
evaluateVersions(versions: string[], versionSpec: string, optionsOrLoose?: boolean | semver.RangeOptions): string
cleanVersion(version: string): string
satisfies(version: string, versionSpec: string, optionsOrLoose?: boolean | semver.RangeOptions): boolean
}

@injectable()
Expand Down Expand Up @@ -52,4 +53,8 @@ export class VersionManager implements IVersionManager {
this.buildAgent.debug('cleaning: ' + version)
return semver.clean(version)
}

public satisfies(version: string, versionSpec: string, optionsOrLoose?: boolean | semver.RangeOptions): boolean {
return semver.satisfies(version, versionSpec, optionsOrLoose)
}
}
2 changes: 1 addition & 1 deletion src/tools/gitreleasemanager/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class GitReleaseManagerTool extends DotnetTool implements IGitReleaseMana
}

public async install(setupSettings: ISetupSettings): Promise<void> {
await this.toolInstall('GitReleaseManager.Tool', setupSettings)
await this.toolInstall('GitReleaseManager.Tool', '>=0.10.0 <0.17.0', setupSettings)
}

public create(settings: GitReleaseManagerCreateSettings): Promise<IExecResult> {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/gitversion/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class GitVersionTool extends DotnetTool implements IGitVersionTool {
}

public async install(setupSettings: ISetupSettings): Promise<void> {
await this.toolInstall('GitVersion.Tool', setupSettings)
await this.toolInstall('GitVersion.Tool', '>=5.10.0 <6.1.0', setupSettings)
}

public run(options: GitVersionSettings): Promise<IExecResult> {
Expand Down

0 comments on commit e6586dc

Please sign in to comment.