diff --git a/__tests__/Inputs.test.ts b/__tests__/Inputs.test.ts index b76223e..4b8cd54 100644 --- a/__tests__/Inputs.test.ts +++ b/__tests__/Inputs.test.ts @@ -1,5 +1,6 @@ const mockGetInput = jest.fn(); const mockReadFileSync = jest.fn(); +const mockStatSync = jest.fn(); import { Inputs } from "../src/Inputs"; import { Context } from "@actions/github/lib/context"; @@ -10,7 +11,10 @@ jest.mock('@actions/core', () => { }); jest.mock('fs', () => { - return { readFileSync: mockReadFileSync }; + return { + readFileSync: mockReadFileSync, + statSync: mockStatSync + }; }); describe('Inputs', () => { @@ -27,6 +31,12 @@ describe('Inputs', () => { expect(inputs.artifact).toBe("a/path") }) + it('returns artifactContentLength', () => { + mockGetInput.mockReturnValue("a/path") + mockStatSync.mockReturnValue({size: 100}) + expect(inputs.artifactContentLength).toBe(100) + }) + it('returns targetCommit', () => { mockGetInput.mockReturnValue("42") expect(inputs.commit).toBe("42") @@ -37,6 +47,17 @@ describe('Inputs', () => { expect(inputs.token).toBe("42") }) + describe('artifactContentType', () => { + it('returns input content-type', () => { + mockGetInput.mockReturnValue("type") + expect(inputs.artifactContentType).toBe("type") + }) + + it('returns raw as default', () => { + expect(inputs.artifactContentType).toBe("raw") + }) + }) + describe('description', () => { it('returns input description', () => { mockGetInput.mockReturnValue("description") diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts deleted file mode 100644 index 48f15ff..0000000 --- a/__tests__/main.test.ts +++ /dev/null @@ -1,3 +0,0 @@ -describe('TODO - Add a test suite', () => { - it('TODO - Add a test', async () => {}); -}); diff --git a/action.yml b/action.yml index 9489056..3c08666 100644 --- a/action.yml +++ b/action.yml @@ -5,6 +5,9 @@ inputs: artifact: description: 'A path to an optional artifact to upload to the release.' default: '' + artifactContentType: + description: 'The content type of the artifact. Defaults to raw' + default: '' commit: description: 'An optional commit reference. This will be used to create the tag if it doesn't exist.' default: '' diff --git a/src/Inputs.ts b/src/Inputs.ts index cbccf0e..695b02b 100644 --- a/src/Inputs.ts +++ b/src/Inputs.ts @@ -1,7 +1,6 @@ import * as core from '@actions/core'; import { Context } from "@actions/github/lib/context"; -import { isObject } from 'util'; -import { fstat, readFileSync } from 'fs'; +import { readFileSync, statSync } from 'fs'; export class Inputs { private context: Context @@ -14,18 +13,31 @@ export class Inputs { return core.getInput('artifact') } + get artifactContentType(): string { + const type = core.getInput('artifactContentType') + if(type) { + return type; + } + + return 'raw' + } + + get artifactContentLength(): number { + return statSync(this.artifact).size + } + get commit(): string { return core.getInput('commit') } get description(): string { const description = core.getInput('description') - if(description) { + if (description) { return description } - + const descriptionFile = core.getInput('descriptionFile') - if(descriptionFile) { + if (descriptionFile) { return this.stringFromFile(descriptionFile) } @@ -41,10 +53,6 @@ export class Inputs { return this.tag } - get token(): string { - return core.getInput('token', { required: true }) - } - get tag(): string { const tag = core.getInput('tag') if (tag) { @@ -60,6 +68,10 @@ export class Inputs { throw Error("No tag found in ref or input!") } + get token(): string { + return core.getInput('token', { required: true }) + } + private stringFromFile(path: string): string { return readFileSync(path, 'utf-8') }