-
Notifications
You must be signed in to change notification settings - Fork 0
Warn on older versions of func #3
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
base: main
Are you sure you want to change the base?
Conversation
bafd5a7 to
54b8989
Compare
twoGiants
left a comment
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.
Good job! 👍
I think we can make it a bit simpler. Wdyt?
See my comments below.
| // Resolve download url based on given input | ||
| // binName: name of func binary when it is to be constructed for full URL | ||
| // (when not using binarySource) | ||
| function resolveDownloadUrl(binName) { |
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 a big change for a small thing => the warning.
I would propose to revert most changes and put a small logic change right after const version = smartVersionUpdate(versionInput); in line 105.
| const version = smartVersionUpdate(versionInput); | ||
| core.info(`Using specific version ${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.
const version = smartVersionUpdate(versionInput);
warnStaleVersion(version);I would put the core.info(Using specific version ${version}); in the warnStaleVersion and log it if the version is fine.
| return buildUrlString(version); | ||
| // Warn if version requested is more than 2 versions behind latest (>= 3) | ||
| // This function does NOT error | ||
| async function warnStaleVersion(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.
This can be done a bit simpler using the github redirect to the latest version. No need for JSON etc.:
async function getLatestVersion() {
const response = await fetch('https://github.com/knative/func/releases/latest', {
method: 'HEAD',
redirect: 'manual'
});
const location = response.headers.get('location');
// location: "https://github.com/knative/func/releases/tag/knative-v1.21.0"
return location.split('/').pop(); // "knative-v1.21.0"
}Then you can use this function to get the version here:
async function warnStaleVersion(version) {
let latestVersion;
try {
latestVersion = getLatestVersion()
} catch (error) {
core.debug(`Failed fetching latest version: ${error.message}`);
return;
}
const offset = 3;
if (hasVersionDrift(latestVersion, version, offset)) {
core.warning(
`You are using func ${version}, which is ${offset} versions behind the latest (${latestVersion}). Upgrading is recommended.`
);
return;
}
core.info(`Using specific version ${version}`);
}versionDiff has a bug. I would not write a warning in this case of version = 1.0.0 and latestVersion = 2.0.0.
I would change versionDiff to hasVersionDrift and change the implementation to use major and minor versions for checking, e.g. knative-v1.21.0 becomes 121 and knative-v1.18.0 becomes 118 and then you subtract them and compare the abs(121 - 118) to offset.
It looks like the time is coming closer for unit tests for this action 😆 .
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.
Well, the comment does say its a "difference of minor versions" 😄 but i get your point. I didnt take it would be needed any time soon. Will update it. The redirect location is super cool! will update that.
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 comment does say its a "difference of minor versions" 😄
You're right of course. My thinking was that if someone adds a very old version for some reason or in future when we have v2+. But you got it 😸 👍
54b8989 to
bd74eef
Compare
This is a subsequent PR to #2
please note
will add in subsequent PR
nccmodule )