Skip to content

Add fallback URL for Testkube CLI download when release tag format doesn't match#16

Open
Copilot wants to merge 2 commits intomainfrom
copilot/fix-setup-testkube-download-issue
Open

Add fallback URL for Testkube CLI download when release tag format doesn't match#16
Copilot wants to merge 2 commits intomainfrom
copilot/fix-setup-testkube-download-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 18, 2026

Testkube CLI releases dropped the v prefix in tag names starting at v2.4.0, causing HTTP 404 errors when the action tried to download newer CLI versions with the old URL format.

Changes

  • src/index.ts: Compute both a primary URL (chosen via semver comparison against 2.4.0) and a fallback URL (opposite v-prefix variant). Wrap downloadTool in a try/catch; on HTTPError with status 404, log and retry with the fallback URL. Import HTTPError from @actions/tool-cache for proper type-safe error handling instead of string-matching.
  • dist/index.js: Rebuilt from updated source.
// Primary URL based on semver check; fallback is the opposite format
const isLegacyVersion = semver.lt(encodedVersion, TAG_UPDATED_SINCE); // TAG_UPDATED_SINCE = "2.4.0"
const primaryArtifactUrl = isLegacyVersion
  ? `https://github.com/kubeshop/testkube/releases/download/v${encodedVersion}/...`
  : `https://github.com/kubeshop/testkube/releases/download/${encodedVersion}/...`;
const fallbackArtifactUrl = isLegacyVersion
  ? `https://github.com/kubeshop/testkube/releases/download/${encodedVersion}/...`
  : `https://github.com/kubeshop/testkube/releases/download/v${encodedVersion}/...`;

try {
  artifactPath = await toolCache.downloadTool(primaryArtifactUrl);
} catch (e: unknown) {
  if (e instanceof HTTPError && e.httpStatusCode === 404) {
    artifactPath = await toolCache.downloadTool(fallbackArtifactUrl);
  } else {
    throw e;
  }
}

This makes the action resilient to the existing 2.4.0 format change and any future tag format changes.

Original prompt

This section details on the original issue you should resolve

<issue_title>setup-testkube action fails to download CLI v2.4.0+ due to release tag format change</issue_title>
<issue_description>Describe the bug

The setup-testkube action fails with HTTP 404 when specifying any CLI version >= 2.4.0. The action constructs the download URL by prepending v to the version:

https://github.com/kubeshop/testkube/releases/download/v2.7.1/testkube_2.7.1_Linux_x86_64.tar.gz

However, starting from version 2.4.0, Testkube release tags dropped the v prefix. The correct URL is:

https://github.com/kubeshop/testkube/releases/download/2.7.1/testkube_2.7.1_Linux_x86_64.tar.gz

Steps to reproduce

  • uses: kubeshop/setup-testkube@v1
    with:
    version: 2.7.1

Error:
Downloading the artifact from "https://github.com/kubeshop/testkube/releases/download/v2.7.1/testkube_2.7.1_Linux_x86_64.tar.gz"...
HTTPError: Unexpected HTTP response: 404

Expected behavior

The action should successfully download the CLI for versions >= 2.4.0.

Additional context

  • Versions <= 2.3.0 use the v prefix in tags (e.g. v2.3.0) — these work fine
  • Versions >= 2.4.0 dropped the v prefix — these all fail
  • Tag v1.0.11 in the repository appears to have a dual URL fallback fix, but it has never been published as a GitHub release, making it unresolvable by the Actions runner
  • Current workaround: download the binary manually via curl

Suggested fix

Publish v1.0.11 as a proper GitHub release, or release a new version with the fallback logic that tries both URL formats.</issue_description>

Comments on the Issue (you are @copilot in this section)


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Co-authored-by: olensmar <1917063+olensmar@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix setup-testkube action to download CLI versions without v prefix Add fallback URL for Testkube CLI download when release tag format doesn't match Mar 18, 2026
Copilot AI requested a review from olensmar March 18, 2026 12:05
@olensmar
Copy link
Copy Markdown
Member

@greptile

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Mar 18, 2026

Greptile Summary

This PR fixes a real production bug where the action was constructing GitHub release download URLs with a v prefix for versions ≥ 2.4.0 (which dropped the prefix), causing HTTP 404 failures. The fix computes a primary URL based on a semver comparison against "2.4.0" and a fallback URL using the opposite format, then retries on 404 using HTTPError from @actions/tool-cache for type-safe error detection.

What's good:

  • The fix directly addresses the root cause and is resilient to future tag-format regressions.
  • Only 404 errors trigger the fallback; other HTTP errors are correctly re-thrown.
  • HTTPError is properly re-exported by @actions/tool-cache v2.x and is correctly referenced in the bundled output.

Minor observation (non-blocking):

  • semver.lt(encodedVersion, TAG_UPDATED_SINCE) passes the URL-encoded version string to semver. For all valid semver strings, encodeURIComponent is a no-op (dots and hyphens are not encoded), so this works correctly in practice. Passing params.version directly would be semantically cleaner, but this is pre-existing code not introduced by the PR.
  • If the fallback URL also returns 404, the HTTPError propagates uncaught from the second downloadTool call. This is intentional and acceptable; the preceding log line ("Primary URL failed, falling back to …") gives enough context for debugging.

Confidence Score: 4/5

  • This PR is safe to merge — the fallback logic is correct, error handling is properly scoped, and it directly fixes a confirmed production 404 bug.
  • The semver-based URL selection is correct, the HTTPError instanceof check is type-safe and backed by a valid export from @actions/tool-cache v2.x, and only 404 errors trigger the fallback while all other errors propagate normally. No critical bugs or regressions were identified.
  • No files require special attention.

Important Files Changed

Filename Overview
src/index.ts Adds semver-based primary/fallback URL selection and wraps downloadTool in a try/catch that retries with the alternate v-prefix format on HTTP 404. Logic is correct; one minor note: encodedVersion (URL-encoded string) is passed to semver.lt, though for valid semver strings encodeURIComponent is a no-op so this works in practice.
dist/index.js Bundled output rebuilt from updated source; the new try/catch and HTTPError instanceof check are faithfully represented in the webpack output.

Sequence Diagram

sequenceDiagram
    participant A as Action (index.ts)
    participant SC as semver.lt()
    participant GH as GitHub Releases CDN

    A->>SC: lt(encodedVersion, "2.4.0")
    SC-->>A: isLegacyVersion (true/false)

    A->>A: Build primaryArtifactUrl<br/>(v-prefix if legacy, no-prefix if modern)
    A->>A: Build fallbackArtifactUrl<br/>(opposite of primary)

    A->>GH: downloadTool(primaryArtifactUrl)
    alt Primary succeeds
        GH-->>A: artifact binary
    else HTTP 404
        GH-->>A: HTTPError (404)
        A->>A: log "falling back to fallbackArtifactUrl"
        A->>GH: downloadTool(fallbackArtifactUrl)
        alt Fallback succeeds
            GH-->>A: artifact binary
        else Fallback fails
            GH-->>A: Error (propagated to caller)
        end
    else Other HTTP error
        GH-->>A: HTTPError (non-404) — rethrown
    end

    A->>A: extractTar → cacheFile → addPath
Loading

Last reviewed commit: "Fix download URL fal..."

@olensmar olensmar marked this pull request as ready for review March 18, 2026 12:12
@JosueSV
Copy link
Copy Markdown

JosueSV commented Mar 19, 2026

Any update on this @olensmar?

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.

setup-testkube action fails to download CLI v2.4.0+ due to release tag format change

4 participants