Skip to content

Handle remote checksum edge cases #322

Description

@iker-barriocanal

The GitHub target makes some assumptions to check whether the local and the remote checksums of an asset match, but the code doesn't handle when these assumptions aren't correct. See

craft/src/targets/github.ts

Lines 381 to 407 in e4f9962

// XXX: This is a bit hacky as we rely on two things:
// 1. GitHub issuing a redirect to S3, where they store the artifacts,
// or at least pass those request headers unmodified to us
// 2. AWS S3 using the MD5 hash of the file for its ETag cache header
// when we issue a HEAD request.
const response = await this.github.request(`HEAD ${url}`, {
headers: {
// WARNING: You **MUST** pass this accept header otherwise you'll
// get a useless JSON API response back, instead of getting
// redirected to the raw file itself.
// And don't even think about using `browser_download_url`
// field as it is close to impossible to authendicate for
// that URL with a token and you'll lose hours getting 404s
// for private repos. Consider yourself warned. --xoxo BYK
Accept: DEFAULT_CONTENT_TYPE,
},
});
// ETag header comes in quotes for some reason so strip those
const remoteChecksum = response.headers['etag']?.slice(1, -1);
const localChecksum = createHash('md5').update(file).digest('hex');
if (localChecksum !== remoteChecksum) {
logger.trace(`Checksum mismatch for "${name}"`, response.headers);
throw new Error(
`Uploaded asset MD5 checksum does not match local asset checksum for "${name} (${localChecksum} != ${remoteChecksum})`
);
}

Update: The ETag header isn't always present in the response, and this is making all releases using the github target to fail (example).

Activity

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

Metadata

Metadata

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions