Merge pull request #88 from immutable-actions/conorsloan/use-npm-to-run

kick off action using custom npm script and prefix arg
This commit is contained in:
Conor Sloan
2024-02-06 16:48:41 +00:00
committed by GitHub
6 changed files with 45 additions and 8 deletions
+25
View File
@@ -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'
+5 -5
View File
@@ -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
+1 -1
View File
@@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="116" height="20" role="img" aria-label="Coverage: 93.96%"><title>Coverage: 93.96%</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="116" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="63" height="20" fill="#555"/><rect x="63" width="53" height="20" fill="#4c1"/><rect width="116" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="325" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="530">Coverage</text><text x="325" y="140" transform="scale(.1)" fill="#fff" textLength="530">Coverage</text><text aria-hidden="true" x="885" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">93.96%</text><text x="885" y="140" transform="scale(.1)" fill="#fff" textLength="430">93.96%</text></g></svg>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="116" height="20" role="img" aria-label="Coverage: 94.08%"><title>Coverage: 94.08%</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="116" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="63" height="20" fill="#555"/><rect x="63" width="53" height="20" fill="#4c1"/><rect width="116" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="325" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="530">Coverage</text><text x="325" y="140" transform="scale(.1)" fill="#fff" textLength="530">Coverage</text><text aria-hidden="true" x="885" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">94.08%</text><text x="885" y="140" transform="scale(.1)" fill="#fff" textLength="430">94.08%</text></g></svg>

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Generated Vendored
+6 -1
View File
@@ -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);
+1
View File
@@ -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",
+7 -1
View File
@@ -12,6 +12,12 @@ import semver from 'semver'
*/
export async function run(): Promise<void> {
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<void> {
// 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')