-
Notifications
You must be signed in to change notification settings - Fork 53
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
Rework our version matching algorithm #217
Rework our version matching algorithm #217
Conversation
- run: npm install | ||
- run: npm run build | ||
- run: npm run format | ||
- run: npm install -g markdownlint-cli |
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 was moved to package.json
which means this whole npm ...
pipeline can simply be as it is proposed here.
- elixir-version: '1.10.3' | ||
otp-version: '22.3.4.1' | ||
os: 'ubuntu-20.04' |
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.
We find this above, already, with version-type: strict
.
"husky": { | ||
"hooks": { | ||
"pre-commit": "npm run format -- --check && npm run build && git add dist/" | ||
} | ||
}, |
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.
Not really used, I guess. npm run build-dist
does it all.
"eslint-plugin-import": "2.26.0", | ||
"eslint-plugin-jsx-a11y": "6.6.1", | ||
"eslint-plugin-react": "7.31.10", | ||
"husky": "8.0.1", |
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.
Not really used, so we can trim down a few deps.
@@ -184,13 +185,16 @@ async function getElixirVersion(exSpec0, otpVersion0, hexMirrors) { | |||
const otpVersion = otpVersion0.match(/^([^-]+-)?(.+)$/)[2] | |||
const otpVersionMajor = otpVersion.match(/^([^.]+).*$/)[1] | |||
const elixirVersions = await getElixirVersions(hexMirrors) | |||
const semverVersions = Array.from(elixirVersions.keys()).sort() |
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 is now done inside getVersionFromSpec/2
, for all consumer functions, as to centralised behaviour and make it more consistent.
return maybePrependWithV(gleamVersion, gleamVersion) | ||
return maybePrependWithV(gleamVersion) |
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.
The 2nd argument had no value, as it wasn't accepted, in any case.
@@ -300,7 +309,7 @@ async function getElixirVersions(hexMirrors) { | |||
.forEach((line) => { | |||
const elixirMatch = | |||
line.match(/^v?(.+)-otp-([^ ]+)/) || line.match(/^v?([^ ]+)/) | |||
const elixirVersion = maybePrependWithV(elixirMatch[1]) |
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 is no longer required, since internally all versions will be stripped of v
and it'll only be added when required for external requests.
return rebar3VersionsListing | ||
} | ||
|
||
function isStrictVersion() { | ||
return getInput('version-type', false) === 'strict' | ||
} | ||
|
||
function getVersionFromSpec(spec, versions, maybePrependWithV0) { |
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.
Most of the big changes are in this function... and maybeCoerced/1
below.
} | ||
|
||
return v | ||
return version || null | ||
} | ||
|
||
function maybeCoerced(v) { |
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.
Most of the big changes are in this function... and getVersionFromSpec/2
above.
Yeah, I agree with that, but the fact remains still that even 25.3.1 is not semver in the case of OTP. However, I think it's fair to say it can be treated like that. I would agree this is a breaking change. So, we're thinking this would result in a new major version then, is that correct? |
It'd probably result in a breaking change, yes, depending on:
I "think" I can try to fit the Edit: Ok, so I'm trying a new approach where I compare version suffixes to a fixed version. |
version-type: strict
I rebased to resolve merge conflict and increased complexity for Edit: also, since the last commit, I moved back most changes in the |
if (isVersion(otpSpec0)) { | ||
otpSpec = `OTP-${otpSpec0}` // ... it's a version! | ||
} |
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.
The result of this block was never used. I don't know why static analysis wouldn't find this...
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.
Needs hank.
src/setup-beam.js
Outdated
function xyzabVer(pref, suf) { | ||
// This accounts for stuff like 6.0.2.0.1.0, as proposed by Erlang's | ||
// https://www.erlang.org/doc/system_principles/versions.html | ||
const dd = '\\.?(\\d+)?' | ||
return new RegExp( | ||
`${pref}v?(\\d+)${dd}${dd}${dd}${dd}${dd}(?:-rc\\.?\\d+)?(?:-otp-\\d+)?${suf}`, | ||
) | ||
} | ||
|
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 function, and its callers, will probably be the "most difficult bits" to maintain, but the regexps here are pretty relaxed, too...
Oof! Conflicts @paulo-ferraz-oliveira |
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.
@paulo-ferraz-oliveira This LGTM. I'd be in favor of merging and a delay on the release, sound good?
Sure. We can merge and delay release. That'll give me a chance to update the other pull request I have opened. |
We want the most important things to fail first and prevent the other ones from executing e.g. if your dist/ is not updated, there's no point seeing the tests fail
We'll deal with all this in a centralized place to make it easier to reason on the code
1. stop accepting maybePrependWithV0, since this is only used in specialized cases 2. sort versions internally (don't expect it to come sorted) 3. compare rc/strict and .includes in a single go (don't separate these) 4. don't expect already coerced version arrays, coerce them when required (the maybeCoerced version had changed already, which means we're smarter at putting stuff inside the version array) 5. raise an exception if a semver-invalid version is not flagged as strict
This reverts commit 500b0fe.
This reverts commit fbe1317.
We cheat on the semver matching: 1. we keep an ordered list of versions that respect e.g. 22.3.4 2. if we match 22.3.4 when fetching a version, we get the last value from the list of versions that respect it, e.g. 22.3.4.2.1.0 (since this is ordered, it should work as previously expected) This increases code complexity for getVersionFromSpec, but hopefully not by much... We also remove throw-based test cases (non-versions will fail later, with null), and add some tests to prove our need code.
But still keep them useful
Force-pushing to resolve merge conflicts. If no actions show issues I'm squash-merging. |
Thank you @paulo-ferraz-oliveira! It seems this PR removed support for maint/master from OTP git, which Elixir relies on. Was it intentional? |
Nevermind, PR sent here: #241 :) |
👋 It wasn't. I'll look at the pull request. |
This:
package.json
, where appropriategetVersionFromSpec/2
to improve on version matching