Sanitize repo name when including in a layer title

These titles were previously including the filename as {org}/{repo}_{version} which means when clients download the layer they think it needs to be unwrapped into a folder called {org}.
This is not what we want, so we should instead rename the file as {org}-{repo}_{version}. e.g. from myorg/myrepo_myversion.zip to myorg-myrepo_myversion.zip
This commit is contained in:
Conor Sloan
2023-11-23 14:37:29 +00:00
parent 0461881066
commit 6c4739c768
3 changed files with 27 additions and 13 deletions
+11 -4
View File
@@ -25,8 +25,9 @@ export function createActionPackageManifest(
created: Date
): Manifest {
const configLayer = createConfigLayer()
const tarLayer = createTarLayer(tarFile, repository, version)
const zipLayer = createZipLayer(zipFile, repository, version)
const sanitizedRepo = sanitizeRepository(repository)
const tarLayer = createTarLayer(tarFile, sanitizedRepo, version)
const zipLayer = createZipLayer(zipFile, sanitizedRepo, version)
const manifest: Manifest = {
schemaVersion: 2,
@@ -70,7 +71,7 @@ function createZipLayer(
size: zipFile.size,
digest: zipFile.sha256,
annotations: {
'org.opencontainers.image.title': `${repository}-${version}.zip`
'org.opencontainers.image.title': `${repository}_${version}.zip`
}
}
@@ -87,9 +88,15 @@ function createTarLayer(
size: tarFile.size,
digest: tarFile.sha256,
annotations: {
'org.opencontainers.image.title': `${repository}-${version}.tar.gz`
'org.opencontainers.image.title': `${repository}_${version}.tar.gz`
}
}
return tarLayer
}
// Remove slashes so we can use the repository in a filename
// repository usually includes the namespace too, e.g. my-org/my-repo
function sanitizeRepository(repository: string): string {
return repository.replace('/', '-')
}