Add biome and initial format rules
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
import * as core from '@actions/core';
|
||||
import {Inputs} from "./Inputs";
|
||||
import * as core from "@actions/core"
|
||||
import { Inputs } from "./Inputs"
|
||||
import {
|
||||
CreateOrUpdateReleaseResponse,
|
||||
CreateReleaseResponse,
|
||||
ReleaseByTagResponse,
|
||||
Releases,
|
||||
UpdateReleaseResponse
|
||||
} from "./Releases";
|
||||
import {ArtifactUploader} from "./ArtifactUploader";
|
||||
import {GithubError} from "./GithubError";
|
||||
import {Outputs} from "./Outputs";
|
||||
import {ArtifactDestroyer} from "./ArtifactDestroyer";
|
||||
import {ReleaseValidator} from "./ReleaseValidator";
|
||||
import {ActionSkipper} from "./ActionSkipper";
|
||||
UpdateReleaseResponse,
|
||||
} from "./Releases"
|
||||
import { ArtifactUploader } from "./ArtifactUploader"
|
||||
import { GithubError } from "./GithubError"
|
||||
import { Outputs } from "./Outputs"
|
||||
import { ArtifactDestroyer } from "./ArtifactDestroyer"
|
||||
import { ReleaseValidator } from "./ReleaseValidator"
|
||||
import { ActionSkipper } from "./ActionSkipper"
|
||||
|
||||
export class Action {
|
||||
private inputs: Inputs
|
||||
@@ -21,15 +21,17 @@ export class Action {
|
||||
private uploader: ArtifactUploader
|
||||
private artifactDestroyer: ArtifactDestroyer
|
||||
private skipper: ActionSkipper
|
||||
|
||||
|
||||
private releaseValidator: ReleaseValidator
|
||||
|
||||
constructor(inputs: Inputs,
|
||||
outputs: Outputs,
|
||||
releases: Releases,
|
||||
uploader: ArtifactUploader,
|
||||
artifactDestroyer: ArtifactDestroyer,
|
||||
skipper: ActionSkipper) {
|
||||
constructor(
|
||||
inputs: Inputs,
|
||||
outputs: Outputs,
|
||||
releases: Releases,
|
||||
uploader: ArtifactUploader,
|
||||
artifactDestroyer: ArtifactDestroyer,
|
||||
skipper: ActionSkipper
|
||||
) {
|
||||
this.inputs = inputs
|
||||
this.outputs = outputs
|
||||
this.releases = releases
|
||||
@@ -44,16 +46,16 @@ export class Action {
|
||||
core.notice("Skipping action, release already exists and skipIfReleaseExists is enabled.")
|
||||
return
|
||||
}
|
||||
|
||||
const releaseResponse = await this.createOrUpdateRelease();
|
||||
|
||||
const releaseResponse = await this.createOrUpdateRelease()
|
||||
const releaseData = releaseResponse.data
|
||||
const releaseId = releaseData.id
|
||||
const uploadUrl = releaseData.upload_url
|
||||
|
||||
|
||||
if (this.inputs.removeArtifacts) {
|
||||
await this.artifactDestroyer.destroyArtifacts(releaseId)
|
||||
}
|
||||
|
||||
|
||||
const artifacts = this.inputs.artifacts
|
||||
if (artifacts.length > 0) {
|
||||
await this.uploader.uploadArtifacts(artifacts, releaseId, uploadUrl)
|
||||
@@ -70,7 +72,7 @@ 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)
|
||||
|
||||
@@ -120,11 +122,11 @@ export class Action {
|
||||
const tag = this.inputs.tag
|
||||
const response = await this.releases.listReleases()
|
||||
const releases = response.data
|
||||
if(!releases) {
|
||||
if (!releases) {
|
||||
throw new Error(`No releases found. Response: ${JSON.stringify(response)}`)
|
||||
}
|
||||
|
||||
const draftRelease = releases.find(release => release.draft && release.tag_name == tag)
|
||||
const draftRelease = releases.find((release) => release.draft && release.tag_name == tag)
|
||||
|
||||
return draftRelease?.id
|
||||
}
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
import {Releases} from "./Releases";
|
||||
import { Releases } from "./Releases"
|
||||
|
||||
export interface ActionSkipper {
|
||||
shouldSkip(): Promise<boolean>
|
||||
}
|
||||
|
||||
export class ReleaseActionSkipper {
|
||||
constructor(private skipIfReleaseExists: boolean,
|
||||
private releases: Releases,
|
||||
private tag: string) {
|
||||
}
|
||||
constructor(
|
||||
private skipIfReleaseExists: boolean,
|
||||
private releases: Releases,
|
||||
private tag: string
|
||||
) {}
|
||||
|
||||
async shouldSkip(): Promise<boolean> {
|
||||
if (!this.skipIfReleaseExists) {
|
||||
// Bail if skip flag isn't set.
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -21,7 +22,7 @@ export class ReleaseActionSkipper {
|
||||
return getResponse.data != null
|
||||
} catch (error: any) {
|
||||
// There is either no release or something else went wrong. Either way, run the action.
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { basename } from "path";
|
||||
import {createReadStream, readFileSync, ReadStream, statSync} from "fs";
|
||||
import { basename } from "path"
|
||||
import { createReadStream, readFileSync, ReadStream, statSync } from "fs"
|
||||
|
||||
export class Artifact {
|
||||
readonly contentType: string
|
||||
@@ -9,7 +9,7 @@ export class Artifact {
|
||||
constructor(path: string, contentType: string = "raw") {
|
||||
this.path = path
|
||||
this.name = basename(path)
|
||||
this.contentType = contentType;
|
||||
this.contentType = contentType
|
||||
}
|
||||
|
||||
get contentLength(): number {
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import {Releases} from "./Releases";
|
||||
import * as core from "@actions/core";
|
||||
import { Releases } from "./Releases"
|
||||
import * as core from "@actions/core"
|
||||
|
||||
export interface ArtifactDestroyer {
|
||||
destroyArtifacts(releaseId: number): Promise<void>
|
||||
}
|
||||
|
||||
export class GithubArtifactDestroyer implements ArtifactDestroyer {
|
||||
constructor(private releases: Releases) {
|
||||
}
|
||||
constructor(private releases: Releases) {}
|
||||
|
||||
async destroyArtifacts(releaseId: number): Promise<void> {
|
||||
const releaseAssets = await this.releases.listArtifactsForRelease(releaseId)
|
||||
@@ -17,4 +16,4 @@ export class GithubArtifactDestroyer implements ArtifactDestroyer {
|
||||
await this.releases.deleteArtifact(asset.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import * as core from '@actions/core';
|
||||
import {Globber, FileGlobber} from "./Globber";
|
||||
import {Artifact} from "./Artifact";
|
||||
import untildify from "untildify";
|
||||
import {ArtifactPathValidator} from "./ArtifactPathValidator";
|
||||
import {PathNormalizer} from "./PathNormalizer";
|
||||
import * as core from "@actions/core"
|
||||
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[]
|
||||
@@ -18,14 +18,15 @@ export class FileArtifactGlobber implements ArtifactGlobber {
|
||||
|
||||
globArtifactString(artifact: string, contentType: string, errorsFailBuild: boolean): Artifact[] {
|
||||
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))
|
||||
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]))
|
||||
.reduce((accumulated, current) => accumulated.concat(current))
|
||||
.map(path => new Artifact(path, contentType))
|
||||
.map((path) => new Artifact(path, contentType))
|
||||
}
|
||||
|
||||
private globPattern(pattern: string, errorsFailBuild: boolean): [string, string[]] {
|
||||
@@ -56,4 +57,4 @@ export class FileArtifactGlobber implements ArtifactGlobber {
|
||||
private static expandPath(path: string): string {
|
||||
return untildify(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
import * as core from "@actions/core";
|
||||
import {statSync} from "fs";
|
||||
import * as core from "@actions/core"
|
||||
import { statSync } from "fs"
|
||||
|
||||
export class ArtifactPathValidator {
|
||||
private readonly errorsFailBuild: boolean;
|
||||
private paths: string[];
|
||||
private readonly errorsFailBuild: boolean
|
||||
private paths: string[]
|
||||
private readonly pattern: string
|
||||
|
||||
|
||||
constructor(errorsFailBuild: boolean, paths: string[], pattern: string) {
|
||||
this.paths = paths;
|
||||
this.paths = paths
|
||||
this.pattern = pattern
|
||||
this.errorsFailBuild = errorsFailBuild;
|
||||
this.errorsFailBuild = errorsFailBuild
|
||||
}
|
||||
|
||||
|
||||
validate(): string[] {
|
||||
this.verifyPathsNotEmpty()
|
||||
return this.paths.filter((path) => this.verifyNotDirectory(path))
|
||||
}
|
||||
|
||||
|
||||
private verifyPathsNotEmpty() {
|
||||
if (this.paths.length == 0) {
|
||||
const message = `Artifact pattern:${this.pattern} did not match any files`
|
||||
this.reportError(message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private verifyNotDirectory(path: string): boolean {
|
||||
const isDir = statSync(path).isDirectory()
|
||||
if (isDir) {
|
||||
@@ -32,7 +32,7 @@ export class ArtifactPathValidator {
|
||||
}
|
||||
return !isDir
|
||||
}
|
||||
|
||||
|
||||
private reportError(message: string) {
|
||||
if (this.errorsFailBuild) {
|
||||
throw Error(message)
|
||||
@@ -40,4 +40,4 @@ export class ArtifactPathValidator {
|
||||
core.warning(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as core from '@actions/core';
|
||||
import {Artifact} from "./Artifact";
|
||||
import {Releases} from "./Releases";
|
||||
import * as core from "@actions/core"
|
||||
import { Artifact } from "./Artifact"
|
||||
import { Releases } from "./Releases"
|
||||
|
||||
export interface ArtifactUploader {
|
||||
uploadArtifacts(artifacts: Artifact[], releaseId: number, uploadUrl: string): Promise<void>
|
||||
@@ -10,13 +10,10 @@ export class GithubArtifactUploader implements ArtifactUploader {
|
||||
constructor(
|
||||
private releases: Releases,
|
||||
private replacesExistingArtifacts: boolean = true,
|
||||
private throwsUploadErrors: boolean = false,
|
||||
) {
|
||||
}
|
||||
private throwsUploadErrors: boolean = false
|
||||
) {}
|
||||
|
||||
async uploadArtifacts(artifacts: Artifact[],
|
||||
releaseId: number,
|
||||
uploadUrl: string): Promise<void> {
|
||||
async uploadArtifacts(artifacts: Artifact[], releaseId: number, uploadUrl: string): Promise<void> {
|
||||
if (this.replacesExistingArtifacts) {
|
||||
await this.deleteUpdatedArtifacts(artifacts, releaseId)
|
||||
}
|
||||
@@ -25,18 +22,17 @@ export class GithubArtifactUploader implements ArtifactUploader {
|
||||
}
|
||||
}
|
||||
|
||||
private async uploadArtifact(artifact: Artifact,
|
||||
releaseId: number,
|
||||
uploadUrl: string,
|
||||
retry = 3) {
|
||||
private async uploadArtifact(artifact: Artifact, releaseId: number, uploadUrl: string, retry = 3) {
|
||||
try {
|
||||
core.debug(`Uploading artifact ${artifact.name}...`)
|
||||
await this.releases.uploadArtifact(uploadUrl,
|
||||
await this.releases.uploadArtifact(
|
||||
uploadUrl,
|
||||
artifact.contentLength,
|
||||
artifact.contentType,
|
||||
artifact.readFile(),
|
||||
artifact.name,
|
||||
releaseId)
|
||||
releaseId
|
||||
)
|
||||
} catch (error: any) {
|
||||
if (error.status >= 500 && retry > 0) {
|
||||
core.warning(`Failed to upload artifact ${artifact.name}. ${error.message}. Retrying...`)
|
||||
@@ -54,9 +50,9 @@ export class GithubArtifactUploader implements ArtifactUploader {
|
||||
private async deleteUpdatedArtifacts(artifacts: Artifact[], releaseId: number): Promise<void> {
|
||||
const releaseAssets = await this.releases.listArtifactsForRelease(releaseId)
|
||||
const assetByName: Record<string, { id: number; name: string }> = {}
|
||||
releaseAssets.forEach(asset => {
|
||||
releaseAssets.forEach((asset) => {
|
||||
assetByName[asset.name] = asset
|
||||
});
|
||||
})
|
||||
for (const artifact of artifacts) {
|
||||
const asset = assetByName[artifact.name]
|
||||
if (asset) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {GithubErrorDetail} from "./GithubErrorDetail"
|
||||
import { GithubErrorDetail } from "./GithubErrorDetail"
|
||||
|
||||
export class GithubError {
|
||||
private error: any
|
||||
@@ -40,7 +40,7 @@ export class GithubError {
|
||||
private errorBulletedList(errors: GithubErrorDetail[]): string {
|
||||
return errors.map((err) => `- ${err}`).join("\n")
|
||||
}
|
||||
|
||||
|
||||
private remediation(): String {
|
||||
if (this.status == 404) {
|
||||
return "\nMake sure your github token has access to the repo and has permission to author releases"
|
||||
@@ -48,4 +48,3 @@ export class GithubError {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export class GithubErrorDetail {
|
||||
private error: any;
|
||||
private error: any
|
||||
|
||||
constructor(error: any) {
|
||||
this.error = error
|
||||
@@ -12,13 +12,13 @@ export class GithubErrorDetail {
|
||||
toString(): string {
|
||||
const code = this.error.code
|
||||
switch (code) {
|
||||
case 'missing':
|
||||
case "missing":
|
||||
return this.missingResourceMessage()
|
||||
case 'missing_field':
|
||||
case "missing_field":
|
||||
return this.missingFieldMessage()
|
||||
case 'invalid':
|
||||
case "invalid":
|
||||
return this.invalidFieldMessage()
|
||||
case 'already_exists':
|
||||
case "already_exists":
|
||||
return this.resourceAlreadyExists()
|
||||
default:
|
||||
return this.customErrorMessage()
|
||||
@@ -26,7 +26,7 @@ export class GithubErrorDetail {
|
||||
}
|
||||
|
||||
private customErrorMessage(): string {
|
||||
const message = this.error.message;
|
||||
const message = this.error.message
|
||||
const documentation = this.error.documentation_url
|
||||
|
||||
let documentationMessage: string
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {globSync} from "glob";
|
||||
|
||||
import { globSync } from "glob"
|
||||
|
||||
export interface Globber {
|
||||
glob(pattern: string): string[]
|
||||
@@ -9,4 +8,4 @@ export class FileGlobber implements Globber {
|
||||
glob(pattern: string): string[] {
|
||||
return globSync(pattern, { mark: true })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
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 * as core from "@actions/core"
|
||||
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
|
||||
@@ -40,53 +40,52 @@ export class CoreInputs implements Inputs {
|
||||
}
|
||||
|
||||
get allowUpdates(): boolean {
|
||||
const allow = core.getInput('allowUpdates')
|
||||
return allow == 'true'
|
||||
const allow = core.getInput("allowUpdates")
|
||||
return allow == "true"
|
||||
}
|
||||
|
||||
get artifacts(): Artifact[] {
|
||||
let artifacts = core.getInput('artifacts')
|
||||
let artifacts = core.getInput("artifacts")
|
||||
if (!artifacts) {
|
||||
artifacts = core.getInput('artifact')
|
||||
artifacts = core.getInput("artifact")
|
||||
}
|
||||
if (artifacts) {
|
||||
let contentType = core.getInput('artifactContentType')
|
||||
let contentType = core.getInput("artifactContentType")
|
||||
if (!contentType) {
|
||||
contentType = 'raw'
|
||||
contentType = "raw"
|
||||
}
|
||||
return this.artifactGlobber
|
||||
.globArtifactString(artifacts, contentType, this.artifactErrorsFailBuild)
|
||||
return this.artifactGlobber.globArtifactString(artifacts, contentType, this.artifactErrorsFailBuild)
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
get artifactErrorsFailBuild(): boolean {
|
||||
const allow = core.getInput('artifactErrorsFailBuild')
|
||||
return allow == 'true'
|
||||
const allow = core.getInput("artifactErrorsFailBuild")
|
||||
return allow == "true"
|
||||
}
|
||||
|
||||
private get body(): string | undefined {
|
||||
const body = core.getInput('body')
|
||||
const body = core.getInput("body")
|
||||
if (body) {
|
||||
return body
|
||||
}
|
||||
|
||||
const bodyFile = core.getInput('bodyFile')
|
||||
const bodyFile = core.getInput("bodyFile")
|
||||
if (bodyFile) {
|
||||
return this.stringFromFile(bodyFile)
|
||||
}
|
||||
|
||||
return ''
|
||||
return ""
|
||||
}
|
||||
|
||||
get createdDraft(): boolean {
|
||||
const draft = core.getInput('draft')
|
||||
return draft == 'true'
|
||||
const draft = core.getInput("draft")
|
||||
return draft == "true"
|
||||
}
|
||||
|
||||
get createdPrerelease(): boolean {
|
||||
const preRelease = core.getInput('prerelease')
|
||||
return preRelease == 'true'
|
||||
const preRelease = core.getInput("prerelease")
|
||||
return preRelease == "true"
|
||||
}
|
||||
|
||||
get createdReleaseBody(): string | undefined {
|
||||
@@ -95,7 +94,7 @@ export class CoreInputs implements Inputs {
|
||||
}
|
||||
|
||||
private static get omitBody(): boolean {
|
||||
return core.getInput('omitBody') == 'true'
|
||||
return core.getInput("omitBody") == "true"
|
||||
}
|
||||
|
||||
get createdReleaseName(): string | undefined {
|
||||
@@ -104,11 +103,11 @@ export class CoreInputs implements Inputs {
|
||||
}
|
||||
|
||||
private static get omitName(): boolean {
|
||||
return core.getInput('omitName') == 'true'
|
||||
return core.getInput("omitName") == "true"
|
||||
}
|
||||
|
||||
get commit(): string | undefined {
|
||||
const commit = core.getInput('commit')
|
||||
const commit = core.getInput("commit")
|
||||
if (commit) {
|
||||
return commit
|
||||
}
|
||||
@@ -116,7 +115,7 @@ export class CoreInputs implements Inputs {
|
||||
}
|
||||
|
||||
get discussionCategory(): string | undefined {
|
||||
const category = core.getInput('discussionCategory')
|
||||
const category = core.getInput("discussionCategory")
|
||||
if (category) {
|
||||
return category
|
||||
}
|
||||
@@ -124,7 +123,7 @@ export class CoreInputs implements Inputs {
|
||||
}
|
||||
|
||||
private get name(): string | undefined {
|
||||
const name = core.getInput('name')
|
||||
const name = core.getInput("name")
|
||||
if (name) {
|
||||
return name
|
||||
}
|
||||
@@ -133,21 +132,21 @@ export class CoreInputs implements Inputs {
|
||||
}
|
||||
|
||||
get generateReleaseNotes(): boolean {
|
||||
const generate = core.getInput('generateReleaseNotes')
|
||||
return generate == 'true'
|
||||
const generate = core.getInput("generateReleaseNotes")
|
||||
return generate == "true"
|
||||
}
|
||||
|
||||
get makeLatest(): "legacy" | "true" | "false" | undefined {
|
||||
let latest = core.getInput('makeLatest')
|
||||
let latest = core.getInput("makeLatest")
|
||||
if (latest == "true" || latest == "false" || latest == "legacy") {
|
||||
return latest;
|
||||
return latest
|
||||
}
|
||||
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
get owner(): string {
|
||||
let owner = core.getInput('owner')
|
||||
let owner = core.getInput("owner")
|
||||
if (owner) {
|
||||
return owner
|
||||
}
|
||||
@@ -155,17 +154,17 @@ export class CoreInputs implements Inputs {
|
||||
}
|
||||
|
||||
get removeArtifacts(): boolean {
|
||||
const removes = core.getInput('removeArtifacts')
|
||||
return removes == 'true'
|
||||
const removes = core.getInput("removeArtifacts")
|
||||
return removes == "true"
|
||||
}
|
||||
|
||||
get replacesArtifacts(): boolean {
|
||||
const replaces = core.getInput('replacesArtifacts')
|
||||
return replaces == 'true'
|
||||
const replaces = core.getInput("replacesArtifacts")
|
||||
return replaces == "true"
|
||||
}
|
||||
|
||||
get repo(): string {
|
||||
let repo = core.getInput('repo')
|
||||
let repo = core.getInput("repo")
|
||||
if (repo) {
|
||||
return repo
|
||||
}
|
||||
@@ -177,9 +176,9 @@ export class CoreInputs implements Inputs {
|
||||
}
|
||||
|
||||
get tag(): string {
|
||||
const tag = core.getInput('tag')
|
||||
const tag = core.getInput("tag")
|
||||
if (tag) {
|
||||
return tag;
|
||||
return tag
|
||||
}
|
||||
|
||||
const ref = this.context.ref
|
||||
@@ -192,7 +191,7 @@ export class CoreInputs implements Inputs {
|
||||
}
|
||||
|
||||
get token(): string {
|
||||
return core.getInput('token', {required: true})
|
||||
return core.getInput("token", { required: true })
|
||||
}
|
||||
|
||||
get updatedDraft(): boolean | undefined {
|
||||
@@ -201,7 +200,7 @@ export class CoreInputs implements Inputs {
|
||||
}
|
||||
|
||||
private static get omitDraftDuringUpdate(): boolean {
|
||||
return core.getInput('omitDraftDuringUpdate') == 'true'
|
||||
return core.getInput("omitDraftDuringUpdate") == "true"
|
||||
}
|
||||
|
||||
get updatedPrerelease(): boolean | undefined {
|
||||
@@ -210,7 +209,7 @@ export class CoreInputs implements Inputs {
|
||||
}
|
||||
|
||||
private static get omitPrereleaseDuringUpdate(): boolean {
|
||||
return core.getInput('omitPrereleaseDuringUpdate') == 'true'
|
||||
return core.getInput("omitPrereleaseDuringUpdate") == "true"
|
||||
}
|
||||
|
||||
get updatedReleaseBody(): string | undefined {
|
||||
@@ -219,7 +218,7 @@ export class CoreInputs implements Inputs {
|
||||
}
|
||||
|
||||
private static get omitBodyDuringUpdate(): boolean {
|
||||
return core.getInput('omitBodyDuringUpdate') == 'true'
|
||||
return core.getInput("omitBodyDuringUpdate") == "true"
|
||||
}
|
||||
|
||||
get updatedReleaseName(): string | undefined {
|
||||
@@ -228,14 +227,14 @@ export class CoreInputs implements Inputs {
|
||||
}
|
||||
|
||||
get updateOnlyUnreleased(): boolean {
|
||||
return core.getInput('updateOnlyUnreleased') == 'true'
|
||||
return core.getInput("updateOnlyUnreleased") == "true"
|
||||
}
|
||||
|
||||
private static get omitNameDuringUpdate(): boolean {
|
||||
return core.getInput('omitNameDuringUpdate') == 'true'
|
||||
return core.getInput("omitNameDuringUpdate") == "true"
|
||||
}
|
||||
|
||||
stringFromFile(path: string): string {
|
||||
return readFileSync(path, 'utf-8')
|
||||
return readFileSync(path, "utf-8")
|
||||
}
|
||||
}
|
||||
|
||||
30
src/Main.ts
30
src/Main.ts
@@ -1,14 +1,14 @@
|
||||
import * as github from '@actions/github';
|
||||
import * as core from '@actions/core';
|
||||
import {CoreInputs} from './Inputs';
|
||||
import {GithubReleases} from './Releases';
|
||||
import {Action} from './Action';
|
||||
import {GithubArtifactUploader} from './ArtifactUploader';
|
||||
import {FileArtifactGlobber} from './ArtifactGlobber';
|
||||
import {GithubError} from './GithubError';
|
||||
import {CoreOutputs} from "./Outputs";
|
||||
import {GithubArtifactDestroyer} from "./ArtifactDestroyer";
|
||||
import {ActionSkipper, ReleaseActionSkipper} from "./ActionSkipper";
|
||||
import * as github from "@actions/github"
|
||||
import * as core from "@actions/core"
|
||||
import { CoreInputs } from "./Inputs"
|
||||
import { GithubReleases } from "./Releases"
|
||||
import { Action } from "./Action"
|
||||
import { GithubArtifactUploader } from "./ArtifactUploader"
|
||||
import { FileArtifactGlobber } from "./ArtifactGlobber"
|
||||
import { GithubError } from "./GithubError"
|
||||
import { CoreOutputs } from "./Outputs"
|
||||
import { GithubArtifactDestroyer } from "./ArtifactDestroyer"
|
||||
import { ActionSkipper, ReleaseActionSkipper } from "./ActionSkipper"
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
@@ -16,12 +16,12 @@ async function run() {
|
||||
await action.perform()
|
||||
} catch (error) {
|
||||
const githubError = new GithubError(error)
|
||||
core.setFailed(githubError.toString());
|
||||
core.setFailed(githubError.toString())
|
||||
}
|
||||
}
|
||||
|
||||
function createAction(): Action {
|
||||
const token = core.getInput('token')
|
||||
const token = core.getInput("token")
|
||||
const context = github.context
|
||||
const git = github.getOctokit(token)
|
||||
const globber = new FileArtifactGlobber()
|
||||
@@ -32,8 +32,8 @@ function createAction(): Action {
|
||||
const skipper = new ReleaseActionSkipper(inputs.skipIfReleaseExists, releases, inputs.tag)
|
||||
const uploader = new GithubArtifactUploader(releases, inputs.replacesArtifacts, inputs.artifactErrorsFailBuild)
|
||||
const artifactDestroyer = new GithubArtifactDestroyer(releases)
|
||||
|
||||
|
||||
return new Action(inputs, outputs, releases, uploader, artifactDestroyer, skipper)
|
||||
}
|
||||
|
||||
run();
|
||||
run()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as core from '@actions/core';
|
||||
import {ReleaseData} from "./Releases";
|
||||
import * as core from "@actions/core"
|
||||
import { ReleaseData } from "./Releases"
|
||||
|
||||
export interface Outputs {
|
||||
applyReleaseData(releaseData: ReleaseData): void
|
||||
@@ -7,8 +7,8 @@ export interface Outputs {
|
||||
|
||||
export class CoreOutputs implements Outputs {
|
||||
applyReleaseData(releaseData: ReleaseData) {
|
||||
core.setOutput('id', releaseData.id)
|
||||
core.setOutput('html_url', releaseData.html_url)
|
||||
core.setOutput('upload_url', releaseData.upload_url)
|
||||
core.setOutput("id", releaseData.id)
|
||||
core.setOutput("html_url", releaseData.html_url)
|
||||
core.setOutput("upload_url", releaseData.upload_url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import path from "path";
|
||||
import path from "path"
|
||||
|
||||
export class PathNormalizer {
|
||||
static normalizePath(pathString: string): string {
|
||||
return pathString.split(path.sep).join("/")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
export class ReleaseValidator {
|
||||
constructor(private updateOnlyUnreleased: boolean) {
|
||||
}
|
||||
constructor(private updateOnlyUnreleased: boolean) {}
|
||||
|
||||
validateReleaseUpdate(releaseResponse: ReleaseStageArguments) {
|
||||
if (!this.updateOnlyUnreleased) {
|
||||
@@ -8,7 +7,9 @@ export class ReleaseValidator {
|
||||
}
|
||||
|
||||
if (!releaseResponse.draft && !releaseResponse.prerelease) {
|
||||
throw new Error(`Tried to update "${releaseResponse.name ?? "release"}" which is neither a draft or prerelease. (updateOnlyUnreleased is on)`)
|
||||
throw new Error(
|
||||
`Tried to update "${releaseResponse.name ?? "release"}" which is neither a draft or prerelease. (updateOnlyUnreleased is on)`
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,4 +18,4 @@ export type ReleaseStageArguments = {
|
||||
draft: boolean
|
||||
name: string | null
|
||||
prerelease: boolean
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {GitHub} from '@actions/github/lib/utils'
|
||||
import {OctokitResponse} from "@octokit/types";
|
||||
import {RestEndpointMethodTypes} from "@octokit/plugin-rest-endpoint-methods";
|
||||
import {Inputs} from "./Inputs";
|
||||
import { GitHub } from "@actions/github/lib/utils"
|
||||
import { OctokitResponse } from "@octokit/types"
|
||||
import { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods"
|
||||
import { Inputs } from "./Inputs"
|
||||
|
||||
export type CreateReleaseResponse = RestEndpointMethodTypes["repos"]["createRelease"]["response"]
|
||||
export type ReleaseByTagResponse = RestEndpointMethodTypes["repos"]["getReleaseByTag"]["response"]
|
||||
@@ -25,7 +25,7 @@ export interface Releases {
|
||||
discussionCategory?: string,
|
||||
draft?: boolean,
|
||||
generateReleaseNotes?: boolean,
|
||||
makeLatest?: "legacy" | "true" | "false" | undefined,
|
||||
makeLatest?: "legacy" | "true" | "false" | undefined,
|
||||
name?: string,
|
||||
prerelease?: boolean
|
||||
): Promise<CreateReleaseResponse>
|
||||
@@ -45,7 +45,7 @@ export interface Releases {
|
||||
commitHash?: string,
|
||||
discussionCategory?: string,
|
||||
draft?: boolean,
|
||||
makeLatest?: "legacy" | "true" | "false" | undefined,
|
||||
makeLatest?: "legacy" | "true" | "false" | undefined,
|
||||
name?: string,
|
||||
prerelease?: boolean
|
||||
): Promise<UpdateReleaseResponse>
|
||||
@@ -56,7 +56,7 @@ export interface Releases {
|
||||
contentType: string,
|
||||
file: string | object,
|
||||
name: string,
|
||||
releaseId: number,
|
||||
releaseId: number
|
||||
): Promise<UploadArtifactResponse>
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ export class GithubReleases implements Releases {
|
||||
discussionCategory?: string,
|
||||
draft?: boolean,
|
||||
generateReleaseNotes?: boolean,
|
||||
makeLatest?: "legacy" | "true" | "false" | undefined,
|
||||
makeLatest?: "legacy" | "true" | "false" | undefined,
|
||||
name?: string,
|
||||
prerelease?: boolean
|
||||
): Promise<CreateReleaseResponse> {
|
||||
@@ -92,17 +92,15 @@ export class GithubReleases implements Releases {
|
||||
prerelease: prerelease,
|
||||
repo: this.inputs.repo,
|
||||
target_commitish: commitHash,
|
||||
tag_name: tag
|
||||
tag_name: tag,
|
||||
})
|
||||
}
|
||||
|
||||
async deleteArtifact(
|
||||
assetId: number
|
||||
): Promise<OctokitResponse<any>> {
|
||||
async deleteArtifact(assetId: number): Promise<OctokitResponse<any>> {
|
||||
return this.git.rest.repos.deleteReleaseAsset({
|
||||
asset_id: assetId,
|
||||
owner: this.inputs.owner,
|
||||
repo: this.inputs.repo
|
||||
repo: this.inputs.repo,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -110,24 +108,22 @@ export class GithubReleases implements Releases {
|
||||
return this.git.rest.repos.getReleaseByTag({
|
||||
owner: this.inputs.owner,
|
||||
repo: this.inputs.repo,
|
||||
tag: tag
|
||||
tag: tag,
|
||||
})
|
||||
}
|
||||
|
||||
async listArtifactsForRelease(
|
||||
releaseId: number
|
||||
): Promise<ListReleaseAssetsResponseData> {
|
||||
async listArtifactsForRelease(releaseId: number): Promise<ListReleaseAssetsResponseData> {
|
||||
return this.git.paginate(this.git.rest.repos.listReleaseAssets, {
|
||||
owner: this.inputs.owner,
|
||||
release_id: releaseId,
|
||||
repo: this.inputs.repo
|
||||
repo: this.inputs.repo,
|
||||
})
|
||||
}
|
||||
|
||||
async listReleases(): Promise<ListReleasesResponse> {
|
||||
return this.git.rest.repos.listReleases({
|
||||
owner: this.inputs.owner,
|
||||
repo: this.inputs.repo
|
||||
repo: this.inputs.repo,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -138,7 +134,7 @@ export class GithubReleases implements Releases {
|
||||
commitHash?: string,
|
||||
discussionCategory?: string,
|
||||
draft?: boolean,
|
||||
makeLatest?: "legacy" | "true" | "false" | undefined,
|
||||
makeLatest?: "legacy" | "true" | "false" | undefined,
|
||||
name?: string,
|
||||
prerelease?: boolean
|
||||
): Promise<UpdateReleaseResponse> {
|
||||
@@ -154,7 +150,7 @@ export class GithubReleases implements Releases {
|
||||
prerelease: prerelease,
|
||||
repo: this.inputs.repo,
|
||||
target_commitish: commitHash,
|
||||
tag_name: tag
|
||||
tag_name: tag,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -164,19 +160,19 @@ export class GithubReleases implements Releases {
|
||||
contentType: string,
|
||||
file: string | object,
|
||||
name: string,
|
||||
releaseId: number,
|
||||
releaseId: number
|
||||
): Promise<UploadArtifactResponse> {
|
||||
return this.git.rest.repos.uploadReleaseAsset({
|
||||
url: assetUrl,
|
||||
headers: {
|
||||
"content-length": contentLength,
|
||||
"content-type": contentType
|
||||
"content-type": contentType,
|
||||
},
|
||||
data: file as any,
|
||||
name: name,
|
||||
owner: this.inputs.owner,
|
||||
release_id: releaseId,
|
||||
repo: this.inputs.repo
|
||||
repo: this.inputs.repo,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user