downcase subject name for OCI images (#63)
Signed-off-by: Brian DeHamer <[email protected]>
This commit is contained in:
@@ -5,6 +5,10 @@ import path from 'path'
|
|||||||
import { subjectFromInputs } from '../src/subject'
|
import { subjectFromInputs } from '../src/subject'
|
||||||
|
|
||||||
describe('subjectFromInputs', () => {
|
describe('subjectFromInputs', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
process.env['INPUT_PUSH-TO-REGISTRY'] = 'false'
|
||||||
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
process.env['INPUT_SUBJECT-PATH'] = ''
|
process.env['INPUT_SUBJECT-PATH'] = ''
|
||||||
process.env['INPUT_SUBJECT-DIGEST'] = ''
|
process.env['INPUT_SUBJECT-DIGEST'] = ''
|
||||||
@@ -45,12 +49,12 @@ describe('subjectFromInputs', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('when specifying a subject digest', () => {
|
describe('when specifying a subject digest', () => {
|
||||||
const name = 'subject'
|
const name = 'Subject'
|
||||||
|
|
||||||
describe('when the digest is malformed', () => {
|
describe('when the digest is malformed', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
process.env['INPUT_SUBJECT-DIGEST'] = 'digest'
|
process.env['INPUT_SUBJECT-DIGEST'] = 'digest'
|
||||||
process.env['INPUT_SUBJECT-NAME'] = 'subject'
|
process.env['INPUT_SUBJECT-NAME'] = name
|
||||||
})
|
})
|
||||||
|
|
||||||
it('throws an error', async () => {
|
it('throws an error', async () => {
|
||||||
@@ -63,7 +67,7 @@ describe('subjectFromInputs', () => {
|
|||||||
describe('when the alogrithm is not supported', () => {
|
describe('when the alogrithm is not supported', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
process.env['INPUT_SUBJECT-DIGEST'] = 'md5:deadbeef'
|
process.env['INPUT_SUBJECT-DIGEST'] = 'md5:deadbeef'
|
||||||
process.env['INPUT_SUBJECT-NAME'] = 'subject'
|
process.env['INPUT_SUBJECT-NAME'] = name
|
||||||
})
|
})
|
||||||
|
|
||||||
it('throws an error', async () => {
|
it('throws an error', async () => {
|
||||||
@@ -76,7 +80,7 @@ describe('subjectFromInputs', () => {
|
|||||||
describe('when the sha256 digest is malformed', () => {
|
describe('when the sha256 digest is malformed', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
process.env['INPUT_SUBJECT-DIGEST'] = 'sha256:deadbeef'
|
process.env['INPUT_SUBJECT-DIGEST'] = 'sha256:deadbeef'
|
||||||
process.env['INPUT_SUBJECT-NAME'] = 'subject'
|
process.env['INPUT_SUBJECT-NAME'] = name
|
||||||
})
|
})
|
||||||
|
|
||||||
it('throws an error', async () => {
|
it('throws an error', async () => {
|
||||||
@@ -105,6 +109,28 @@ describe('subjectFromInputs', () => {
|
|||||||
expect(subject[0].digest).toEqual({ [alg]: digest })
|
expect(subject[0].digest).toEqual({ [alg]: digest })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('when the push-to-registry is true', () => {
|
||||||
|
const imageName = 'ghcr.io/FOO/bar'
|
||||||
|
const alg = 'sha256'
|
||||||
|
const digest =
|
||||||
|
'7d070f6b64d9bcc530fe99cc21eaaa4b3c364e0b2d367d7735671fa202a03b32'
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
process.env['INPUT_SUBJECT-DIGEST'] = `${alg}:${digest}`
|
||||||
|
process.env['INPUT_SUBJECT-NAME'] = imageName
|
||||||
|
process.env['INPUT_PUSH-TO-REGISTRY'] = 'true'
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns the subject (with name downcased)', async () => {
|
||||||
|
const subject = await subjectFromInputs()
|
||||||
|
|
||||||
|
expect(subject).toBeDefined()
|
||||||
|
expect(subject).toHaveLength(1)
|
||||||
|
expect(subject[0].name).toEqual(imageName.toLowerCase())
|
||||||
|
expect(subject[0].digest).toEqual({ [alg]: digest })
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when specifying a subject path', () => {
|
describe('when specifying a subject path', () => {
|
||||||
|
|||||||
+8
-2
@@ -80186,6 +80186,9 @@ const subjectFromInputs = async () => {
|
|||||||
const subjectPath = core.getInput('subject-path', { required: false });
|
const subjectPath = core.getInput('subject-path', { required: false });
|
||||||
const subjectDigest = core.getInput('subject-digest', { required: false });
|
const subjectDigest = core.getInput('subject-digest', { required: false });
|
||||||
const subjectName = core.getInput('subject-name', { required: false });
|
const subjectName = core.getInput('subject-name', { required: false });
|
||||||
|
const pushToRegistry = core.getBooleanInput('push-to-registry', {
|
||||||
|
required: false
|
||||||
|
});
|
||||||
if (!subjectPath && !subjectDigest) {
|
if (!subjectPath && !subjectDigest) {
|
||||||
throw new Error('One of subject-path or subject-digest must be provided');
|
throw new Error('One of subject-path or subject-digest must be provided');
|
||||||
}
|
}
|
||||||
@@ -80195,11 +80198,14 @@ const subjectFromInputs = async () => {
|
|||||||
if (subjectDigest && !subjectName) {
|
if (subjectDigest && !subjectName) {
|
||||||
throw new Error('subject-name must be provided when using subject-digest');
|
throw new Error('subject-name must be provided when using subject-digest');
|
||||||
}
|
}
|
||||||
|
// If push-to-registry is enabled, ensure the subject name is lowercase
|
||||||
|
// to conform to OCI image naming conventions
|
||||||
|
const name = pushToRegistry ? subjectName.toLowerCase() : subjectName;
|
||||||
if (subjectPath) {
|
if (subjectPath) {
|
||||||
return await getSubjectFromPath(subjectPath, subjectName);
|
return await getSubjectFromPath(subjectPath, name);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return [getSubjectFromDigest(subjectDigest, subjectName)];
|
return [getSubjectFromDigest(subjectDigest, name)];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
exports.subjectFromInputs = subjectFromInputs;
|
exports.subjectFromInputs = subjectFromInputs;
|
||||||
|
|||||||
+9
-2
@@ -17,6 +17,9 @@ export const subjectFromInputs = async (): Promise<Subject[]> => {
|
|||||||
const subjectPath = core.getInput('subject-path', { required: false })
|
const subjectPath = core.getInput('subject-path', { required: false })
|
||||||
const subjectDigest = core.getInput('subject-digest', { required: false })
|
const subjectDigest = core.getInput('subject-digest', { required: false })
|
||||||
const subjectName = core.getInput('subject-name', { required: false })
|
const subjectName = core.getInput('subject-name', { required: false })
|
||||||
|
const pushToRegistry = core.getBooleanInput('push-to-registry', {
|
||||||
|
required: false
|
||||||
|
})
|
||||||
|
|
||||||
if (!subjectPath && !subjectDigest) {
|
if (!subjectPath && !subjectDigest) {
|
||||||
throw new Error('One of subject-path or subject-digest must be provided')
|
throw new Error('One of subject-path or subject-digest must be provided')
|
||||||
@@ -32,10 +35,14 @@ export const subjectFromInputs = async (): Promise<Subject[]> => {
|
|||||||
throw new Error('subject-name must be provided when using subject-digest')
|
throw new Error('subject-name must be provided when using subject-digest')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If push-to-registry is enabled, ensure the subject name is lowercase
|
||||||
|
// to conform to OCI image naming conventions
|
||||||
|
const name = pushToRegistry ? subjectName.toLowerCase() : subjectName
|
||||||
|
|
||||||
if (subjectPath) {
|
if (subjectPath) {
|
||||||
return await getSubjectFromPath(subjectPath, subjectName)
|
return await getSubjectFromPath(subjectPath, name)
|
||||||
} else {
|
} else {
|
||||||
return [getSubjectFromDigest(subjectDigest, subjectName)]
|
return [getSubjectFromDigest(subjectDigest, name)]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user