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. - **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. - **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. - **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. - **prerelease**: Optionally marks this release as prerelease. Set to true to enable.
- **replacesArtifacts**: Indicates if existing release artifacts should be replaced. Defaults to true. - **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). - **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', () => { it('returns empty artifacts', () => {
mockGetInput.mockReturnValueOnce('') mockGetInput.mockReturnValueOnce('')
.mockReturnValueOnce('') .mockReturnValueOnce('')
expect(inputs.artifacts).toEqual([]) expect(inputs.artifacts).toEqual([])
expect(mockGlob).toBeCalledTimes(0) expect(mockGlob).toBeCalledTimes(0)
}) })
@@ -66,7 +66,7 @@ describe('Inputs', () => {
it('returns input.artifacts', () => { it('returns input.artifacts', () => {
mockGetInput.mockReturnValueOnce('art1') mockGetInput.mockReturnValueOnce('art1')
.mockReturnValueOnce('contentType') .mockReturnValueOnce('contentType')
expect(inputs.artifacts).toEqual(artifacts) expect(inputs.artifacts).toEqual(artifacts)
expect(mockGlob).toBeCalledTimes(1) expect(mockGlob).toBeCalledTimes(1)
expect(mockGlob).toBeCalledWith('art1', 'contentType') expect(mockGlob).toBeCalledWith('art1', 'contentType')
@@ -74,17 +74,17 @@ describe('Inputs', () => {
it('returns input.artifacts with default contentType', () => { it('returns input.artifacts with default contentType', () => {
mockGetInput.mockReturnValueOnce('art1') mockGetInput.mockReturnValueOnce('art1')
expect(inputs.artifacts).toEqual(artifacts) expect(inputs.artifacts).toEqual(artifacts)
expect(mockGlob).toBeCalledTimes(1) expect(mockGlob).toBeCalledTimes(1)
expect(mockGlob).toBeCalledWith('art1', 'raw') expect(mockGlob).toBeCalledWith('art1', 'raw')
}) })
it('returns input.artifact', () => { it('returns input.artifact', () => {
mockGetInput.mockReturnValueOnce('') mockGetInput.mockReturnValueOnce('')
.mockReturnValueOnce('art2') .mockReturnValueOnce('art2')
.mockReturnValueOnce('contentType') .mockReturnValueOnce('contentType')
expect(inputs.artifacts).toEqual(artifacts) expect(inputs.artifacts).toEqual(artifacts)
expect(mockGlob).toBeCalledTimes(1) expect(mockGlob).toBeCalledTimes(1)
expect(mockGlob).toBeCalledWith('art2', 'contentType') expect(mockGlob).toBeCalledWith('art2', 'contentType')
@@ -93,20 +93,36 @@ describe('Inputs', () => {
describe('body', () => { describe('body', () => {
it('returns input body', () => { it('returns input body', () => {
mockGetInput.mockReturnValue('body') mockGetInput
.mockReturnValueOnce('false')
.mockReturnValueOnce('body')
expect(inputs.body).toBe('body') expect(inputs.body).toBe('body')
}) })
it('returns body file contents', () => { it('returns body file contents', () => {
mockGetInput.mockReturnValueOnce('').mockReturnValueOnce('a/path') mockGetInput
.mockReturnValueOnce('false')
.mockReturnValueOnce('')
.mockReturnValueOnce('a/path')
mockReadFileSync.mockReturnValue('file') mockReadFileSync.mockReturnValue('file')
expect(inputs.body).toBe('file') expect(inputs.body).toBe('file')
}) })
it('returns empty', () => { it('returns empty', () => {
mockGetInput
.mockReturnValueOnce('false')
.mockReturnValueOnce('')
.mockReturnValueOnce('')
expect(inputs.body).toBe('') expect(inputs.body).toBe('')
}) })
it('returns null when omitted', () => {
mockGetInput
.mockReturnValueOnce('true')
.mockReturnValueOnce('body')
expect(inputs.body).toBeUndefined()
})
}) })
describe('draft', () => { describe('draft', () => {
@@ -122,12 +138,23 @@ describe('Inputs', () => {
describe('name', () => { describe('name', () => {
it('returns input name', () => { it('returns input name', () => {
mockGetInput.mockReturnValue('name') mockGetInput
.mockReturnValueOnce('false')
.mockReturnValueOnce('name')
expect(inputs.name).toBe('name') expect(inputs.name).toBe('name')
}) })
it('returns null when omitted', () => {
mockGetInput
.mockReturnValueOnce('true')
.mockReturnValueOnce('name')
expect(inputs.body).toBeUndefined()
})
it('returns tag', () => { it('returns tag', () => {
mockGetInput.mockReturnValue('') mockGetInput
.mockReturnValueOnce('false')
.mockReturnValueOnce('')
context.ref = 'refs/tags/sha-tag' context.ref = 'refs/tags/sha-tag'
expect(inputs.name).toBe('sha-tag') expect(inputs.name).toBe('sha-tag')
}) })
@@ -184,4 +211,4 @@ describe('Inputs', () => {
mockGlob.mockImplementation(() => artifacts) mockGlob.mockImplementation(() => artifacts)
return new MockGlobber() return new MockGlobber()
} }
}) })

View File

@@ -2,42 +2,62 @@ name: 'Create Release'
description: 'Creates github releases' description: 'Creates github releases'
author: 'Nick Cipollo' author: 'Nick Cipollo'
inputs: inputs:
allowUpdates: allowUpdates:
description: 'An optional flag which indicates if we should update a release if it already exists. Defaults to false.' description: 'An optional flag which indicates if we should update a release if it already exists. Defaults to false.'
required: false
default: '' default: ''
artifact: artifact:
deprecationMessage: Use 'artifacts' instead. 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)' 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: '' default: ''
artifacts: 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)' 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: artifactContentType:
description: 'The content type of the artifact. Defaults to raw' description: 'The content type of the artifact. Defaults to raw'
required: false
default: '' default: ''
body: body:
description: 'An optional body for the release.' description: 'An optional body for the release.'
required: false
default: '' default: ''
bodyFile: bodyFile:
description: 'An optional body file for the release. This should be the path to the file' description: 'An optional body file for the release. This should be the path to the file'
default: '' required: false
default: ''
commit: commit:
description: "An optional commit reference. This will be used to create the tag if it does not exist." description: "An optional commit reference. This will be used to create the tag if it does not exist."
required: false
default: '' default: ''
draft: draft:
description: "Optionally marks this release as a draft release. Set to true to enable." description: "Optionally marks this release as a draft release. Set to true to enable."
required: false
default: '' default: ''
name: name:
description: 'An optional name for the release. If this is omitted the tag will be used.' description: 'An optional name for the release. If this is omitted the tag will be used.'
required: false
default: '' 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: prerelease:
description: "Optionally marks this release as prerelease. Set to true to enable." description: "Optionally marks this release as prerelease. Set to true to enable."
required: false
default: '' default: ''
replacesArtifacts: replacesArtifacts:
description: "Indicates if existing release artifacts should be replaced. Defaults to true." description: "Indicates if existing release artifacts should be replaced. Defaults to true."
default: 'true' required: false
default: 'true'
tag: tag:
description: 'An optional tag for the release. If this is omitted the git ref will be used (if it is a 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: '' default: ''
token: token:
description: 'The Github token.' description: 'The Github token.'

View File

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

View File

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