Compare commits

..

5 Commits

Author SHA1 Message Date
83e65faee7 debug 2021-08-09 23:39:13 -04:00
c95b4533d0 debug 2021-08-09 23:36:44 -04:00
0eaa34fb9f debug 2021-08-09 23:33:55 -04:00
c54d2bad6b debug 2021-08-09 23:26:29 -04:00
4f0fb075a4 debug 2021-08-09 23:23:35 -04:00
7 changed files with 71 additions and 59 deletions

View File

@ -1,15 +1,6 @@
## 0.1.13
- fix issue with multiple runs concatenating release bodies [#145](https://github.com/softprops/action-gh-release/pull/145)
## 0.1.12
- fix bug leading to empty strings subsituted for inputs users don't provide breaking api calls [#144](https://github.com/softprops/action-gh-release/pull/144)
## 0.1.11 ## 0.1.11
- better error message on release create failed [#143](https://github.com/softprops/action-gh-release/pull/143) - better error message on release create failed [#143](https://github.com/softprops/action-gh-release/pull/143)
## 0.1.10 ## 0.1.10
- fixed error message formatting for file uploads - fixed error message formatting for file uploads

View File

@ -11,7 +11,7 @@ import * as assert from "assert";
describe("util", () => { describe("util", () => {
describe("uploadUrl", () => { describe("uploadUrl", () => {
it("strips template", () => { it("stripts template", () => {
assert.equal( assert.equal(
uploadUrl( uploadUrl(
"https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}" "https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}"
@ -95,33 +95,21 @@ describe("util", () => {
}); });
describe("parseConfig", () => { describe("parseConfig", () => {
it("parses basic config", () => { it("parses basic config", () => {
assert.deepStrictEqual( assert.deepStrictEqual(parseConfig({}), {
parseConfig({ github_ref: "",
// note: inputs declared in actions.yml, even when declared not required, github_repository: "",
// are still provided by the actions runtime env as empty strings instead of github_token: "",
// the normal absent env value one would expect. this breaks things input_body: undefined,
// as an empty string !== undefined in terms of what we pass to the api input_body_path: undefined,
// so we cover that in a test case here to ensure undefined values are actually input_draft: undefined,
// resolved as undefined and not empty strings input_prerelease: undefined,
INPUT_TARGET_COMMITISH: "", input_files: [],
INPUT_DISCUSSION_CATEGORY_NAME: "" input_name: undefined,
}), input_tag_name: undefined,
{ input_fail_on_unmatched_files: false,
github_ref: "", input_target_commitish: undefined,
github_repository: "", input_discussion_category_name: undefined
github_token: "", });
input_body: undefined,
input_body_path: undefined,
input_draft: undefined,
input_prerelease: undefined,
input_files: [],
input_name: undefined,
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
input_target_commitish: undefined,
input_discussion_category_name: undefined
}
);
}); });
it("parses basic config with commitish", () => { it("parses basic config with commitish", () => {

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "action-gh-release", "name": "action-gh-release",
"version": "0.1.13", "version": "0.1.8",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "action-gh-release", "name": "action-gh-release",
"version": "0.1.13", "version": "0.1.11",
"private": true, "private": true,
"description": "GitHub Action for creating GitHub Releases", "description": "GitHub Action for creating GitHub Releases",
"main": "lib/main.js", "main": "lib/main.js",

View File

@ -124,7 +124,7 @@ export const asset = (path: string): ReleaseAsset => {
name: basename(path), name: basename(path),
mime: mimeOrDefault(path), mime: mimeOrDefault(path),
size: lstatSync(path).size, size: lstatSync(path).size,
data: readFileSync(path) data: readFileSync(path),
}; };
}; };
@ -149,7 +149,7 @@ export const upload = async (
await github.rest.repos.deleteReleaseAsset({ await github.rest.repos.deleteReleaseAsset({
asset_id: currentAsset.id || 1, asset_id: currentAsset.id || 1,
owner, owner,
repo repo,
}); });
} }
console.log(`⬆️ Uploading ${name}...`); console.log(`⬆️ Uploading ${name}...`);
@ -159,10 +159,10 @@ export const upload = async (
headers: { headers: {
"content-length": `${size}`, "content-length": `${size}`,
"content-type": mime, "content-type": mime,
authorization: `token ${config.github_token}` authorization: `token ${config.github_token}`,
}, },
method: "POST", method: "POST",
body body,
}); });
const json = await resp.json(); const json = await resp.json();
if (resp.status !== 201) { if (resp.status !== 201) {
@ -199,19 +199,21 @@ export const release = async (
if (config.input_draft) { if (config.input_draft) {
for await (const response of releaser.allReleases({ for await (const response of releaser.allReleases({
owner, owner,
repo repo,
})) { })) {
let release = response.data.find(release => release.tag_name === tag); let release = response.data.find((release) => release.tag_name === tag);
if (release) { if (release) {
return release; return release;
} }
} }
} }
console.log(`fetching existing release for tag ${owner}/${repo}/${tag}`);
let existingRelease = await releaser.getReleaseByTag({ let existingRelease = await releaser.getReleaseByTag({
owner, owner,
repo, repo,
tag tag,
}); });
console.log(`found release ${existingRelease.data.id}`);
const release_id = existingRelease.data.id; const release_id = existingRelease.data.id;
let target_commitish: string; let target_commitish: string;
@ -229,11 +231,12 @@ export const release = async (
const tag_name = tag; const tag_name = tag;
const name = config.input_name || existingRelease.data.name || tag; const name = config.input_name || existingRelease.data.name || tag;
// revisit: support a new body-concat-strategy input for accumulating
// body parts as a release gets updated. some users will likely want this while let body: string = "";
// others won't previously this was duplicating content for most which if (existingRelease.data.body) body += existingRelease.data.body;
// no one wants let workflowBody = releaseBody(config);
let body = releaseBody(config) || existingRelease.data.body || ""; if (existingRelease.data.body && workflowBody) body += "\n";
if (workflowBody) body += workflowBody;
const draft = const draft =
config.input_draft !== undefined config.input_draft !== undefined
@ -244,6 +247,21 @@ export const release = async (
? config.input_prerelease ? config.input_prerelease
: existingRelease.data.prerelease; : existingRelease.data.prerelease;
console.log(
`attemping update of release_id ${release_id} tag_name ${tag_name} target_commitish ${target_commitish} discussion_category_name ${discussion_category_name}`
);
console.log({
owner,
repo,
release_id,
tag_name,
target_commitish,
name,
body,
draft,
prerelease,
discussion_category_name,
});
const release = await releaser.updateRelease({ const release = await releaser.updateRelease({
owner, owner,
repo, repo,
@ -254,11 +272,14 @@ export const release = async (
body, body,
draft, draft,
prerelease, prerelease,
discussion_category_name discussion_category_name,
}); });
console.log(`updated release ${release_id}`);
return release.data; return release.data;
} catch (error) { } catch (error) {
if (error.status === 404) { if (error.status === 404) {
console.log(`update failed with 404`);
console.log(JSON.stringify(error.response.data.errors));
const tag_name = tag; const tag_name = tag;
const name = config.input_name || tag; const name = config.input_name || tag;
const body = releaseBody(config); const body = releaseBody(config);
@ -272,6 +293,18 @@ export const release = async (
console.log( console.log(
`👩‍🏭 Creating new GitHub release for tag ${tag_name}${commitMessage}...` `👩‍🏭 Creating new GitHub release for tag ${tag_name}${commitMessage}...`
); );
console.log({
owner,
repo,
tag_name,
name,
body,
draft,
prerelease,
target_commitish,
discussion_category_name,
});
try { try {
let release = await releaser.createRelease({ let release = await releaser.createRelease({
owner, owner,
@ -282,7 +315,7 @@ export const release = async (
draft, draft,
prerelease, prerelease,
target_commitish, target_commitish,
discussion_category_name discussion_category_name,
}); });
return release.data; return release.data;
} catch (error) { } catch (error) {

View File

@ -42,8 +42,8 @@ export const parseInputFiles = (files: string): string[] => {
(acc, line) => (acc, line) =>
acc acc
.concat(line.split(",")) .concat(line.split(","))
.filter(pat => pat) .filter((pat) => pat)
.map(pat => pat.trim()), .map((pat) => pat.trim()),
[] []
); );
}; };
@ -65,14 +65,14 @@ export const parseConfig = (env: Env): Config => {
input_fail_on_unmatched_files: env.INPUT_FAIL_ON_UNMATCHED_FILES == "true", input_fail_on_unmatched_files: env.INPUT_FAIL_ON_UNMATCHED_FILES == "true",
input_target_commitish: env.INPUT_TARGET_COMMITISH || undefined, input_target_commitish: env.INPUT_TARGET_COMMITISH || undefined,
input_discussion_category_name: input_discussion_category_name:
env.INPUT_DISCUSSION_CATEGORY_NAME || undefined env.INPUT_DISCUSSION_CATEGORY_NAME || undefined,
}; };
}; };
export const paths = (patterns: string[]): string[] => { export const paths = (patterns: string[]): string[] => {
return patterns.reduce((acc: string[], pattern: string): string[] => { return patterns.reduce((acc: string[], pattern: string): string[] => {
return acc.concat( return acc.concat(
glob.sync(pattern).filter(path => lstatSync(path).isFile()) glob.sync(pattern).filter((path) => lstatSync(path).isFile())
); );
}, []); }, []);
}; };
@ -80,7 +80,7 @@ export const paths = (patterns: string[]): string[] => {
export const unmatchedPatterns = (patterns: string[]): string[] => { export const unmatchedPatterns = (patterns: string[]): string[] => {
return patterns.reduce((acc: string[], pattern: string): string[] => { return patterns.reduce((acc: string[], pattern: string): string[] => {
return acc.concat( return acc.concat(
glob.sync(pattern).filter(path => lstatSync(path).isFile()).length == 0 glob.sync(pattern).filter((path) => lstatSync(path).isFile()).length == 0
? [pattern] ? [pattern]
: [] : []
); );