Skip to content

Conversation

@gauron99
Copy link
Collaborator

@gauron99 gauron99 commented Jan 29, 2026

This is a subsequent PR to #2

  • warn on func version when version is <= 3 than latest (latest - 3 and older)
  • one "practical" test in workflow for simplicity (can check manually in the workflow which uses custom version)

please note

  • when someone specifies the custom binary url base we skip the version check (dont warn)
  • when someone specifies 'latest' version we skip the version check (dont warn)

will add in subsequent PR

  • some js tests to cover this ( I want to remove the node_modules first -- use ncc module )

@gauron99 gauron99 force-pushed the push-loruqtwsqvmw branch 3 times, most recently from bafd5a7 to 54b8989 Compare January 30, 2026 10:48
Copy link

@twoGiants twoGiants left a 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) {

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.

Comment on lines -105 to -106
const version = smartVersionUpdate(versionInput);
core.info(`Using specific version ${version}`);
Copy link

@twoGiants twoGiants Jan 30, 2026

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) {

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 😆 .

Copy link
Collaborator Author

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.

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 😸 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants