Fixes #15 Add omitBody and omitName

This commit is contained in:
Nick Cipollo
2020-05-25 16:23:42 -04:00
parent 93adae701b
commit 8954a2e764
5 changed files with 87 additions and 26 deletions

View File

@@ -12,6 +12,8 @@ This action will create a github release and optionally upload an artifact to it
- **commit**: An optional commit reference. This will be used to create the tag if it does not exist.
- **draft**: Optionally marks this release as a draft release. Set to `true` to enable.
- **name**: An optional name for the release. If this is omitted the tag will be used.
- **omitBody**: Indicates if the release body should be omitted. This is primarily useful for preserving the release body during updates.
- **omitName**: Indicates if the release name should be omitted. This is primarily useful for preserving the release name during updates.
- **prerelease**: Optionally marks this release as prerelease. Set to true to enable.
- **replacesArtifacts**: Indicates if existing release artifacts should be replaced. Defaults to true.
- **tag**: An optional tag for the release. If this is omitted the git ref will be used (if it is a tag).

View File

@@ -58,7 +58,7 @@ describe('Inputs', () => {
it('returns empty artifacts', () => {
mockGetInput.mockReturnValueOnce('')
.mockReturnValueOnce('')
expect(inputs.artifacts).toEqual([])
expect(mockGlob).toBeCalledTimes(0)
})
@@ -66,7 +66,7 @@ describe('Inputs', () => {
it('returns input.artifacts', () => {
mockGetInput.mockReturnValueOnce('art1')
.mockReturnValueOnce('contentType')
expect(inputs.artifacts).toEqual(artifacts)
expect(mockGlob).toBeCalledTimes(1)
expect(mockGlob).toBeCalledWith('art1', 'contentType')
@@ -74,17 +74,17 @@ describe('Inputs', () => {
it('returns input.artifacts with default contentType', () => {
mockGetInput.mockReturnValueOnce('art1')
expect(inputs.artifacts).toEqual(artifacts)
expect(mockGlob).toBeCalledTimes(1)
expect(mockGlob).toBeCalledWith('art1', 'raw')
})
it('returns input.artifact', () => {
mockGetInput.mockReturnValueOnce('')
.mockReturnValueOnce('art2')
.mockReturnValueOnce('contentType')
expect(inputs.artifacts).toEqual(artifacts)
expect(mockGlob).toBeCalledTimes(1)
expect(mockGlob).toBeCalledWith('art2', 'contentType')
@@ -93,20 +93,36 @@ describe('Inputs', () => {
describe('body', () => {
it('returns input body', () => {
mockGetInput.mockReturnValue('body')
mockGetInput
.mockReturnValueOnce('false')
.mockReturnValueOnce('body')
expect(inputs.body).toBe('body')
})
it('returns body file contents', () => {
mockGetInput.mockReturnValueOnce('').mockReturnValueOnce('a/path')
mockGetInput
.mockReturnValueOnce('false')
.mockReturnValueOnce('')
.mockReturnValueOnce('a/path')
mockReadFileSync.mockReturnValue('file')
expect(inputs.body).toBe('file')
})
it('returns empty', () => {
mockGetInput
.mockReturnValueOnce('false')
.mockReturnValueOnce('')
.mockReturnValueOnce('')
expect(inputs.body).toBe('')
})
it('returns null when omitted', () => {
mockGetInput
.mockReturnValueOnce('true')
.mockReturnValueOnce('body')
expect(inputs.body).toBeUndefined()
})
})
describe('draft', () => {
@@ -122,12 +138,23 @@ describe('Inputs', () => {
describe('name', () => {
it('returns input name', () => {
mockGetInput.mockReturnValue('name')
mockGetInput
.mockReturnValueOnce('false')
.mockReturnValueOnce('name')
expect(inputs.name).toBe('name')
})
it('returns null when omitted', () => {
mockGetInput
.mockReturnValueOnce('true')
.mockReturnValueOnce('name')
expect(inputs.body).toBeUndefined()
})
it('returns tag', () => {
mockGetInput.mockReturnValue('')
mockGetInput
.mockReturnValueOnce('false')
.mockReturnValueOnce('')
context.ref = 'refs/tags/sha-tag'
expect(inputs.name).toBe('sha-tag')
})
@@ -184,4 +211,4 @@ describe('Inputs', () => {
mockGlob.mockImplementation(() => artifacts)
return new MockGlobber()
}
})
})

View File

@@ -2,42 +2,62 @@ name: 'Create Release'
description: 'Creates github releases'
author: 'Nick Cipollo'
inputs:
allowUpdates:
allowUpdates:
description: 'An optional flag which indicates if we should update a release if it already exists. Defaults to false.'
required: false
default: ''
artifact:
deprecationMessage: Use 'artifacts' instead.
description: 'An optional set of paths representing artifacts to upload to the release. This may be a single path or a comma delimited list of paths (or globs)'
required: false
default: ''
artifacts:
description: 'An optional set of paths representing artifacts to upload to the release. This may be a single path or a comma delimited list of paths (or globs)'
default: ''
required: false
default: ''
artifactContentType:
description: 'The content type of the artifact. Defaults to raw'
required: false
default: ''
body:
description: 'An optional body for the release.'
required: false
default: ''
bodyFile:
description: 'An optional body file for the release. This should be the path to the file'
default: ''
required: false
default: ''
commit:
description: "An optional commit reference. This will be used to create the tag if it does not exist."
required: false
default: ''
draft:
description: "Optionally marks this release as a draft release. Set to true to enable."
required: false
default: ''
name:
description: 'An optional name for the release. If this is omitted the tag will be used.'
required: false
default: ''
omitBody:
description: 'Indicates if the release body should be omitted. This is primarily useful for preserving the release body during updates.'
required: false
default: 'false'
omitName:
description: 'Indicates if the release name should be omitted. This is primarily useful for preserving the release name during updates.'
required: false
default: 'false'
prerelease:
description: "Optionally marks this release as prerelease. Set to true to enable."
required: false
default: ''
replacesArtifacts:
description: "Indicates if existing release artifacts should be replaced. Defaults to true."
default: 'true'
required: false
default: 'true'
tag:
description: 'An optional tag for the release. If this is omitted the git ref will be used (if it is a tag).'
required: false
default: ''
token:
description: 'The Github token.'

View File

@@ -1,4 +1,4 @@
import { GithubError } from "./GithubError"
import {GithubError} from "./GithubError"
export class ErrorMessage {
private error: any
@@ -18,7 +18,7 @@ export class ErrorMessage {
}
}
get status():number {
get status(): number {
return this.error.status
}

View File

@@ -1,16 +1,16 @@
import * as core from '@actions/core';
import { Context } from "@actions/github/lib/context";
import { readFileSync } from 'fs';
import { ArtifactGlobber } from './ArtifactGlobber';
import { Artifact } from './Artifact';
import {Context} from "@actions/github/lib/context";
import {readFileSync} from 'fs';
import {ArtifactGlobber} from './ArtifactGlobber';
import {Artifact} from './Artifact';
export interface Inputs {
readonly allowUpdates: boolean
readonly artifacts: Artifact[]
readonly body: string
readonly body?: string
readonly commit: string
readonly draft: boolean
readonly name: string
readonly name?: string
readonly prerelease: boolean
readonly replacesArtifacts: boolean
readonly tag: string
@@ -47,7 +47,9 @@ export class CoreInputs implements Inputs {
return []
}
get body(): string {
get body(): string | undefined {
if (CoreInputs.omitBody()) return undefined
const body = core.getInput('body')
if (body) {
return body
@@ -61,6 +63,10 @@ export class CoreInputs implements Inputs {
return ''
}
private static omitBody(): boolean {
return core.getInput('omitBody') == 'true'
}
get commit(): string {
return core.getInput('commit')
}
@@ -70,7 +76,9 @@ export class CoreInputs implements Inputs {
return draft == 'true'
}
get name(): string {
get name(): string | undefined {
if (CoreInputs.omitName()) return undefined
const name = core.getInput('name')
if (name) {
return name
@@ -79,6 +87,10 @@ export class CoreInputs implements Inputs {
return this.tag
}
private static omitName(): boolean {
return core.getInput('omitName') == 'true'
}
get prerelease(): boolean {
const preRelease = core.getInput('prerelease')
return preRelease == 'true'
@@ -105,10 +117,10 @@ export class CoreInputs implements Inputs {
}
get token(): string {
return core.getInput('token', { required: true })
return core.getInput('token', {required: true})
}
stringFromFile(path: string): string {
return readFileSync(path, 'utf-8')
}
}
}