From c3a232b7b2c0307d553e324778556bcca244c79a Mon Sep 17 00:00:00 2001 From: Nick Cipollo Date: Wed, 10 Feb 2021 12:12:01 -0500 Subject: [PATCH] Fix release mode --- lib/Action.js | 105 +++++++++++++++++++------------- lib/ArtifactUploader.js | 81 +++++++++++++++---------- lib/Main.js | 29 ++++++--- lib/Releases.js | 131 +++++++++++++++++++++++----------------- package.json | 2 +- tsconfig.json | 57 +---------------- yarn.lock | 2 +- 7 files changed, 213 insertions(+), 194 deletions(-) diff --git a/lib/Action.js b/lib/Action.js index 7ae76bf..ad938a7 100644 --- a/lib/Action.js +++ b/lib/Action.js @@ -1,4 +1,13 @@ "use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; Object.defineProperty(exports, "__esModule", { value: true }); exports.Action = void 0; const ErrorMessage_1 = require("./ErrorMessage"); @@ -8,60 +17,72 @@ class Action { this.releases = releases; this.uploader = uploader; } - async perform() { - const releaseResponse = await this.createOrUpdateRelease(); - const releaseId = releaseResponse.data.id; - const uploadUrl = releaseResponse.data.upload_url; - const artifacts = this.inputs.artifacts; - if (artifacts.length > 0) { - await this.uploader.uploadArtifacts(artifacts, releaseId, uploadUrl); - } - } - async createOrUpdateRelease() { - if (this.inputs.allowUpdates) { - try { - const getResponse = await this.releases.getByTag(this.inputs.tag); - return await this.updateRelease(getResponse.data.id); + perform() { + return __awaiter(this, void 0, void 0, function* () { + const releaseResponse = yield this.createOrUpdateRelease(); + const releaseId = releaseResponse.data.id; + const uploadUrl = releaseResponse.data.upload_url; + const artifacts = this.inputs.artifacts; + if (artifacts.length > 0) { + yield this.uploader.uploadArtifacts(artifacts, releaseId, uploadUrl); } - catch (error) { - if (Action.noPublishedRelease(error)) { - return await this.updateDraftOrCreateRelease(); + }); + } + createOrUpdateRelease() { + return __awaiter(this, void 0, void 0, function* () { + if (this.inputs.allowUpdates) { + try { + const getResponse = yield this.releases.getByTag(this.inputs.tag); + return yield this.updateRelease(getResponse.data.id); } - else { - throw error; + catch (error) { + if (Action.noPublishedRelease(error)) { + return yield this.updateDraftOrCreateRelease(); + } + else { + throw error; + } } } - } - else { - return await this.createRelease(); - } + else { + return yield this.createRelease(); + } + }); } - async updateRelease(id) { - return await this.releases.update(id, this.inputs.tag, this.inputs.updatedReleaseBody, this.inputs.commit, this.inputs.draft, this.inputs.updatedReleaseName, this.inputs.prerelease); + updateRelease(id) { + return __awaiter(this, void 0, void 0, function* () { + return yield this.releases.update(id, this.inputs.tag, this.inputs.updatedReleaseBody, this.inputs.commit, this.inputs.draft, this.inputs.updatedReleaseName, this.inputs.prerelease); + }); } static noPublishedRelease(error) { const errorMessage = new ErrorMessage_1.ErrorMessage(error); return errorMessage.status == 404; } - async updateDraftOrCreateRelease() { - const draftReleaseId = await this.findMatchingDraftReleaseId(); - if (draftReleaseId) { - return await this.updateRelease(draftReleaseId); - } - else { - return await this.createRelease(); - } + updateDraftOrCreateRelease() { + return __awaiter(this, void 0, void 0, function* () { + const draftReleaseId = yield this.findMatchingDraftReleaseId(); + if (draftReleaseId) { + return yield this.updateRelease(draftReleaseId); + } + else { + return yield this.createRelease(); + } + }); } - async findMatchingDraftReleaseId() { - const tag = this.inputs.tag; - const response = await this.releases.listReleases(); - const releases = response.data; - const draftRelease = releases.find(release => release.draft && release.tag_name == tag); - return draftRelease === null || draftRelease === void 0 ? void 0 : draftRelease.id; + findMatchingDraftReleaseId() { + return __awaiter(this, void 0, void 0, function* () { + const tag = this.inputs.tag; + const response = yield this.releases.listReleases(); + const releases = response.data; + const draftRelease = releases.find(release => release.draft && release.tag_name == tag); + return draftRelease === null || draftRelease === void 0 ? void 0 : draftRelease.id; + }); } - async createRelease() { - const response = await this.releases.create(this.inputs.tag, this.inputs.createdReleaseBody, this.inputs.commit, this.inputs.draft, this.inputs.createdReleaseName, this.inputs.prerelease); - return response; + createRelease() { + return __awaiter(this, void 0, void 0, function* () { + const response = yield this.releases.create(this.inputs.tag, this.inputs.createdReleaseBody, this.inputs.commit, this.inputs.draft, this.inputs.createdReleaseName, this.inputs.prerelease); + return response; + }); } } exports.Action = Action; diff --git a/lib/ArtifactUploader.js b/lib/ArtifactUploader.js index 7976abc..91c2415 100644 --- a/lib/ArtifactUploader.js +++ b/lib/ArtifactUploader.js @@ -18,6 +18,15 @@ var __importStar = (this && this.__importStar) || function (mod) { __setModuleDefault(result, mod); return result; }; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; Object.defineProperty(exports, "__esModule", { value: true }); exports.GithubArtifactUploader = void 0; const core = __importStar(require("@actions/core")); @@ -26,43 +35,49 @@ class GithubArtifactUploader { this.releases = releases; this.replacesExistingArtifacts = replacesExistingArtifacts; } - async uploadArtifacts(artifacts, releaseId, uploadUrl) { - if (this.replacesExistingArtifacts) { - await this.deleteUpdatedArtifacts(artifacts, releaseId); - } - for (const artifact of artifacts) { - await this.uploadArtifact(artifact, releaseId, uploadUrl); - } - } - async uploadArtifact(artifact, releaseId, uploadUrl, retry = 3) { - try { - core.debug(`Uploading artifact ${artifact.name}...`); - await this.releases.uploadArtifact(uploadUrl, artifact.contentLength, artifact.contentType, artifact.readFile(), artifact.name, releaseId); - } - catch (error) { - if (error.status >= 500 && retry > 0) { - core.warning(`Failed to upload artifact ${artifact.name}. ${error.message}. Retrying...`); - await this.uploadArtifact(artifact, releaseId, uploadUrl, retry - 1); + uploadArtifacts(artifacts, releaseId, uploadUrl) { + return __awaiter(this, void 0, void 0, function* () { + if (this.replacesExistingArtifacts) { + yield this.deleteUpdatedArtifacts(artifacts, releaseId); } - else { - core.warning(`Failed to upload artifact ${artifact.name}. ${error.message}.`); + for (const artifact of artifacts) { + yield this.uploadArtifact(artifact, releaseId, uploadUrl); } - } - } - async deleteUpdatedArtifacts(artifacts, releaseId) { - const response = await this.releases.listArtifactsForRelease(releaseId); - const releaseAssets = response.data; - const assetByName = {}; - releaseAssets.forEach(asset => { - assetByName[asset.name] = asset; }); - for (const artifact of artifacts) { - const asset = assetByName[artifact.name]; - if (asset) { - core.debug(`Deleting existing artifact ${artifact.name}...`); - await this.releases.deleteArtifact(asset.id); + } + uploadArtifact(artifact, releaseId, uploadUrl, retry = 3) { + return __awaiter(this, void 0, void 0, function* () { + try { + core.debug(`Uploading artifact ${artifact.name}...`); + yield this.releases.uploadArtifact(uploadUrl, artifact.contentLength, artifact.contentType, artifact.readFile(), artifact.name, releaseId); } - } + catch (error) { + if (error.status >= 500 && retry > 0) { + core.warning(`Failed to upload artifact ${artifact.name}. ${error.message}. Retrying...`); + yield this.uploadArtifact(artifact, releaseId, uploadUrl, retry - 1); + } + else { + core.warning(`Failed to upload artifact ${artifact.name}. ${error.message}.`); + } + } + }); + } + deleteUpdatedArtifacts(artifacts, releaseId) { + return __awaiter(this, void 0, void 0, function* () { + const response = yield this.releases.listArtifactsForRelease(releaseId); + const releaseAssets = response.data; + const assetByName = {}; + releaseAssets.forEach(asset => { + assetByName[asset.name] = asset; + }); + for (const artifact of artifacts) { + const asset = assetByName[artifact.name]; + if (asset) { + core.debug(`Deleting existing artifact ${artifact.name}...`); + yield this.releases.deleteArtifact(asset.id); + } + } + }); } } exports.GithubArtifactUploader = GithubArtifactUploader; diff --git a/lib/Main.js b/lib/Main.js index 8230327..044531f 100644 --- a/lib/Main.js +++ b/lib/Main.js @@ -18,6 +18,15 @@ var __importStar = (this && this.__importStar) || function (mod) { __setModuleDefault(result, mod); return result; }; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; Object.defineProperty(exports, "__esModule", { value: true }); const github = __importStar(require("@actions/github")); const core = __importStar(require("@actions/core")); @@ -27,15 +36,17 @@ const Action_1 = require("./Action"); const ArtifactUploader_1 = require("./ArtifactUploader"); const ArtifactGlobber_1 = require("./ArtifactGlobber"); const ErrorMessage_1 = require("./ErrorMessage"); -async function run() { - try { - const action = createAction(); - await action.perform(); - } - catch (error) { - const errorMessage = new ErrorMessage_1.ErrorMessage(error); - core.setFailed(errorMessage.toString()); - } +function run() { + return __awaiter(this, void 0, void 0, function* () { + try { + const action = createAction(); + yield action.perform(); + } + catch (error) { + const errorMessage = new ErrorMessage_1.ErrorMessage(error); + core.setFailed(errorMessage.toString()); + } + }); } function createAction() { const token = core.getInput('token'); diff --git a/lib/Releases.js b/lib/Releases.js index fb7f9d0..0948fce 100644 --- a/lib/Releases.js +++ b/lib/Releases.js @@ -1,4 +1,13 @@ "use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; Object.defineProperty(exports, "__esModule", { value: true }); exports.GithubReleases = void 0; class GithubReleases { @@ -6,72 +15,86 @@ class GithubReleases { this.inputs = inputs; this.git = git; } - async create(tag, body, commitHash, draft, name, prerelease) { - // noinspection TypeScriptValidateJSTypes - return this.git.repos.createRelease({ - body: body, - name: name, - draft: draft, - owner: this.inputs.owner, - prerelease: prerelease, - repo: this.inputs.repo, - target_commitish: commitHash, - tag_name: tag + create(tag, body, commitHash, draft, name, prerelease) { + return __awaiter(this, void 0, void 0, function* () { + // noinspection TypeScriptValidateJSTypes + return this.git.repos.createRelease({ + body: body, + name: name, + draft: draft, + owner: this.inputs.owner, + prerelease: prerelease, + repo: this.inputs.repo, + target_commitish: commitHash, + tag_name: tag + }); }); } - async deleteArtifact(assetId) { - return this.git.repos.deleteReleaseAsset({ - asset_id: assetId, - owner: this.inputs.owner, - repo: this.inputs.repo + deleteArtifact(assetId) { + return __awaiter(this, void 0, void 0, function* () { + return this.git.repos.deleteReleaseAsset({ + asset_id: assetId, + owner: this.inputs.owner, + repo: this.inputs.repo + }); }); } - async getByTag(tag) { - return this.git.repos.getReleaseByTag({ - owner: this.inputs.owner, - repo: this.inputs.repo, - tag: tag + getByTag(tag) { + return __awaiter(this, void 0, void 0, function* () { + return this.git.repos.getReleaseByTag({ + owner: this.inputs.owner, + repo: this.inputs.repo, + tag: tag + }); }); } - async listArtifactsForRelease(releaseId) { - return this.git.repos.listReleaseAssets({ - owner: this.inputs.owner, - release_id: releaseId, - repo: this.inputs.repo + listArtifactsForRelease(releaseId) { + return __awaiter(this, void 0, void 0, function* () { + return this.git.repos.listReleaseAssets({ + owner: this.inputs.owner, + release_id: releaseId, + repo: this.inputs.repo + }); }); } - async listReleases() { - return this.git.repos.listReleases({ - owner: this.inputs.owner, - repo: this.inputs.repo + listReleases() { + return __awaiter(this, void 0, void 0, function* () { + return this.git.repos.listReleases({ + owner: this.inputs.owner, + repo: this.inputs.repo + }); }); } - async update(id, tag, body, commitHash, draft, name, prerelease) { - // noinspection TypeScriptValidateJSTypes - return this.git.repos.updateRelease({ - release_id: id, - body: body, - name: name, - draft: draft, - owner: this.inputs.owner, - prerelease: prerelease, - repo: this.inputs.repo, - target_commitish: commitHash, - tag_name: tag + update(id, tag, body, commitHash, draft, name, prerelease) { + return __awaiter(this, void 0, void 0, function* () { + // noinspection TypeScriptValidateJSTypes + return this.git.repos.updateRelease({ + release_id: id, + body: body, + name: name, + draft: draft, + owner: this.inputs.owner, + prerelease: prerelease, + repo: this.inputs.repo, + target_commitish: commitHash, + tag_name: tag + }); }); } - async uploadArtifact(assetUrl, contentLength, contentType, file, name, releaseId) { - return this.git.repos.uploadReleaseAsset({ - url: assetUrl, - headers: { - "content-length": contentLength, - "content-type": contentType - }, - data: file, - name: name, - owner: this.inputs.owner, - release_id: releaseId, - repo: this.inputs.repo + uploadArtifact(assetUrl, contentLength, contentType, file, name, releaseId) { + return __awaiter(this, void 0, void 0, function* () { + return this.git.repos.uploadReleaseAsset({ + url: assetUrl, + headers: { + "content-length": contentLength, + "content-type": contentType + }, + data: file, + name: name, + owner: this.inputs.owner, + release_id: releaseId, + repo: this.inputs.repo + }); }); } } diff --git a/package.json b/package.json index 16674e2..1cef32f 100644 --- a/package.json +++ b/package.json @@ -25,12 +25,12 @@ "dependencies": { "@actions/core": "^1.2.6", "@actions/github": "^4.0.0", + "@types/glob": "^7.1.3", "add": "^2.0.6", "glob": "^7.1.4", "global": "^4.4.0" }, "devDependencies": { - "@types/glob": "^7.1.1", "@types/jest": "^26.0.20", "@types/node": "^14.14.25", "jest": "^26.1.0", diff --git a/tsconfig.json b/tsconfig.json index 2570c60..353d2ea 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,63 +1,12 @@ { "compilerOptions": { - /* Basic Options */ - // "incremental": true, /* Enable incremental compilation */ - "target": "es2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ + "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ - // "allowJs": true, /* Allow javascript files to be compiled. */ - // "checkJs": true, /* Report errors in .js files. */ - // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ - // "declaration": true, /* Generates corresponding '.d.ts' file. */ - // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ - // "sourceMap": true, /* Generates corresponding '.map' file. */ - // "outFile": "./", /* Concatenate and emit output to single file. */ "outDir": "./lib", /* Redirect output structure to the directory. */ "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ - // "composite": true, /* Enable project compilation */ - // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ - // "removeComments": true, /* Do not emit comments to output. */ - // "noEmit": true, /* Do not emit outputs. */ - // "importHelpers": true, /* Import emit helpers from 'tslib'. */ - // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ - // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ - - /* Strict Type-Checking Options */ "strict": true, /* Enable all strict type-checking options. */ - "noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */ - // "strictNullChecks": true, /* Enable strict null checks. */ - // "strictFunctionTypes": true, /* Enable strict checking of function types. */ - // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ - // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ - // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ - // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ - - /* Additional Checks */ - // "noUnusedLocals": true, /* Report errors on unused locals. */ - // "noUnusedParameters": true, /* Report errors on unused parameters. */ - // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ - // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ - - /* Module Resolution Options */ - // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ - // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ - // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ - // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ - // "typeRoots": [], /* List of folders to include type definitions from. */ - // "types": [], /* Type declaration files to be included in compilation. */ - // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ - // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ - // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ - - /* Source Map Options */ - // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ - // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ - // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ - - /* Experimental Options */ - // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ - // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ }, "exclude": ["node_modules", "**/*.test.ts"] -} +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index c844b20..48fc3de 100644 --- a/yarn.lock +++ b/yarn.lock @@ -622,7 +622,7 @@ dependencies: "@babel/types" "^7.3.0" -"@types/glob@^7.1.1": +"@types/glob@^7.1.3": version "7.1.3" resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.3.tgz#e6ba80f36b7daad2c685acd9266382e68985c183" integrity sha512-SEYeGAIQIQX8NN6LDKprLjbrd5dARM5EXsd8GI/A5l0apYI1fGMWgPHSe4ZKL4eozlAyI+doUE9XbYS4xCkQ1w==