From d1bc1df0f88b88f9d83149470298fe337f7bc255 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Fri, 13 Oct 2023 00:23:08 -0500 Subject: [PATCH] Add workflow to run unit tests for Pepr module Refactor getRepositoryNames() in Pepr module to handle images with digest ref Add test case to unit tests to validate handling of images with digest --- .github/workflows/test-aws-init-package.yml | 14 +++++--- .github/workflows/test-pepr-module.yml | 40 +++++++++++++++++++++ capabilities/lib/utils.test.ts | 5 +++ capabilities/lib/utils.ts | 4 ++- 4 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/test-pepr-module.yml diff --git a/.github/workflows/test-aws-init-package.yml b/.github/workflows/test-aws-init-package.yml index f4c4e8d..908f7a0 100644 --- a/.github/workflows/test-aws-init-package.yml +++ b/.github/workflows/test-aws-init-package.yml @@ -1,11 +1,15 @@ name: Test AWS Init Package on: - push: - branches: - - main pull_request: - branches: - - main + paths-ignore: + - "**.md" + - "**.jpg" + - "**.png" + - "**.gif" + - "**.svg" + - "adr/**" + - "docs/**" + - "CODEOWNERS" workflow_dispatch: inputs: diff --git a/.github/workflows/test-pepr-module.yml b/.github/workflows/test-pepr-module.yml new file mode 100644 index 0000000..420a94d --- /dev/null +++ b/.github/workflows/test-pepr-module.yml @@ -0,0 +1,40 @@ +name: Test Pepr Module +on: + pull_request: + paths-ignore: + - "**.md" + - "**.jpg" + - "**.png" + - "**.gif" + - "**.svg" + - "adr/**" + - "docs/**" + - "CODEOWNERS" + +permissions: + contents: read + +# Abort prior jobs in the same workflow / PR +concurrency: + group: pepr-module-${{ github.ref }} + cancel-in-progress: true + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 + + - name: Setup NodeJS + uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1 + with: + node-version: 18 + cache: "npm" + cache-dependency-path: "package-lock.json" + + - name: Install Node dependencies + run: npm ci + + - name: Run unit tests for Pepr module + run: make test-module diff --git a/capabilities/lib/utils.test.ts b/capabilities/lib/utils.test.ts index 7680c96..8d9e0d7 100644 --- a/capabilities/lib/utils.test.ts +++ b/capabilities/lib/utils.test.ts @@ -27,6 +27,11 @@ describe("getRepositoryNames", () => { input: "registry1.dso.mil/defenseunicorns/zarf/agent:latest", expected: "defenseunicorns/zarf/agent", }, + { + input: + "defenseunicorns/zarf-game@sha256:f78e442f0f3eb3e9459b5ae6b1a8fda62f8dfe818112e7d130a4e8ae72b3cbff", + expected: "defenseunicorns/zarf-game", + }, ]; testCases.forEach(({ input, expected }) => { diff --git a/capabilities/lib/utils.ts b/capabilities/lib/utils.ts index 51cb17a..2730a12 100644 --- a/capabilities/lib/utils.ts +++ b/capabilities/lib/utils.ts @@ -46,8 +46,10 @@ export function getRepositoryNames(images: string[]): string[] { } const repoNames = images.map((image: string) => { - if (image.includes(":")) { + if (image.includes(":") && !image.includes("@sha256")) { image = image.split(":")[0]; + } else if (image.includes("@sha256")) { + image = image.split("@sha256")[0]; } const firstSlashIndex = image.indexOf("/");