diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 7e7883c..7d65e65 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -64,8 +64,22 @@ describe('run', () => { .mockImplementation() }) + it('fails if no action workspace found', async () => { + // Mock the environment + process.env.GITHUB_WORKSPACE = '' + + // Run the action + await main.run() + + // Check the results + expect(setFailedMock).toHaveBeenCalledWith( + 'Could not find GITHUB_WORKSPACE.' + ) + }) + it('fails if no repository found', async () => { // Mock the environment + process.env.GITHUB_WORKSPACE = '.' process.env.GITHUB_REPOSITORY = '' // Run the action @@ -77,6 +91,7 @@ describe('run', () => { it('fails if no token found', async () => { // Mock the environment + process.env.GITHUB_WORKSPACE = '.' process.env.GITHUB_REPOSITORY = 'test-org/test-repo' process.env.TOKEN = '' @@ -89,6 +104,7 @@ describe('run', () => { it('fails if no source commit found', async () => { // Mock the environment + process.env.GITHUB_WORKSPACE = '.' process.env.GITHUB_REPOSITORY = 'test-org/test-repo' process.env.TOKEN = 'test' process.env.GITHUB_SHA = '' @@ -101,6 +117,7 @@ describe('run', () => { }) it('fails if trigger is not release or tag push', async () => { + process.env.GITHUB_WORKSPACE = '.' process.env.GITHUB_REPOSITORY = 'test-org/test-repo' process.env.GITHUB_SHA = 'test-sha' process.env.TOKEN = 'token' @@ -117,6 +134,7 @@ describe('run', () => { }) it('fails if the trigger is a push, but not a tag push', async () => { + process.env.GITHUB_WORKSPACE = '.' process.env.GITHUB_REPOSITORY = 'test-org/test-repo' process.env.GITHUB_SHA = 'test-sha' process.env.TOKEN = 'token' @@ -131,6 +149,7 @@ describe('run', () => { }) it('fails if the value of the tag input is not a valid semver', async () => { + process.env.GITHUB_WORKSPACE = '.' process.env.GITHUB_REPOSITORY = 'test-org/test-repo' process.env.GITHUB_SHA = 'test-sha' process.env.TOKEN = 'token' @@ -155,6 +174,7 @@ describe('run', () => { it('fails if staging files fails', async () => { // Mock the environment + process.env.GITHUB_WORKSPACE = '.' process.env.GITHUB_REPOSITORY = 'test-org/test-repo' github.context.eventName = 'release' process.env.GITHUB_SHA = 'test-sha' @@ -179,6 +199,7 @@ describe('run', () => { it('fails if creating temp directory fails', async () => { // Mock the environment + process.env.GITHUB_WORKSPACE = '.' process.env.GITHUB_REPOSITORY = 'test-org/test-repo' github.context.eventName = 'release' process.env.GITHUB_SHA = 'test-sha' @@ -203,6 +224,7 @@ describe('run', () => { it('fails if creating archives fails', async () => { // Mock the environment + process.env.GITHUB_WORKSPACE = '.' process.env.GITHUB_REPOSITORY = 'test-org/test-repo' github.context.eventName = 'release' process.env.GITHUB_SHA = 'test-sha' @@ -226,6 +248,7 @@ describe('run', () => { }) it('fails if getting container registry URL fails', async () => { + process.env.GITHUB_WORKSPACE = '.' process.env.GITHUB_REPOSITORY = 'test-org/test-repo' github.context.eventName = 'release' process.env.GITHUB_SHA = 'test-sha' @@ -268,6 +291,7 @@ describe('run', () => { }) it('fails if publishing OCI artifact fails', async () => { + process.env.GITHUB_WORKSPACE = '.' process.env.GITHUB_REPOSITORY = 'test-org/test-repo' github.context.eventName = 'release' process.env.GITHUB_SHA = 'test-sha' @@ -314,6 +338,7 @@ describe('run', () => { }) it('uploads the artifact, returns package metadata from GHCR, and cleans up tmp dirs', async () => { + process.env.GITHUB_WORKSPACE = '.' process.env.GITHUB_REPOSITORY = 'test-org/test-repo' github.context.eventName = 'release' process.env.GITHUB_SHA = 'test-sha' diff --git a/action.yml b/action.yml index 99dd0b3..527c2a0 100644 --- a/action.yml +++ b/action.yml @@ -21,7 +21,7 @@ runs: using: 'composite' steps: - name: Publish Action Package - run: 'node ${{github.action_path}}/dist/index.js' + run: 'npm --prefix "${{github.action_path}}" start' shell: bash id: publish env: @@ -29,13 +29,13 @@ runs: GITHUB_REPOSITORY: ${{ github.repository }} GITHUB_REF: ${{ github.ref }} GITHUB_SHA: ${{ github.sha }} + GITHUB_WORKSPACE: ${{ github.workspace }} - name: Output variables shell: bash run: | - echo "package manifest": ${{steps.publish.outputs.package-manifest}} - 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}} + 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 diff --git a/badges/coverage.svg b/badges/coverage.svg index 8225784..56c2350 100644 --- a/badges/coverage.svg +++ b/badges/coverage.svg @@ -1 +1 @@ -Coverage: 93.96%Coverage93.96% \ No newline at end of file +Coverage: 94.08%Coverage94.08% \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 0b7d415..5f23d50 100644 --- a/dist/index.js +++ b/dist/index.js @@ -74703,6 +74703,11 @@ const semver_1 = __importDefault(__nccwpck_require__(11383)); */ async function run() { try { + const workspace = process.env.GITHUB_WORKSPACE || ''; + if (workspace === '') { + core.setFailed(`Could not find GITHUB_WORKSPACE.`); + return; + } const repository = process.env.GITHUB_REPOSITORY || ''; if (repository === '') { core.setFailed(`Could not find Repository.`); @@ -74721,7 +74726,7 @@ async function run() { const semanticVersion = parseSourceSemanticVersion(); // Create a temporary directory to stage files for packaging in archives const stagedActionFilesDir = fsHelper.createTempDir('staging'); - fsHelper.stageActionFiles('.', stagedActionFilesDir); + fsHelper.stageActionFiles(workspace, stagedActionFilesDir); // Create a temporary directory to store the archives const archiveDir = fsHelper.createTempDir('archive'); const archives = await fsHelper.createArchives(stagedActionFilesDir, archiveDir); diff --git a/package.json b/package.json index 7fe0e9e..3479f39 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "package": "ncc build src/index.ts --license licenses.txt", "package:watch": "npm run package -- --watch", "test": "jest", + "start": "node dist/index.js", "all": "npm run format:write && npm run lint && npm run test && npm run coverage && npm run package" }, "license": "MIT", diff --git a/src/main.ts b/src/main.ts index 0d29c18..be35c96 100644 --- a/src/main.ts +++ b/src/main.ts @@ -12,6 +12,12 @@ import semver from 'semver' */ export async function run(): Promise { try { + const workspace: string = process.env.GITHUB_WORKSPACE || '' + if (workspace === '') { + core.setFailed(`Could not find GITHUB_WORKSPACE.`) + return + } + const repository: string = process.env.GITHUB_REPOSITORY || '' if (repository === '') { core.setFailed(`Could not find Repository.`) @@ -33,7 +39,7 @@ export async function run(): Promise { // Create a temporary directory to stage files for packaging in archives const stagedActionFilesDir = fsHelper.createTempDir('staging') - fsHelper.stageActionFiles('.', stagedActionFilesDir) + fsHelper.stageActionFiles(workspace, stagedActionFilesDir) // Create a temporary directory to store the archives const archiveDir = fsHelper.createTempDir('archive')