Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix artifact name collision #74

Merged
merged 5 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ The following input parameters are also supported for the Endor Labs GitHub acti
| `bazel_include_targets` | Specify a list of Bazel targets to scan. If `bazel_targets_include` is not set the `bazel_targets_query` value is used to determine with bazel targets to scan. |
| `bazel_targets_query` | Specify a bazel query to determine with Bazel targets to scan. Ignored if `bazel_targets_include` is set. |
| `enable_pr_comments` | Set to `true` to publish new findings as review comments. Must be set together with `pr` and `github_token`. Additionally, the `pull-requests: write` permissions must be set in the workflow. (Default: `false`) |
| `export_scan_result_artifact` | Set to `false` to disable the json scan result artifact export. (Default: `true`) |
| `export_scan_result_artifact` | Set to `false` to disable the json scan result artifact export. (Default: `true`). Artifact name appears in step output named `scan_result` |
| `github_token` | Set the token used to authenticate with GitHub. Must be provided if `enable_pr_comments` is set to `true` |
| `phantom_dependencies` | Set to `true` to enable phantom dependency analysis. (Default: `false`) |
| `output_file` | Set a file to save the scan results to; use this in lieu of `export_scan_result_artifact` to save any scan results data to a file in the workspace for processing by others steps in the same job, instead of the workflow run log. |
Expand Down
35 changes: 31 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116400,24 +116400,51 @@ const setupEndorctl = ({ version, checksum, api }) => __awaiter(void 0, void 0,
exports.setupEndorctl = setupEndorctl;
const uploadArtifact = (scanResult) => __awaiter(void 0, void 0, void 0, function* () {
const artifactClient = new artifact.DefaultArtifactClient();
const artifactName = "endor-scan";
const maxExistingChecks = 8;
let artifactName = "endor-scan";
// TODO - list artifacts and add a random identifier if artifact already exists
let artifactExists = true;
let checkCount = 0;
while (artifactExists && checkCount < maxExistingChecks) {
checkCount += 1;
try {
const artifactResult = yield artifactClient.getArtifact(artifactName);
artifactExists = true;
core.info(`Found existing artifact '${artifactResult.artifact.name}'`);
const uppercaseAsciiStart = 65;
const letterIndex = Math.floor(Math.random() * 26);
const letter = String.fromCharCode(uppercaseAsciiStart + letterIndex);
artifactName += letter;
}
catch (e) {
// the artifact exists: add a random letter and try again
core.info(`No existing artifact named '${artifactName}'; using that`);
artifactExists = false;
}
} // - while artifactExists...
if (artifactExists) {
core.warning(`Can't find a unique artifact name for scan results after ${checkCount} tries`);
return;
}
const { filePath, uploadPath, error } = yield (0, exports.writeJsonToFile)(scanResult);
if (error) {
core.error(error);
core.warning(`Unable to write JSON document for scan result to file: ${error}`);
}
else {
const files = [filePath];
const rootDirectory = uploadPath;
core.info(`Writing artifact ${artifactName}`);
try {
const { id, size } = yield artifactClient.uploadArtifact(artifactName, files, rootDirectory, {});
core.info(`Scan result exported to artifact ${id}, size ${size}`);
core.setOutput("scan_result", artifactName);
}
catch (e) {
if (e instanceof Error) {
core.error(`Some items failed to export: ${e.message}`);
core.warning(`Some items failed to export: ${e.message}`);
}
else {
core.error(`Some items failed to export: ${e}`);
core.warning(`Some items failed to export: ${e}`);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

35 changes: 31 additions & 4 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116216,24 +116216,51 @@ const setupEndorctl = ({ version, checksum, api }) => __awaiter(void 0, void 0,
exports.setupEndorctl = setupEndorctl;
const uploadArtifact = (scanResult) => __awaiter(void 0, void 0, void 0, function* () {
const artifactClient = new artifact.DefaultArtifactClient();
const artifactName = "endor-scan";
const maxExistingChecks = 8;
let artifactName = "endor-scan";
// TODO - list artifacts and add a random identifier if artifact already exists
let artifactExists = true;
let checkCount = 0;
while (artifactExists && checkCount < maxExistingChecks) {
checkCount += 1;
try {
const artifactResult = yield artifactClient.getArtifact(artifactName);
artifactExists = true;
core.info(`Found existing artifact '${artifactResult.artifact.name}'`);
const uppercaseAsciiStart = 65;
const letterIndex = Math.floor(Math.random() * 26);
const letter = String.fromCharCode(uppercaseAsciiStart + letterIndex);
artifactName += letter;
}
catch (e) {
// the artifact exists: add a random letter and try again
core.info(`No existing artifact named '${artifactName}'; using that`);
artifactExists = false;
}
} // - while artifactExists...
if (artifactExists) {
core.warning(`Can't find a unique artifact name for scan results after ${checkCount} tries`);
return;
}
const { filePath, uploadPath, error } = yield (0, exports.writeJsonToFile)(scanResult);
if (error) {
core.error(error);
core.warning(`Unable to write JSON document for scan result to file: ${error}`);
}
else {
const files = [filePath];
const rootDirectory = uploadPath;
core.info(`Writing artifact ${artifactName}`);
try {
const { id, size } = yield artifactClient.uploadArtifact(artifactName, files, rootDirectory, {});
core.info(`Scan result exported to artifact ${id}, size ${size}`);
core.setOutput("scan_result", artifactName);
}
catch (e) {
if (e instanceof Error) {
core.error(`Some items failed to export: ${e.message}`);
core.warning(`Some items failed to export: ${e.message}`);
}
else {
core.error(`Some items failed to export: ${e}`);
core.warning(`Some items failed to export: ${e}`);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/setup/index.js.map

Large diffs are not rendered by default.

35 changes: 31 additions & 4 deletions dist/sign/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116213,24 +116213,51 @@ const setupEndorctl = ({ version, checksum, api }) => __awaiter(void 0, void 0,
exports.setupEndorctl = setupEndorctl;
const uploadArtifact = (scanResult) => __awaiter(void 0, void 0, void 0, function* () {
const artifactClient = new artifact.DefaultArtifactClient();
const artifactName = "endor-scan";
const maxExistingChecks = 8;
let artifactName = "endor-scan";
// TODO - list artifacts and add a random identifier if artifact already exists
let artifactExists = true;
let checkCount = 0;
while (artifactExists && checkCount < maxExistingChecks) {
checkCount += 1;
try {
const artifactResult = yield artifactClient.getArtifact(artifactName);
artifactExists = true;
core.info(`Found existing artifact '${artifactResult.artifact.name}'`);
const uppercaseAsciiStart = 65;
const letterIndex = Math.floor(Math.random() * 26);
const letter = String.fromCharCode(uppercaseAsciiStart + letterIndex);
artifactName += letter;
}
catch (e) {
// the artifact exists: add a random letter and try again
core.info(`No existing artifact named '${artifactName}'; using that`);
artifactExists = false;
}
} // - while artifactExists...
if (artifactExists) {
core.warning(`Can't find a unique artifact name for scan results after ${checkCount} tries`);
return;
}
const { filePath, uploadPath, error } = yield (0, exports.writeJsonToFile)(scanResult);
if (error) {
core.error(error);
core.warning(`Unable to write JSON document for scan result to file: ${error}`);
}
else {
const files = [filePath];
const rootDirectory = uploadPath;
core.info(`Writing artifact ${artifactName}`);
try {
const { id, size } = yield artifactClient.uploadArtifact(artifactName, files, rootDirectory, {});
core.info(`Scan result exported to artifact ${id}, size ${size}`);
core.setOutput("scan_result", artifactName);
}
catch (e) {
if (e instanceof Error) {
core.error(`Some items failed to export: ${e.message}`);
core.warning(`Some items failed to export: ${e.message}`);
}
else {
core.error(`Some items failed to export: ${e}`);
core.warning(`Some items failed to export: ${e}`);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/sign/index.js.map

Large diffs are not rendered by default.

35 changes: 31 additions & 4 deletions dist/verify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116056,24 +116056,51 @@ const setupEndorctl = ({ version, checksum, api }) => __awaiter(void 0, void 0,
exports.setupEndorctl = setupEndorctl;
const uploadArtifact = (scanResult) => __awaiter(void 0, void 0, void 0, function* () {
const artifactClient = new artifact.DefaultArtifactClient();
const artifactName = "endor-scan";
const maxExistingChecks = 8;
let artifactName = "endor-scan";
// TODO - list artifacts and add a random identifier if artifact already exists
let artifactExists = true;
let checkCount = 0;
while (artifactExists && checkCount < maxExistingChecks) {
checkCount += 1;
try {
const artifactResult = yield artifactClient.getArtifact(artifactName);
artifactExists = true;
core.info(`Found existing artifact '${artifactResult.artifact.name}'`);
const uppercaseAsciiStart = 65;
const letterIndex = Math.floor(Math.random() * 26);
const letter = String.fromCharCode(uppercaseAsciiStart + letterIndex);
artifactName += letter;
}
catch (e) {
// the artifact exists: add a random letter and try again
core.info(`No existing artifact named '${artifactName}'; using that`);
artifactExists = false;
}
} // - while artifactExists...
if (artifactExists) {
core.warning(`Can't find a unique artifact name for scan results after ${checkCount} tries`);
return;
}
const { filePath, uploadPath, error } = yield (0, exports.writeJsonToFile)(scanResult);
if (error) {
core.error(error);
core.warning(`Unable to write JSON document for scan result to file: ${error}`);
}
else {
const files = [filePath];
const rootDirectory = uploadPath;
core.info(`Writing artifact ${artifactName}`);
try {
const { id, size } = yield artifactClient.uploadArtifact(artifactName, files, rootDirectory, {});
core.info(`Scan result exported to artifact ${id}, size ${size}`);
core.setOutput("scan_result", artifactName);
}
catch (e) {
if (e instanceof Error) {
core.error(`Some items failed to export: ${e.message}`);
core.warning(`Some items failed to export: ${e.message}`);
}
else {
core.error(`Some items failed to export: ${e}`);
core.warning(`Some items failed to export: ${e}`);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/verify/index.js.map

Large diffs are not rendered by default.

89 changes: 89 additions & 0 deletions licensed-failures.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
Checking cached dependency records for github-action
......FF................................F.F.F.....................F.FF......................F...F.......F..F...............F...F.F...FF...........FF.......F....................
Errors:
* github-action.npm.@actions/http-client-2.0.1
version: 2.0.1, filename: /Users/darren/endor/github-action/.licenses/npm/@actions/http-client-2.0.1.dep.yml, license: other, allowed: false
- license needs review: other

* github-action.npm.@actions/http-client-2.2.3
version: 2.2.3, filename: /Users/darren/endor/github-action/.licenses/npm/@actions/http-client-2.2.3.dep.yml, license: other, allowed: false
- license needs review: other

* github-action.npm.@pkgjs/parseargs
version: 0.11.0, filename: /Users/darren/endor/github-action/.licenses/npm/@pkgjs/parseargs.dep.yml, license: other, allowed: false
- license needs review: other

* github-action.npm.@protobuf-ts/plugin-framework
version: 2.9.4, filename: /Users/darren/endor/github-action/.licenses/npm/@protobuf-ts/plugin-framework.dep.yml, license: other, allowed: false
- license needs review: other

* github-action.npm.@protobuf-ts/runtime
version: 2.9.4, filename: /Users/darren/endor/github-action/.licenses/npm/@protobuf-ts/runtime.dep.yml, license: other, allowed: false
- license needs review: other

* github-action.npm.buffers
version: 0.1.1, filename: /Users/darren/endor/github-action/.licenses/npm/buffers.dep.yml, license: none, allowed: false
- missing license text
- license needs review: none

* github-action.npm.chainsaw
version: 0.1.0, filename: /Users/darren/endor/github-action/.licenses/npm/chainsaw.dep.yml, license: none, allowed: false
- missing license text
- license needs review: none

* github-action.npm.color-convert
version: 2.0.1, filename: /Users/darren/endor/github-action/.licenses/npm/color-convert.dep.yml, license: other, allowed: false
- license needs review: other

* github-action.npm.glob-7.2.3
version: 7.2.3, filename: /Users/darren/endor/github-action/.licenses/npm/glob-7.2.3.dep.yml, license: other, allowed: false
- license needs review: other

* github-action.npm.ieee754
version: 1.2.1, filename: /Users/darren/endor/github-action/.licenses/npm/ieee754.dep.yml, license: other, allowed: false
- license needs review: other

* github-action.npm.jackspeak
version: 3.4.3, filename: /Users/darren/endor/github-action/.licenses/npm/jackspeak.dep.yml, license: other, allowed: false
- license needs review: other

* github-action.npm.lodash
version: 4.17.21, filename: /Users/darren/endor/github-action/.licenses/npm/lodash.dep.yml, license: other, allowed: false
- license needs review: other

* github-action.npm.package-json-from-dist
version: 1.0.1, filename: /Users/darren/endor/github-action/.licenses/npm/package-json-from-dist.dep.yml, license: other, allowed: false
- license needs review: other

* github-action.npm.path-scurry
version: 1.11.1, filename: /Users/darren/endor/github-action/.licenses/npm/path-scurry.dep.yml, license: other, allowed: false
- license needs review: other

* github-action.npm.prettier
version: 2.8.8, filename: /Users/darren/endor/github-action/.licenses/npm/prettier.dep.yml, license: other, allowed: false
- license needs review: other

* github-action.npm.readable-stream-2.3.8
version: 2.3.8, filename: /Users/darren/endor/github-action/.licenses/npm/readable-stream-2.3.8.dep.yml, license: other, allowed: false
- license needs review: other

* github-action.npm.readable-stream-4.5.2
version: 4.5.2, filename: /Users/darren/endor/github-action/.licenses/npm/readable-stream-4.5.2.dep.yml, license: other, allowed: false
- license needs review: other

* github-action.npm.string_decoder-1.1.1
version: 1.1.1, filename: /Users/darren/endor/github-action/.licenses/npm/string_decoder-1.1.1.dep.yml, license: other, allowed: false
- license needs review: other

* github-action.npm.string_decoder-1.3.0
version: 1.3.0, filename: /Users/darren/endor/github-action/.licenses/npm/string_decoder-1.3.0.dep.yml, license: other, allowed: false
- license needs review: other

* github-action.npm.traverse
version: 0.3.9, filename: /Users/darren/endor/github-action/.licenses/npm/traverse.dep.yml, license: other, allowed: false
- license needs review: other


176 dependencies checked, 22 errors found.

Licensed found errors during source enumeration. Please see https://github.com/github/licensed/tree/master/docs/commands/status.md#status-errors-and-resolutions for possible resolutions.
40 changes: 36 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,45 @@ export const setupEndorctl = async ({ version, checksum, api }: SetupProps) => {

export const uploadArtifact = async (scanResult: string) => {
const artifactClient = new artifact.DefaultArtifactClient();
const artifactName = "endor-scan";
const maxExistingChecks = 8;
let artifactName = "endor-scan";
// TODO - list artifacts and add a random identifier if artifact already exists
let artifactExists = true;
let checkCount = 0;
while (artifactExists && checkCount < maxExistingChecks) {
checkCount += 1;
try {
const artifactResult: artifact.GetArtifactResponse =
await artifactClient.getArtifact(artifactName);
artifactExists = true;
core.info(`Found existing artifact '${artifactResult.artifact.name}'`);
const uppercaseAsciiStart = 65;
const letterIndex = Math.floor(Math.random() * 26);
const letter = String.fromCharCode(uppercaseAsciiStart + letterIndex);
artifactName += letter;
} catch (e) {
// the artifact exists: add a random letter and try again
core.info(`No existing artifact named '${artifactName}'; using that`);
artifactExists = false;
}
} // - while artifactExists...

if (artifactExists) {
core.warning(
`Can't find a unique artifact name for scan results after ${checkCount} tries`
);
return;
}

const { filePath, uploadPath, error } = await writeJsonToFile(scanResult);
if (error) {
core.error(error);
core.warning(
`Unable to write JSON document for scan result to file: ${error}`
);
} else {
const files = [filePath];
const rootDirectory = uploadPath;
core.info(`Writing artifact ${artifactName}`);
try {
const { id, size } = await artifactClient.uploadArtifact(
artifactName,
Expand All @@ -305,11 +336,12 @@ export const uploadArtifact = async (scanResult: string) => {
{}
);
core.info(`Scan result exported to artifact ${id}, size ${size}`);
core.setOutput("scan_result", artifactName);
} catch (e) {
if (e instanceof Error) {
core.error(`Some items failed to export: ${e.message}`);
core.warning(`Some items failed to export: ${e.message}`);
} else {
core.error(`Some items failed to export: ${e}`);
core.warning(`Some items failed to export: ${e}`);
}
}
}
Expand Down
Loading