Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c75f0f2e4 | ||
|
|
b072aaafe1 | ||
|
|
f3ea29dca7 | ||
|
|
889eb279f8 | ||
|
|
5b3ed26ce2 |
@@ -22,13 +22,14 @@ This action will create a GitHub release and optionally upload an artifact to it
|
||||
| omitName | Indicates if the release name should be omitted. | false | false |
|
||||
| omitNameDuringUpdate | Indicates if the release name should be omitted during updates. The name will still be applied for newly created releases. This will preserve the existing name during updates. | false | false |
|
||||
| omitPrereleaseDuringUpdate | Indicates if the prerelease flag should be omitted during updates. The prerelease flag will still be applied for newly created releases. This will preserve the existing prerelease state during updates. | false | false |
|
||||
| owner | Optionally specify the owner of the repo where the release should be generated. Defaults to current repo's owner. | false | "current repo owner" |
|
||||
| owner | Optionally specify the owner of the repo where the release should be generated. Defaults to current repo's owner. | false | "current repo owner" |
|
||||
| prerelease | Optionally marks this release as prerelease. Set to true to enable. | false | "" |
|
||||
| removeArtifacts | Indicates if existing release artifacts should be removed. | false | false |
|
||||
| replacesArtifacts | Indicates if existing release artifacts should be replaced. | false | true |
|
||||
| repo | Optionally specify the repo where the release should be generated. | false | current repo |
|
||||
| tag | An optional tag for the release. If this is omitted the git ref will be used (if it is a tag). | false | "" |
|
||||
| token | The GitHub token. This will default to the GitHub app token. This is primarily useful if you want to use your personal token (for targeting other repos, etc). If you are using a personal access token it should have access to the `repo` scope. | false | github.token |
|
||||
| updateOnlyUnreleased | When allowUpdates is enabled, this will fail the action if the release it is updating is not a draft or a prerelease. | false | false |
|
||||
|
||||
## Action Outputs
|
||||
| Output name | Description |
|
||||
|
||||
@@ -37,6 +37,7 @@ const updateBody = 'updateBody'
|
||||
const updateDraft = false
|
||||
const updateName = 'updateName'
|
||||
const updatePrerelease = false
|
||||
const updateOnlyUnreleased = false
|
||||
const url = 'http://api.example.com'
|
||||
|
||||
describe("Action", () => {
|
||||
@@ -317,7 +318,9 @@ describe("Action", () => {
|
||||
expect(applyReleaseDataMock).toBeCalledWith({id: releaseId, upload_url: url})
|
||||
}
|
||||
|
||||
function createAction(allowUpdates: boolean, hasArtifact: boolean, removeArtifacts: boolean = false): Action {
|
||||
function createAction(allowUpdates: boolean,
|
||||
hasArtifact: boolean,
|
||||
removeArtifacts: boolean = false): Action {
|
||||
let inputArtifact: Artifact[]
|
||||
if (hasArtifact) {
|
||||
inputArtifact = artifacts
|
||||
@@ -379,7 +382,8 @@ describe("Action", () => {
|
||||
updatedDraft: updateDraft,
|
||||
updatedReleaseBody: updateBody,
|
||||
updatedReleaseName: updateName,
|
||||
updatedPrerelease: updatePrerelease
|
||||
updatedPrerelease: updatePrerelease,
|
||||
updateOnlyUnreleased: updateOnlyUnreleased
|
||||
}
|
||||
})
|
||||
const MockOutputs = jest.fn<Outputs, any>(() => {
|
||||
|
||||
@@ -430,6 +430,17 @@ describe('Inputs', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('updateOnlyUnreleased', () => {
|
||||
it('returns false', () => {
|
||||
expect(inputs.updateOnlyUnreleased).toBe(false)
|
||||
})
|
||||
|
||||
it('returns true', () => {
|
||||
mockGetInput.mockReturnValueOnce('true')
|
||||
expect(inputs.updateOnlyUnreleased).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
function createGlobber(): ArtifactGlobber {
|
||||
const MockGlobber = jest.fn<ArtifactGlobber, any>(() => {
|
||||
return {
|
||||
|
||||
@@ -57,7 +57,8 @@ describe.skip('Integration Test', () => {
|
||||
updatedDraft: false,
|
||||
updatedReleaseBody: "This release was generated by release-action's integration test",
|
||||
updatedReleaseName: "Releases Action Integration Test",
|
||||
updatedPrerelease: false
|
||||
updatedPrerelease: false,
|
||||
updateOnlyUnreleased: false
|
||||
}
|
||||
})
|
||||
return new MockInputs();
|
||||
|
||||
74
__tests__/ReleaseValidator.test.ts
Normal file
74
__tests__/ReleaseValidator.test.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import {ReleaseValidator} from "../src/ReleaseValidator";
|
||||
|
||||
describe("validateReleaseUpdate", () => {
|
||||
describe("updateOnlyUnreleased is disabled", () => {
|
||||
const validator = new ReleaseValidator(false)
|
||||
it('should not throw', () => {
|
||||
const releaseResponse = {
|
||||
draft: false,
|
||||
prerelease: false,
|
||||
name: "Name"
|
||||
}
|
||||
expect(() => {
|
||||
validator.validateReleaseUpdate(releaseResponse)
|
||||
}).not.toThrow()
|
||||
})
|
||||
})
|
||||
describe("updateOnlyUnreleased is enabled", () => {
|
||||
const validator = new ReleaseValidator(true)
|
||||
it('should throw if neither draft or prerelease are enabled', () => {
|
||||
const releaseResponse = {
|
||||
draft: false,
|
||||
prerelease: false,
|
||||
name: "Name"
|
||||
}
|
||||
expect(() => {
|
||||
validator.validateReleaseUpdate(releaseResponse)
|
||||
}).toThrow()
|
||||
})
|
||||
|
||||
it('should not throw if draft is enabled', () => {
|
||||
const releaseResponse = {
|
||||
draft: true,
|
||||
prerelease: false,
|
||||
name: "Name"
|
||||
}
|
||||
expect(() => {
|
||||
validator.validateReleaseUpdate(releaseResponse)
|
||||
}).not.toThrow()
|
||||
})
|
||||
|
||||
it('should not throw if prerelease is enabled', () => {
|
||||
const releaseResponse = {
|
||||
draft: false,
|
||||
prerelease: true,
|
||||
name: "Name"
|
||||
}
|
||||
expect(() => {
|
||||
validator.validateReleaseUpdate(releaseResponse)
|
||||
}).not.toThrow()
|
||||
})
|
||||
|
||||
it('should not throw if draft & prerelease is enabled', () => {
|
||||
const releaseResponse = {
|
||||
draft: true,
|
||||
prerelease: true,
|
||||
name: "Name"
|
||||
}
|
||||
expect(() => {
|
||||
validator.validateReleaseUpdate(releaseResponse)
|
||||
}).not.toThrow()
|
||||
})
|
||||
|
||||
it('should default error message release name to release', () => {
|
||||
const releaseResponse = {
|
||||
draft: false,
|
||||
prerelease: false,
|
||||
name: null
|
||||
}
|
||||
expect(() => {
|
||||
validator.validateReleaseUpdate(releaseResponse)
|
||||
}).toThrow(`Tried to update "release" which is neither a draft or prerelease. (updateOnlyUnreleased is on)`)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -94,7 +94,7 @@ inputs:
|
||||
repo:
|
||||
description: "Optionally specify the repo where the release should be generated. Defaults to current repo"
|
||||
required: false
|
||||
default: ''
|
||||
default: ''
|
||||
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
|
||||
@@ -103,6 +103,10 @@ inputs:
|
||||
description: 'The Github token.'
|
||||
required: false
|
||||
default: ${{ github.token }}
|
||||
updateOnlyUnreleased:
|
||||
description: "When allowUpdates is enabled, this will fail the action if the release it is updating is not a draft or a prerelease."
|
||||
required: false
|
||||
default: 'false'
|
||||
outputs:
|
||||
id:
|
||||
description: 'The identifier of the created release.'
|
||||
|
||||
492
dist/index.js
vendored
492
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/sourcemap-register.js
vendored
2
dist/sourcemap-register.js
vendored
File diff suppressed because one or more lines are too long
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Action = void 0;
|
||||
const GithubError_1 = require("./GithubError");
|
||||
const ReleaseValidator_1 = require("./ReleaseValidator");
|
||||
class Action {
|
||||
constructor(inputs, outputs, releases, uploader, artifactDestroyer) {
|
||||
this.inputs = inputs;
|
||||
@@ -18,6 +19,7 @@ class Action {
|
||||
this.releases = releases;
|
||||
this.uploader = uploader;
|
||||
this.artifactDestroyer = artifactDestroyer;
|
||||
this.releaseValidator = new ReleaseValidator_1.ReleaseValidator(inputs.updateOnlyUnreleased);
|
||||
}
|
||||
perform() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
@@ -45,6 +47,8 @@ class Action {
|
||||
catch (error) {
|
||||
return yield this.checkForMissingReleaseError(error);
|
||||
}
|
||||
// Fail if this isn't an unreleased release & updateOnlyUnreleased is enabled.
|
||||
this.releaseValidator.validateReleaseUpdate(getResponse.data);
|
||||
return yield this.updateRelease(getResponse.data.id);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -32,6 +32,7 @@ const Globber_1 = require("./Globber");
|
||||
const Artifact_1 = require("./Artifact");
|
||||
const untildify_1 = __importDefault(require("untildify"));
|
||||
const ArtifactPathValidator_1 = require("./ArtifactPathValidator");
|
||||
const PathNormalizer_1 = require("./PathNormalizer");
|
||||
class FileArtifactGlobber {
|
||||
constructor(globber = new Globber_1.FileGlobber()) {
|
||||
this.globber = globber;
|
||||
@@ -40,6 +41,7 @@ class FileArtifactGlobber {
|
||||
const split = /[,\n]/;
|
||||
return artifact.split(split)
|
||||
.map(path => path.trimStart())
|
||||
.map(path => PathNormalizer_1.PathNormalizer.normalizePath(path))
|
||||
.map(path => FileArtifactGlobber.expandPath(path))
|
||||
.map(pattern => this.globPattern(pattern, errorsFailBuild))
|
||||
.map((globResult) => FileArtifactGlobber.validatePattern(errorsFailBuild, globResult[1], globResult[0]))
|
||||
|
||||
@@ -180,6 +180,9 @@ class CoreInputs {
|
||||
return undefined;
|
||||
return this.name;
|
||||
}
|
||||
get updateOnlyUnreleased() {
|
||||
return core.getInput('updateOnlyUnreleased') == 'true';
|
||||
}
|
||||
static get omitNameDuringUpdate() {
|
||||
return core.getInput('omitNameDuringUpdate') == 'true';
|
||||
}
|
||||
|
||||
13
lib/PathNormalizer.js
Normal file
13
lib/PathNormalizer.js
Normal file
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PathNormalizer = void 0;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
class PathNormalizer {
|
||||
static normalizePath(pathString) {
|
||||
return pathString.split(path_1.default.sep).join("/");
|
||||
}
|
||||
}
|
||||
exports.PathNormalizer = PathNormalizer;
|
||||
18
lib/ReleaseValidator.js
Normal file
18
lib/ReleaseValidator.js
Normal file
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ReleaseValidator = void 0;
|
||||
class ReleaseValidator {
|
||||
constructor(updateOnlyUnreleased) {
|
||||
this.updateOnlyUnreleased = updateOnlyUnreleased;
|
||||
}
|
||||
validateReleaseUpdate(releaseResponse) {
|
||||
var _a;
|
||||
if (!this.updateOnlyUnreleased) {
|
||||
return;
|
||||
}
|
||||
if (!releaseResponse.draft && !releaseResponse.prerelease) {
|
||||
throw new Error(`Tried to update "${(_a = releaseResponse.name) !== null && _a !== void 0 ? _a : "release"}" which is neither a draft or prerelease. (updateOnlyUnreleased is on)`);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.ReleaseValidator = ReleaseValidator;
|
||||
@@ -10,13 +10,16 @@ import {ArtifactUploader} from "./ArtifactUploader";
|
||||
import {GithubError} from "./GithubError";
|
||||
import {Outputs} from "./Outputs";
|
||||
import {ArtifactDestroyer} from "./ArtifactDestroyer";
|
||||
import {ReleaseValidator} from "./ReleaseValidator";
|
||||
|
||||
export class Action {
|
||||
private inputs: Inputs
|
||||
private outputs: Outputs
|
||||
private releases: Releases
|
||||
private artifactDestroyer: ArtifactDestroyer
|
||||
private uploader: ArtifactUploader
|
||||
private artifactDestroyer: ArtifactDestroyer
|
||||
|
||||
private releaseValidator: ReleaseValidator
|
||||
|
||||
constructor(inputs: Inputs,
|
||||
outputs: Outputs,
|
||||
@@ -28,6 +31,7 @@ export class Action {
|
||||
this.releases = releases
|
||||
this.uploader = uploader
|
||||
this.artifactDestroyer = artifactDestroyer
|
||||
this.releaseValidator = new ReleaseValidator(inputs.updateOnlyUnreleased)
|
||||
}
|
||||
|
||||
async perform() {
|
||||
@@ -56,6 +60,9 @@ export class Action {
|
||||
} catch (error: any) {
|
||||
return await this.checkForMissingReleaseError(error)
|
||||
}
|
||||
|
||||
// Fail if this isn't an unreleased release & updateOnlyUnreleased is enabled.
|
||||
this.releaseValidator.validateReleaseUpdate(getResponse.data)
|
||||
|
||||
return await this.updateRelease(getResponse.data.id)
|
||||
} else {
|
||||
|
||||
@@ -3,6 +3,7 @@ import {Globber, FileGlobber} from "./Globber";
|
||||
import {Artifact} from "./Artifact";
|
||||
import untildify from "untildify";
|
||||
import {ArtifactPathValidator} from "./ArtifactPathValidator";
|
||||
import {PathNormalizer} from "./PathNormalizer";
|
||||
|
||||
export interface ArtifactGlobber {
|
||||
globArtifactString(artifact: string, contentType: string, errorsFailBuild: boolean): Artifact[]
|
||||
@@ -19,6 +20,7 @@ export class FileArtifactGlobber implements ArtifactGlobber {
|
||||
const split = /[,\n]/
|
||||
return artifact.split(split)
|
||||
.map(path => path.trimStart())
|
||||
.map(path => PathNormalizer.normalizePath(path))
|
||||
.map(path => FileArtifactGlobber.expandPath(path))
|
||||
.map(pattern => this.globPattern(pattern, errorsFailBuild))
|
||||
.map((globResult) => FileArtifactGlobber.validatePattern(errorsFailBuild, globResult[1], globResult[0]))
|
||||
|
||||
@@ -25,6 +25,7 @@ export interface Inputs {
|
||||
readonly updatedReleaseBody?: string
|
||||
readonly updatedReleaseName?: string
|
||||
readonly updatedPrerelease?: boolean
|
||||
readonly updateOnlyUnreleased: boolean
|
||||
}
|
||||
|
||||
export class CoreInputs implements Inputs {
|
||||
@@ -209,6 +210,10 @@ export class CoreInputs implements Inputs {
|
||||
if (CoreInputs.omitName || CoreInputs.omitNameDuringUpdate) return undefined
|
||||
return this.name
|
||||
}
|
||||
|
||||
get updateOnlyUnreleased(): boolean {
|
||||
return core.getInput('updateOnlyUnreleased') == 'true'
|
||||
}
|
||||
|
||||
private static get omitNameDuringUpdate(): boolean {
|
||||
return core.getInput('omitNameDuringUpdate') == 'true'
|
||||
|
||||
7
src/PathNormalizer.ts
Normal file
7
src/PathNormalizer.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import path from "path";
|
||||
|
||||
export class PathNormalizer {
|
||||
static normalizePath(pathString: string): string {
|
||||
return pathString.split(path.sep).join("/")
|
||||
}
|
||||
}
|
||||
20
src/ReleaseValidator.ts
Normal file
20
src/ReleaseValidator.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
export class ReleaseValidator {
|
||||
constructor(private updateOnlyUnreleased: boolean) {
|
||||
}
|
||||
|
||||
validateReleaseUpdate(releaseResponse: ReleaseStageArguments) {
|
||||
if (!this.updateOnlyUnreleased) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!releaseResponse.draft && !releaseResponse.prerelease) {
|
||||
throw new Error(`Tried to update "${releaseResponse.name ?? "release"}" which is neither a draft or prerelease. (updateOnlyUnreleased is on)`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type ReleaseStageArguments = {
|
||||
draft: boolean
|
||||
name: string | null
|
||||
prerelease: boolean
|
||||
}
|
||||
Reference in New Issue
Block a user