Skip to content

Commit

Permalink
use versionSpec for runner.spec.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
arturcic committed Nov 18, 2024
1 parent 718bd08 commit 5dd6035
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/__tests__/tools/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import process from 'node:process'
import { expect } from 'vitest'
import { keysOf } from '@tools/common'
import { type IBuildAgent } from '@agents/common'
import * as semver from 'semver'

export function setEnv(key: string, value: string): void {
process.env[key.toUpperCase()] = value
Expand Down Expand Up @@ -34,8 +35,9 @@ export const expectValidSettings = <T extends object>(expectedSettings: T, actua
}
}

export async function getLatestVersion(toolName: string): Promise<string> {
export async function getLatestVersion(toolName: string, versionSpec: string): Promise<string> {
const response = await fetch(`https://api.nuget.org/v3-flatcontainer/${toolName.toLowerCase()}/index.json`)
const json = (await response.json()) as { versions: string[] }
return json.versions.reverse()[0]
const filteredVersions = json.versions.filter(v => semver.satisfies(v, versionSpec))
return filteredVersions.reverse()[0]
}
5 changes: 3 additions & 2 deletions src/__tests__/tools/gitreleasemanager/runner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ describe('GitReleaseManager Runner', () => {

const toolPathVariable = 'GITRELEASEMANAGER_PATH'
const toolName = 'dotnet-gitreleasemanager'
const versionSpec = '0.x'

function testOnAgent(agent: IBuildAgent): void {
let version: string
let toolPath: string
let runner: Runner

beforeAll(async () => {
version = await getLatestVersion('GitReleaseManager.Tool')
version = await getLatestVersion('GitReleaseManager.Tool', versionSpec)
toolPath = path.resolve(baseDir, 'tools', 'GitReleaseManager.Tool', version)
runner = new Runner(agent)
})
Expand All @@ -39,7 +40,7 @@ describe('GitReleaseManager Runner', () => {

it.sequential('should run setup GitReleaseManager', async () => {
setInputs({
versionSpec: '0.x',
versionSpec: versionSpec,
includePrerelease: false,
ignoreFailedSources: false,
preferLatestVersion: true
Expand Down
5 changes: 3 additions & 2 deletions src/__tests__/tools/gitversion/runner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ describe('GitVersion Runner', () => {

const toolPathVariable = 'GITVERSION_PATH'
const toolName = 'dotnet-gitversion'
const versionSpec = '6.x'

function testOnAgent(agent: IBuildAgent): void {
let version: string
let toolPath: string
let runner: Runner

beforeAll(async () => {
version = await getLatestVersion('GitVersion.Tool')
version = await getLatestVersion('GitVersion.Tool', versionSpec)
toolPath = path.resolve(baseDir, 'tools', 'GitVersion.Tool', version)
runner = new Runner(agent)
})
Expand All @@ -41,7 +42,7 @@ describe('GitVersion Runner', () => {

it.sequential('should run setup GitVersion', async () => {
setInputs({
versionSpec: '6.x',
versionSpec: versionSpec,
includePrerelease: false,
ignoreFailedSources: false,
preferLatestVersion: true
Expand Down

0 comments on commit 5dd6035

Please sign in to comment.