Merge pull request #16 from softprops/draft-merger

Draft merger
This commit is contained in:
Doug Tangren 2019-09-17 19:39:58 +09:00 committed by GitHub
commit a6281eb824
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 148 additions and 16 deletions

View File

@ -1,9 +1,20 @@
## 0.1.0 ## 0.1.2
* Initial release * Add support for merging draft releases [#16](https://github.com/softprops/action-gh-release/pull/16)
GitHub's api doesn't explicitly have a way of fetching a draft release by tag name which caused draft releases to appear as separate releases when used in a build matrix.
This is now fixed.
---
## 0.1.1 ## 0.1.1
* Add support for publishing releases on all supported virtual hosts * Add support for publishing releases on all supported virtual hosts
You'll need to remove `docker://` prefix and use the `@v1` action tag You'll need to remove `docker://` prefix and use the `@v1` action tag
---
## 0.1.0
* Initial release

View File

@ -8,8 +8,6 @@
> **⚠️ Note:** To use this action, you must have access to the [GitHub Actions](https://github.com/features/actions) feature. GitHub Actions are currently only available in public beta. You can [apply for the GitHub Actions beta here](https://github.com/features/actions/signup/). > **⚠️ Note:** To use this action, you must have access to the [GitHub Actions](https://github.com/features/actions) feature. GitHub Actions are currently only available in public beta. You can [apply for the GitHub Actions beta here](https://github.com/features/actions/signup/).
> **⚠️ Note:** This action was previously implemented as a docker container, limiting its use to GitHub Actions Linux virtual environments only. With recent releases, we now support cross platform usage. You'll need to remove the `docker://` prefix in these versions
## 🤸 Usage ## 🤸 Usage
### 🚥 Limit releases to pushes to tags ### 🚥 Limit releases to pushes to tags
@ -148,4 +146,7 @@ The following are *required* as `step.env` keys
|----------------|--------------------------------------| |----------------|--------------------------------------|
| `GITHUB_TOKEN` | GITHUB_TOKEN as provided by `secrets`| | `GITHUB_TOKEN` | GITHUB_TOKEN as provided by `secrets`|
> **⚠️ Note:** This action was previously implemented as a docker container, limiting its use to GitHub Actions Linux virtual environments only. With recent releases, we now support cross platform usage. You'll need to remove the `docker://` prefix in these versions
Doug Tangren (softprops) 2019 Doug Tangren (softprops) 2019

View File

@ -8,10 +8,32 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next()); step((generator = generator.apply(thisArg, _arguments || [])).next());
}); });
}; };
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = require("fs"); const fs_1 = require("fs");
const mime_1 = require("mime"); const mime_1 = require("mime");
const path_1 = require("path"); const path_1 = require("path");
class GitHubReleaser {
constructor(github) {
this.github = github;
}
getReleaseByTag(params) {
return this.github.repos.getReleaseByTag(params);
}
createRelease(params) {
return this.github.repos.createRelease(params);
}
allReleases(params) {
return this.github.paginate.iterator(this.github.repos.listReleases.endpoint.merge(params));
}
}
exports.GitHubReleaser = GitHubReleaser;
exports.asset = (path) => { exports.asset = (path) => {
return { return {
name: path_1.basename(path), name: path_1.basename(path),
@ -36,11 +58,35 @@ exports.upload = (gh, url, path) => __awaiter(void 0, void 0, void 0, function*
file file
}); });
}); });
exports.release = (config, gh) => __awaiter(void 0, void 0, void 0, function* () { exports.release = (config, releaser) => __awaiter(void 0, void 0, void 0, function* () {
var e_1, _a;
const [owner, repo] = config.github_repository.split("/"); const [owner, repo] = config.github_repository.split("/");
const tag = config.github_ref.replace("refs/tags/", ""); const tag = config.github_ref.replace("refs/tags/", "");
try { try {
let release = yield gh.repos.getReleaseByTag({ // you can't get a an existing draft by tag
// so we must find one in the list of all releases
if (config.input_draft) {
try {
for (var _b = __asyncValues(releaser.allReleases({
owner,
repo
})), _c; _c = yield _b.next(), !_c.done;) {
const response = _c.value;
let release = response.data.find(release => release.tag_name === tag);
if (release) {
return release;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
}
let release = yield releaser.getReleaseByTag({
owner, owner,
repo, repo,
tag tag
@ -55,7 +101,7 @@ exports.release = (config, gh) => __awaiter(void 0, void 0, void 0, function* ()
const body = config.input_body; const body = config.input_body;
const draft = config.input_draft; const draft = config.input_draft;
console.log(`👩‍🏭 Creating new GitHub release for tag ${tag_name}...`); console.log(`👩‍🏭 Creating new GitHub release for tag ${tag_name}...`);
let release = yield gh.repos.createRelease({ let release = yield releaser.createRelease({
owner, owner,
repo, repo,
tag_name, tag_name,
@ -68,7 +114,7 @@ exports.release = (config, gh) => __awaiter(void 0, void 0, void 0, function* ()
catch (error) { catch (error) {
// presume a race with competing metrix runs // presume a race with competing metrix runs
console.log(`⚠️ GitHub release failed with status: ${error.status}, retrying...`); console.log(`⚠️ GitHub release failed with status: ${error.status}, retrying...`);
return exports.release(config, gh); return exports.release(config, releaser);
} }
} }
else { else {

View File

@ -22,7 +22,7 @@ function run() {
throw new Error(`⚠️ GitHub Releases requires a tag`); throw new Error(`⚠️ GitHub Releases requires a tag`);
} }
const gh = new github_2.GitHub(config.github_token); const gh = new github_2.GitHub(config.github_token);
let rel = yield github_1.release(config, gh); let rel = yield github_1.release(config, new github_1.GitHubReleaser(gh));
if (config.input_files) { if (config.input_files) {
util_1.paths(config.input_files).forEach((path) => __awaiter(this, void 0, void 0, function* () { util_1.paths(config.input_files).forEach((path) => __awaiter(this, void 0, void 0, function* () {
yield github_1.upload(gh, rel.upload_url, path); yield github_1.upload(gh, rel.upload_url, path);

View File

@ -14,6 +14,64 @@ export interface ReleaseAsset {
export interface Release { export interface Release {
upload_url: string; upload_url: string;
html_url: string; html_url: string;
tag_name: string;
}
export interface Releaser {
getReleaseByTag(params: {
owner: string;
repo: string;
tag: string;
}): Promise<{ data: Release }>;
createRelease(params: {
owner: string;
repo: string;
tag_name: string;
name: string;
body: string | undefined;
draft: boolean | undefined;
}): Promise<{ data: Release }>;
allReleases(params: {
owner: string;
repo: string;
}): AsyncIterableIterator<{ data: Release[] }>;
}
export class GitHubReleaser implements Releaser {
github: GitHub;
constructor(github: GitHub) {
this.github = github;
}
getReleaseByTag(params: {
owner: string;
repo: string;
tag: string;
}): Promise<{ data: Release }> {
return this.github.repos.getReleaseByTag(params);
}
createRelease(params: {
owner: string;
repo: string;
tag_name: string;
name: string;
body: string | undefined;
draft: boolean | undefined;
}): Promise<{ data: Release }> {
return this.github.repos.createRelease(params);
}
allReleases(params: {
owner: string;
repo: string;
}): AsyncIterableIterator<{ data: Release[] }> {
return this.github.paginate.iterator(
this.github.repos.listReleases.endpoint.merge(params)
);
}
} }
export const asset = (path: string): ReleaseAsset => { export const asset = (path: string): ReleaseAsset => {
@ -47,11 +105,27 @@ export const upload = async (
}); });
}; };
export const release = async (config: Config, gh: GitHub): Promise<Release> => { export const release = async (
config: Config,
releaser: Releaser
): Promise<Release> => {
const [owner, repo] = config.github_repository.split("/"); const [owner, repo] = config.github_repository.split("/");
const tag = config.github_ref.replace("refs/tags/", ""); const tag = config.github_ref.replace("refs/tags/", "");
try { try {
let release = await gh.repos.getReleaseByTag({ // you can't get a an existing draft by tag
// so we must find one in the list of all releases
if (config.input_draft) {
for await (const response of releaser.allReleases({
owner,
repo
})) {
let release = response.data.find(release => release.tag_name === tag);
if (release) {
return release;
}
}
}
let release = await releaser.getReleaseByTag({
owner, owner,
repo, repo,
tag tag
@ -65,7 +139,7 @@ export const release = async (config: Config, gh: GitHub): Promise<Release> => {
const body = config.input_body; const body = config.input_body;
const draft = config.input_draft; const draft = config.input_draft;
console.log(`👩‍🏭 Creating new GitHub release for tag ${tag_name}...`); console.log(`👩‍🏭 Creating new GitHub release for tag ${tag_name}...`);
let release = await gh.repos.createRelease({ let release = await releaser.createRelease({
owner, owner,
repo, repo,
tag_name, tag_name,
@ -79,7 +153,7 @@ export const release = async (config: Config, gh: GitHub): Promise<Release> => {
console.log( console.log(
`⚠️ GitHub release failed with status: ${error.status}, retrying...` `⚠️ GitHub release failed with status: ${error.status}, retrying...`
); );
return release(config, gh); return release(config, releaser);
} }
} else { } else {
console.log( console.log(

View File

@ -1,5 +1,5 @@
import { paths, parseConfig, isTag } from "./util"; import { paths, parseConfig, isTag } from "./util";
import { release, upload } from "./github"; import { release, upload, GitHubReleaser } from "./github";
import { setFailed } from "@actions/core"; import { setFailed } from "@actions/core";
import { GitHub } from "@actions/github"; import { GitHub } from "@actions/github";
import { env } from "process"; import { env } from "process";
@ -11,7 +11,7 @@ async function run() {
throw new Error(`⚠️ GitHub Releases requires a tag`); throw new Error(`⚠️ GitHub Releases requires a tag`);
} }
const gh = new GitHub(config.github_token); const gh = new GitHub(config.github_token);
let rel = await release(config, gh); let rel = await release(config, new GitHubReleaser(gh));
if (config.input_files) { if (config.input_files) {
paths(config.input_files).forEach(async path => { paths(config.input_files).forEach(async path => {
await upload(gh, rel.upload_url, path); await upload(gh, rel.upload_url, path);