deduplicate subjects before adding to statement (#180)

Signed-off-by: Brian DeHamer <[email protected]>
This commit is contained in:
Brian DeHamer
2024-12-06 07:14:14 -08:00
committed by GitHub
parent 4cd38b497a
commit 65e34a8aa7
5 changed files with 40 additions and 5 deletions
+25
View File
@@ -362,6 +362,31 @@ describe('subjectFromInputs', () => {
}) })
}) })
}) })
describe('when duplicate subjects are supplied', () => {
let otherDir = ''
// Add duplicate subject in alternate directory
beforeEach(async () => {
// Set-up temp directory
const tmpDir = await fs.realpath(os.tmpdir())
otherDir = await fs.mkdtemp(tmpDir + path.sep)
// Write file to temp directory
await fs.writeFile(path.join(otherDir, filename), content)
})
it('returns de-duplicated subjects', async () => {
const inputs: SubjectInputs = {
...blankInputs,
subjectPath: `${path.join(dir, 'subject')}, ${path.join(otherDir, 'subject')} `
}
const subjects = await subjectFromInputs(inputs)
expect(subjects).toBeDefined()
expect(subjects).toHaveLength(1)
})
})
}) })
}) })
Generated Vendored
+4 -1
View File
@@ -71205,7 +71205,10 @@ const getSubjectFromPath = async (subjectPath, subjectName) => {
for (const file of files) { for (const file of files) {
const name = subjectName || path_1.default.parse(file).base; const name = subjectName || path_1.default.parse(file).base;
const digest = await digestFile(DIGEST_ALGORITHM, file); const digest = await digestFile(DIGEST_ALGORITHM, file);
digestedSubjects.push({ name, digest: { [DIGEST_ALGORITHM]: digest } }); // Only add the subject if it is not already in the list
if (!digestedSubjects.some(s => s.name === name && s.digest[DIGEST_ALGORITHM] === digest)) {
digestedSubjects.push({ name, digest: { [DIGEST_ALGORITHM]: digest } });
}
} }
if (digestedSubjects.length === 0) { if (digestedSubjects.length === 0) {
throw new Error(`Could not find subject at path ${subjectPath}`); throw new Error(`Could not find subject at path ${subjectPath}`);
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "actions/attest", "name": "actions/attest",
"version": "2.0.0", "version": "2.0.1",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "actions/attest", "name": "actions/attest",
"version": "2.0.0", "version": "2.0.1",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/attest": "^1.5.0", "@actions/attest": "^1.5.0",
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "actions/attest", "name": "actions/attest",
"description": "Generate signed attestations for workflow artifacts", "description": "Generate signed attestations for workflow artifacts",
"version": "2.0.0", "version": "2.0.1",
"author": "", "author": "",
"private": true, "private": true,
"homepage": "https://github.com/actions/attest", "homepage": "https://github.com/actions/attest",
+8 -1
View File
@@ -84,7 +84,14 @@ const getSubjectFromPath = async (
const name = subjectName || path.parse(file).base const name = subjectName || path.parse(file).base
const digest = await digestFile(DIGEST_ALGORITHM, file) const digest = await digestFile(DIGEST_ALGORITHM, file)
digestedSubjects.push({ name, digest: { [DIGEST_ALGORITHM]: digest } }) // Only add the subject if it is not already in the list
if (
!digestedSubjects.some(
s => s.name === name && s.digest[DIGEST_ALGORITHM] === digest
)
) {
digestedSubjects.push({ name, digest: { [DIGEST_ALGORITHM]: digest } })
}
} }
if (digestedSubjects.length === 0) { if (digestedSubjects.length === 0) {