-
Notifications
You must be signed in to change notification settings - Fork 5
Support “nightly-latest” version #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 17 commits
c83d049
7fff986
eabad98
98646ae
38856bd
09245dd
d94ed1f
3b8354c
63517f1
1336a53
4a5e8c9
a2efa05
562807d
51ed729
8b30437
8a5d5cc
5d5649b
56f2eb1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,7 +7,7 @@ const os = require("os"); | |||||||||||||||
| try { | ||||||||||||||||
| const version = core.getInput("dafny-version", { required: true }); | ||||||||||||||||
| const distribution = getDistribution(os.platform(), version); | ||||||||||||||||
| const url = dafnyURL(version, distribution); | ||||||||||||||||
| const url = await dafnyURL(version, distribution); | ||||||||||||||||
|
|
||||||||||||||||
| core.info(`Dafny Url: ${url}`); | ||||||||||||||||
| core.info(`Dafny Distribution: ${distribution}`); | ||||||||||||||||
|
|
@@ -22,29 +22,86 @@ const os = require("os"); | |||||||||||||||
| // Install related tools. | ||||||||||||||||
| // Hopefully in the future we can install Dafny itself this way as well. | ||||||||||||||||
| // For now the zipped releases are simpler because they include Z3. | ||||||||||||||||
| await installDotnetTool("dafny-reportgenerator", "1.*") | ||||||||||||||||
| await installDotnetTool("dafny-reportgenerator", "1.*"); | ||||||||||||||||
| } catch (error) { | ||||||||||||||||
| core.setFailed(error.message); | ||||||||||||||||
| } | ||||||||||||||||
| })(); | ||||||||||||||||
|
|
||||||||||||||||
| async function installDotnetTool(toolName, version) { | ||||||||||||||||
| await exec.exec("dotnet", ["tool", "install", "-g", toolName, "--version", version]) | ||||||||||||||||
| await exec.exec("dotnet", [ | ||||||||||||||||
| "tool", | ||||||||||||||||
| "install", | ||||||||||||||||
| "-g", | ||||||||||||||||
| toolName, | ||||||||||||||||
| "--version", | ||||||||||||||||
| version, | ||||||||||||||||
| ]); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| // Export functions for testing | ||||||||||||||||
| exports.dafnyURL = dafnyURL; | ||||||||||||||||
| exports.getDistribution = getDistribution; | ||||||||||||||||
|
|
||||||||||||||||
| function dafnyURL(version, distribution) { | ||||||||||||||||
| async function dafnyURL(version, distribution) { | ||||||||||||||||
| const versionPath = version.startsWith("nightly") ? "nightly" : `v${version}`; | ||||||||||||||||
| if (version == "nightly-latest") { | ||||||||||||||||
| version = await latestNightlyVersion(); | ||||||||||||||||
| } | ||||||||||||||||
| const root = "https://github.com/dafny-lang/dafny/releases/download"; | ||||||||||||||||
| return `${root}/${versionPath}/dafny-${version == "2.3.0" ? "2.3.0.10506" : version}-x64-${distribution}.zip`; | ||||||||||||||||
| return `${root}/${versionPath}/dafny-${ | ||||||||||||||||
| version == "2.3.0" ? "2.3.0.10506" : version | ||||||||||||||||
| }-x64-${distribution}.zip`; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| async function latestNightlyVersion() { | ||||||||||||||||
| // Shamelessly copied and modified from dafny-lang/ide-vscode. | ||||||||||||||||
| // Parsing the dotnet tool output is obviously not great, | ||||||||||||||||
| // and we could consider using the NuGet API in the future. | ||||||||||||||||
| // Alternatively if we move to installing Dafny using `dotnet tool install` | ||||||||||||||||
| // we could use the `--prerelease` flag, although that assumes | ||||||||||||||||
| // that all nightly builds use a fresh version number, | ||||||||||||||||
| // and can't be used together with `--version` to express something like | ||||||||||||||||
| // "install the latest 3.X version including prereleases". | ||||||||||||||||
| const { exitCode, stdout, stderr } = await exec.getExecOutput( | ||||||||||||||||
| "dotnet", | ||||||||||||||||
| ["tool", "search", "Dafny", "--detail", "--prerelease"], | ||||||||||||||||
| { silent: true } | ||||||||||||||||
| ); | ||||||||||||||||
| if (exitCode != 0) { | ||||||||||||||||
| throw new Error( | ||||||||||||||||
| `dotnet tool command failed (exitCode ${exitCode}):\n${stderr}"` | ||||||||||||||||
| ); | ||||||||||||||||
| } | ||||||||||||||||
| const entries = stdout | ||||||||||||||||
| .split("----------------") | ||||||||||||||||
| .map((entry) => entry.split(/\r?\n/).filter((e) => e !== "")); | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having only taken the first or removed the report generator
Suggested change
|
||||||||||||||||
| const dafnyEntry = entries.filter((entry) => entry[0] === "dafny")[0]; | ||||||||||||||||
| const versionsIndex = dafnyEntry.findIndex((v) => v.startsWith("Versions:")); | ||||||||||||||||
| const versions = dafnyEntry | ||||||||||||||||
| .slice(versionsIndex + 1) | ||||||||||||||||
| .map((versionLine) => versionLine.trimStart().split(" ")[0]); | ||||||||||||||||
|
|
||||||||||||||||
| const nightlies = versions.filter((l) => l.includes("nightly")); | ||||||||||||||||
| const dates = nightlies.map((n, index) => { | ||||||||||||||||
| const split = n.split("-"); | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean to compare a date,
Suggested change
|
||||||||||||||||
| return { index, date: split[2] + split[3] + split[4] }; | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would just take the value
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had that thought too when making this work initially :) |
||||||||||||||||
| }); | ||||||||||||||||
| dates.sort((a, b) => (a.date < b.date ? 1 : -1)); | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree I don't think you care about equal |
||||||||||||||||
| const toolVersion = nightlies[dates[0].index]; | ||||||||||||||||
|
|
||||||||||||||||
| // Slice off the "3.11.0.50201-" from 3.11.0.50201-nightly-2023-02-13-14bc57f, for e.g. | ||||||||||||||||
| const version = toolVersion.slice(toolVersion.indexOf("-") + 1); | ||||||||||||||||
|
|
||||||||||||||||
| core.info(`Using latest nightly version: ${version}`); | ||||||||||||||||
| return version; | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be best refactored into a function that takes the string. |
||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| function getDistribution(platform, version) { | ||||||||||||||||
| return platform === "darwin" // Osx | ||||||||||||||||
| ? version == "2.3.0" ? "osx-10.14.1" : "osx-10.14.2" | ||||||||||||||||
| ? version == "2.3.0" | ||||||||||||||||
| ? "osx-10.14.1" | ||||||||||||||||
| : "osx-10.14.2" | ||||||||||||||||
| : platform === "win32" // windows | ||||||||||||||||
| ? "win" | ||||||||||||||||
| : "ubuntu-16.04"; // Everything else is linux... | ||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pulls both dafny and the report, I would suggest
--take 1There is some way to query,
but I don't understand how to get the specific package ID.
https://learn.microsoft.com/en-us/nuget/api/search-query-service-resource#search-for-packages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, I wouldn't want to just
--take 1though, it feels brittle to depend on the order of results.As per my comment I'd also prefer to use the NuGet API, will timebox attempting that.