diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index eb12a52..34b94f8 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -24,6 +24,7 @@ let isDirectoryMock: jest.SpyInstance let createArchivesMock: jest.SpyInstance let removeDirMock: jest.SpyInstance let bundleFilesintoDirectoryMock: jest.SpyInstance +let isActionRepoMock: jest.SpyInstance // Mock the GHCR Client let publishOCIArtifactMock: jest.SpyInstance @@ -49,6 +50,7 @@ describe('action', () => { bundleFilesintoDirectoryMock = jest .spyOn(fsHelper, 'bundleFilesintoDirectory') .mockImplementation() + isActionRepoMock = jest.spyOn(fsHelper, 'isActionRepo').mockImplementation() // GHCR Client mocks publishOCIArtifactMock = jest @@ -61,7 +63,7 @@ describe('action', () => { process.env.GITHUB_REPOSITORY = '' // Run the action - await main.run() + await main.run('directory1 directory2') // Check the results expect(setFailedMock).toHaveBeenCalledWith('Could not find Repository.') @@ -73,7 +75,7 @@ describe('action', () => { github.context.eventName = 'push' // Run the action - await main.run() + await main.run('directory1 directory2') // Check the results expect(setFailedMock).toHaveBeenCalledWith( @@ -93,7 +95,7 @@ describe('action', () => { } // Run the action - await main.run() + await main.run('directory1 directory2') // Check the results expect(setFailedMock).toHaveBeenCalledWith( @@ -127,7 +129,7 @@ describe('action', () => { }) // Run the action - await main.run() + await main.run('directory1 directory2') // Check the results expect(setFailedMock).toHaveBeenCalledWith('Something went wrong') @@ -153,6 +155,7 @@ describe('action', () => { }) isDirectoryMock.mockImplementation(() => true) + isActionRepoMock.mockImplementation(() => true) createTempDirMock.mockImplementation(() => '/tmp/test') @@ -161,7 +164,7 @@ describe('action', () => { }) // Run the action - await main.run() + await main.run('directory') // Check the results expect(isDirectoryMock).toHaveBeenCalledWith('directory') @@ -205,6 +208,7 @@ async function testHappyPath(version: string, path: string): Promise { }) isDirectoryMock.mockImplementation(() => true) + isActionRepoMock.mockImplementation(() => true) bundleFilesintoDirectoryMock.mockImplementation(() => { return '/tmp/test' @@ -232,7 +236,7 @@ async function testHappyPath(version: string, path: string): Promise { }) // Run the action - await main.run() + await main.run(path) expect(publishOCIArtifactMock).toHaveBeenCalledTimes(1) diff --git a/action.yml b/action.yml index ac9a220..f204310 100644 --- a/action.yml +++ b/action.yml @@ -15,10 +15,13 @@ inputs: outputs: package-url: description: 'The name of package published to GHCR along with semver. For example, https://ghcr.io/actions/package-action:1.0.1' + value: ${{steps.publish.outputs.package-url}} package-manifest: description: 'The package manifest of the published package in JSON format' + value: ${{steps.publish.outputs.package-manifest}} package-manifest-sha: description: 'A sha256 hash of the package manifest' + value: ${{steps.publish.outputs.package-manifest-sha}} runs: using: 'composite' steps: @@ -36,10 +39,10 @@ runs: echo "package manifest sha": ${{steps.publish.outputs.package-manifest-sha}} echo "package url": ${{steps.publish.outputs.package-url}} echo "subject name": ${{github.repository}}_${{github.ref}} - - name: Generate Provenance Attestation - uses: github-early-access/generate-build-provenance@main - id: build-provenance - with: - subject-name: ${{github.repository}}_${{github.ref}} - subject-digest: ${{steps.publish.outputs.package-manifest-sha}} - push-to-registry: false + # - name: Generate Provenance Attestation + # uses: github-early-access/generate-build-provenance@main + # id: build-provenance + # with: + # subject-name: ${{github.repository}}_${{github.ref}} + # subject-digest: ${{steps.publish.outputs.package-manifest-sha}} + # push-to-registry: false diff --git a/badges/coverage.svg b/badges/coverage.svg index 6d43479..abd228b 100644 --- a/badges/coverage.svg +++ b/badges/coverage.svg @@ -1 +1 @@ -Coverage: 95.05%Coverage95.05% \ No newline at end of file +Coverage: 93.81%Coverage93.81% \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index fb91e07..379212e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -75061,13 +75061,6 @@ async function run(pathInput) { return; } const token = process.env.TOKEN; - const response = await fetch(process.env.GITHUB_API_URL + '/packages/container-registry-url'); - if (!response.ok) { - throw new Error(`Failed to fetch status page: ${response.statusText}`); - } - const data = await response.json(); - const registryURL = new URL(data.url); - console.log(`Container registry URL: ${registryURL}`); // Gather & validate user input // Paths to be included in the OCI image // const paths: string[] = core.getInput('path').split(' ') @@ -75097,6 +75090,13 @@ async function run(pathInput) { const manifestHash = manifestSHA .update(JSON.stringify(manifest)) .digest('hex'); + const response = await fetch(`${process.env.GITHUB_API_URL}/packages/container-registry-url`); + if (!response.ok) { + throw new Error(`Failed to fetch status page: ${response.statusText}`); + } + const data = await response.json(); + const registryURL = new URL(data.url); + console.log(`Container registry URL: ${registryURL}`); const packageURL = await ghcr.publishOCIArtifact(token, registryURL, repository, releaseId.toString(), targetVersion.raw, archives.zipFile, archives.tarFile, manifest, true); core.setOutput('package-url', packageURL.toString()); core.setOutput('package-manifest', JSON.stringify(manifest)); @@ -75104,7 +75104,8 @@ async function run(pathInput) { } catch (error) { // Fail the workflow run if an error occurs - // if (error instanceof Error) core.setFailed(error.message) + if (error instanceof Error) + core.setFailed(error.message); } finally { // Clean up any temporary directories that exist diff --git a/src/main.ts b/src/main.ts index 8e936ae..4fbf8bb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -85,7 +85,7 @@ export async function run(pathInput: string): Promise { .digest('hex') const response = await fetch( - process.env.GITHUB_API_URL + '/packages/container-registry-url' + `${process.env.GITHUB_API_URL}/packages/container-registry-url` ) if (!response.ok) { throw new Error(`Failed to fetch status page: ${response.statusText}`) @@ -111,7 +111,7 @@ export async function run(pathInput: string): Promise { core.setOutput('package-manifest-sha', `sha256:${manifestHash}`) } catch (error) { // Fail the workflow run if an error occurs - // if (error instanceof Error) core.setFailed(error.message) + if (error instanceof Error) core.setFailed(error.message) } finally { // Clean up any temporary directories that exist for (const tmpDir of tmpDirs) {