Skip to content

Commit

Permalink
Install exact NuGet version with retry (#78)
Browse files Browse the repository at this point in the history
Fixes #75

- Use "[x.y.z]" format version to disallow NuGet from finding the closest possible match if not found exactly.
- Retry for up to 15 minutes if we get "Unable to find package" in the failed command output.
  • Loading branch information
danielrbradley authored Dec 12, 2024
1 parent fd10689 commit aafbfb2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 18 additions & 6 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

30 changes: 22 additions & 8 deletions src/verifyRelease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,28 @@ async function installDotnetPackageVersion(
)
}

const packageVersionRef = `${packageRef} --version ${opts.packageVersion}`
const addCmd = `dotnet add package ${packageVersionRef}`
core.debug(`Installing dotnet package: ${addCmd}`)
const addExec = shell.exec(addCmd, { cwd, fatal: true })
if (addExec.code !== 0) {
throw new Error(
`Failed to install ${packageVersionRef}: \n${addExec.stderr}\n${addExec.stdout}`
)
const packageVersionRef = `${packageRef} --version "[${opts.packageVersion}]"`
// Retry for up to 15 minutes if the package isn't available yet
const startTime = Date.now()
// eslint-disable-next-line no-constant-condition
while (true) {
const addCmd = `dotnet add package ${packageVersionRef}`
core.debug(`Installing dotnet package: ${addCmd}`)
const addExec = shell.exec(addCmd, { cwd, fatal: false })
if (addExec.code === 0) {
break
}
if (!addExec.stdout.includes('Unable to find package')) {
throw new Error(
`Failed to install ${packageVersionRef}: \n${addExec.stderr}\n${addExec.stdout}`
)
}
if (Date.now() - startTime > 15 * 60 * 1000) {
throw new Error(
`Timed out waiting for ${packageRef}==${opts.packageVersion} to be available on NuGet`
)
}
await new Promise(resolve => setTimeout(resolve, 5000)) // 5 seconds
}
}

Expand Down

0 comments on commit aafbfb2

Please sign in to comment.