diff --git a/action.yml b/action.yml index 95dec15..f5f7a52 100644 --- a/action.yml +++ b/action.yml @@ -17,11 +17,11 @@ inputs: draft: description: "The resultant deployment is a draft Release that only repository collaborators can see. This gives you an opportunity to examine and edit the draft release." required: false - default: "true" + default: "" prerelease: description: "The resultant deployment is a Prerelease. This gives you an opportunity to examine and edit the prerelease." required: false - default: "false" + default: "" tags: description: "With tags: true, your Releases deployment will trigger if and only if the build is a tagged build." required: false diff --git a/lib/index.js b/lib/index.js index a7697a5..410c768 100755 --- a/lib/index.js +++ b/lib/index.js @@ -20639,10 +20639,10 @@ function getInputAsArray(name) { .filter((v) => !!v); } exports.getInputAsArray = getInputAsArray; -function getInputAsBool(name) { +function getInputAsBool(name, default_value = false) { const res = (0, string_env_interpolation_1.env)(action_core.getInput(name) || "").toLowerCase(); if (!res) { - return false; + return default_value; } return (res != "false" && res != "disabled" && @@ -20677,7 +20677,7 @@ async function run() { const upload_files_pattern = getInputAsArray("file"); const delete_files_pattern = getInputAsArray("delete_file"); const is_overwrite = getInputAsBool("overwrite"); - let is_draft = getInputAsBool("draft"); + let is_draft = getInputAsBool("draft", true); let is_prerelease = getInputAsBool("prerelease"); const with_tags = getInputAsBool("tags"); const with_branches = getInputAsArray("branches"); @@ -20777,11 +20777,20 @@ async function run() { repo: target_repo, }).catch((error) => { console.log(`Try to get latest release from ${target_owner}/${target_repo} : ${error.message}`); + return undefined; }); + if (deploy_release) { + if (is_verbose) { + console.log(`getLatestRelease and the target release = ${JSON.stringify(deploy_release.data)}`); + } + } + else if (is_verbose) { + console.log(`Call getLatestRelease but not found`); + } } if (release_id != 0 && !(deploy_release && deploy_release.data)) { console.log(`Try to get release by id ${release_id} from ${target_owner}/${target_repo}`); - deploy_release = await octokit.rest.repos.getRelease({ + const release_content_by_id = await octokit.rest.repos.getRelease({ owner: target_owner, repo: target_repo, release_id: release_id, @@ -20790,34 +20799,40 @@ async function run() { console.error(message); action_core.setFailed(message); }); - if (!deploy_release) { - return; - } - release_tag_name = deploy_release.data.tag_name; - if (deploy_release.data.name) { - release_name = deploy_release.data.name; - } - if (isInputEmpty("draft")) { - is_draft = deploy_release.data.draft; + if (release_content_by_id) { + deploy_release = release_content_by_id; + if (is_verbose) { + console.log(`getRelease and the target release = ${JSON.stringify(release_content_by_id.data)}`); + } } - if (isInputEmpty("prerelease")) { - is_prerelease = deploy_release.data.prerelease; + else if (is_verbose) { + console.log(`Call getRelease but not found`); } } if (!(deploy_release && deploy_release.data)) { console.log(`Try to get release by tag ${release_tag_name} from ${target_owner}/${target_repo}`); - deploy_release = await octokit.rest.repos.getReleaseByTag({ + const release_context_by_tag = await octokit.rest.repos.getReleaseByTag({ owner: target_owner, repo: target_repo, tag: release_tag_name, }).catch((error) => { console.log(`Try to get release by tag ${release_tag_name} from ${target_owner}/${target_repo} : ${error.message}`); }); + if (release_context_by_tag) { + deploy_release = release_context_by_tag; + if (is_verbose) { + console.log(`getReleaseByTag and the target release = ${JSON.stringify(release_context_by_tag.data)}`); + } + } + else if (is_verbose) { + console.log(`Call getReleaseByTag but not found`); + } } // We can not get a draft release by getReleaseByTag, so we try to find the draft release with the same name by if (!(deploy_release && deploy_release.data) && release_tag_name_has_ref) { + let try_draft_release; console.log(`Try to get draft release ${release_tag_name} from ${target_owner}/${target_repo}`); - deploy_release = await octokit.rest.repos.listReleases({ + try_draft_release = await octokit.rest.repos.listReleases({ owner: target_owner, repo: target_repo, page: 1, @@ -20836,16 +20851,21 @@ async function run() { return undefined; }).catch((error) => { console.log(`Try to get draft release ${release_tag_name} from ${target_owner}/${target_repo} : ${error.message}`); + return undefined; }); - } - if (is_verbose) { - console.log("============================= v3 API: getReleaseByTag ============================="); - } - if (deploy_release && deploy_release.headers) { - console.log(`Get release ${release_tag_name} from ${target_owner}/${target_repo} : ${deploy_release.headers.status || ("HTTP Code: " + deploy_release.status)}`); - if (is_verbose) { - console.log(`getReleaseByTag.data = ${JSON.stringify(deploy_release.data)}`); + if (try_draft_release && try_draft_release.headers) { + deploy_release = try_draft_release; + console.log(`Get release ${release_tag_name} from ${target_owner}/${target_repo} : ${deploy_release.headers.status || ("HTTP Code: " + deploy_release.status)}`); + if (is_verbose) { + console.log(`listReleases and the target release = ${JSON.stringify(try_draft_release.data)}`); + } } + else if (is_verbose) { + console.log(`Call listReleases but no matched release`); + } + } + if (deploy_release && deploy_release.data) { + release_tag_name = deploy_release.data.tag_name; if (deploy_release.data.name) { release_name = deploy_release.data.name; } diff --git a/lib/index.js.map b/lib/index.js.map index a7697a5..410c768 100755 --- a/lib/index.js.map +++ b/lib/index.js.map @@ -20639,10 +20639,10 @@ function getInputAsArray(name) { .filter((v) => !!v); } exports.getInputAsArray = getInputAsArray; -function getInputAsBool(name) { +function getInputAsBool(name, default_value = false) { const res = (0, string_env_interpolation_1.env)(action_core.getInput(name) || "").toLowerCase(); if (!res) { - return false; + return default_value; } return (res != "false" && res != "disabled" && @@ -20677,7 +20677,7 @@ async function run() { const upload_files_pattern = getInputAsArray("file"); const delete_files_pattern = getInputAsArray("delete_file"); const is_overwrite = getInputAsBool("overwrite"); - let is_draft = getInputAsBool("draft"); + let is_draft = getInputAsBool("draft", true); let is_prerelease = getInputAsBool("prerelease"); const with_tags = getInputAsBool("tags"); const with_branches = getInputAsArray("branches"); @@ -20777,11 +20777,20 @@ async function run() { repo: target_repo, }).catch((error) => { console.log(`Try to get latest release from ${target_owner}/${target_repo} : ${error.message}`); + return undefined; }); + if (deploy_release) { + if (is_verbose) { + console.log(`getLatestRelease and the target release = ${JSON.stringify(deploy_release.data)}`); + } + } + else if (is_verbose) { + console.log(`Call getLatestRelease but not found`); + } } if (release_id != 0 && !(deploy_release && deploy_release.data)) { console.log(`Try to get release by id ${release_id} from ${target_owner}/${target_repo}`); - deploy_release = await octokit.rest.repos.getRelease({ + const release_content_by_id = await octokit.rest.repos.getRelease({ owner: target_owner, repo: target_repo, release_id: release_id, @@ -20790,34 +20799,40 @@ async function run() { console.error(message); action_core.setFailed(message); }); - if (!deploy_release) { - return; - } - release_tag_name = deploy_release.data.tag_name; - if (deploy_release.data.name) { - release_name = deploy_release.data.name; - } - if (isInputEmpty("draft")) { - is_draft = deploy_release.data.draft; + if (release_content_by_id) { + deploy_release = release_content_by_id; + if (is_verbose) { + console.log(`getRelease and the target release = ${JSON.stringify(release_content_by_id.data)}`); + } } - if (isInputEmpty("prerelease")) { - is_prerelease = deploy_release.data.prerelease; + else if (is_verbose) { + console.log(`Call getRelease but not found`); } } if (!(deploy_release && deploy_release.data)) { console.log(`Try to get release by tag ${release_tag_name} from ${target_owner}/${target_repo}`); - deploy_release = await octokit.rest.repos.getReleaseByTag({ + const release_context_by_tag = await octokit.rest.repos.getReleaseByTag({ owner: target_owner, repo: target_repo, tag: release_tag_name, }).catch((error) => { console.log(`Try to get release by tag ${release_tag_name} from ${target_owner}/${target_repo} : ${error.message}`); }); + if (release_context_by_tag) { + deploy_release = release_context_by_tag; + if (is_verbose) { + console.log(`getReleaseByTag and the target release = ${JSON.stringify(release_context_by_tag.data)}`); + } + } + else if (is_verbose) { + console.log(`Call getReleaseByTag but not found`); + } } // We can not get a draft release by getReleaseByTag, so we try to find the draft release with the same name by if (!(deploy_release && deploy_release.data) && release_tag_name_has_ref) { + let try_draft_release; console.log(`Try to get draft release ${release_tag_name} from ${target_owner}/${target_repo}`); - deploy_release = await octokit.rest.repos.listReleases({ + try_draft_release = await octokit.rest.repos.listReleases({ owner: target_owner, repo: target_repo, page: 1, @@ -20836,16 +20851,21 @@ async function run() { return undefined; }).catch((error) => { console.log(`Try to get draft release ${release_tag_name} from ${target_owner}/${target_repo} : ${error.message}`); + return undefined; }); - } - if (is_verbose) { - console.log("============================= v3 API: getReleaseByTag ============================="); - } - if (deploy_release && deploy_release.headers) { - console.log(`Get release ${release_tag_name} from ${target_owner}/${target_repo} : ${deploy_release.headers.status || ("HTTP Code: " + deploy_release.status)}`); - if (is_verbose) { - console.log(`getReleaseByTag.data = ${JSON.stringify(deploy_release.data)}`); + if (try_draft_release && try_draft_release.headers) { + deploy_release = try_draft_release; + console.log(`Get release ${release_tag_name} from ${target_owner}/${target_repo} : ${deploy_release.headers.status || ("HTTP Code: " + deploy_release.status)}`); + if (is_verbose) { + console.log(`listReleases and the target release = ${JSON.stringify(try_draft_release.data)}`); + } } + else if (is_verbose) { + console.log(`Call listReleases but no matched release`); + } + } + if (deploy_release && deploy_release.data) { + release_tag_name = deploy_release.data.tag_name; if (deploy_release.data.name) { release_name = deploy_release.data.name; } diff --git a/package.json b/package.json index cccd20d..2d1d54a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "upload-to-github-release", - "version": "1.3.8", + "version": "1.3.9", "description": "Github Action to deploy files to github release", "main": "index.js", "scripts": { diff --git a/src/index.ts b/src/index.ts index 48ea2c4..5af2ed3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,10 +19,10 @@ function getInputAsArray(name: string): string[] { .filter((v) => !!v); } -function getInputAsBool(name: string): boolean { +function getInputAsBool(name: string, default_value: boolean = false): boolean { const res = env(action_core.getInput(name) || "").toLowerCase(); if (!res) { - return false; + return default_value; } return ( @@ -63,7 +63,7 @@ async function run() { const upload_files_pattern = getInputAsArray("file"); const delete_files_pattern = getInputAsArray("delete_file"); const is_overwrite = getInputAsBool("overwrite"); - let is_draft = getInputAsBool("draft"); + let is_draft = getInputAsBool("draft", true); let is_prerelease = getInputAsBool("prerelease"); const with_tags = getInputAsBool("tags"); const with_branches = getInputAsArray("branches"); @@ -235,18 +235,11 @@ async function run() { type FakeListReleaseReponse = AsyncReturnType< typeof octokit.rest.repos.listReleases >; - var deploy_release: - | AsyncReturnType - | AsyncReturnType - | AsyncReturnType - | AsyncReturnType - | { - data: ValueOf, 0>; - status: ValueOf; - headers: ValueOf; - } - | void - | undefined = undefined; + var deploy_release: { + data: ValueOf, 0>; + status: ValueOf; + headers: ValueOf; + } | undefined = undefined; if (update_latest_release) { console.log( @@ -259,14 +252,26 @@ async function run() { console.log( `Try to get latest release from ${target_owner}/${target_repo} : ${error.message}` ); + + return undefined; }); + + if (deploy_release) { + if (is_verbose) { + console.log( + `getLatestRelease and the target release = ${JSON.stringify(deploy_release.data)}` + ); + } + } else if (is_verbose) { + console.log(`Call getLatestRelease but not found`); + } } if (release_id != 0 && !(deploy_release && deploy_release.data)) { console.log( `Try to get release by id ${release_id} from ${target_owner}/${target_repo}` ); - deploy_release = await octokit.rest.repos.getRelease({ + const release_content_by_id = await octokit.rest.repos.getRelease({ owner: target_owner, repo: target_repo, release_id: release_id, @@ -276,19 +281,16 @@ async function run() { action_core.setFailed(message); }); - if (!deploy_release) { - return; - } + if (release_content_by_id) { + deploy_release = release_content_by_id; - release_tag_name = deploy_release.data.tag_name; - if (deploy_release.data.name) { - release_name = deploy_release.data.name; - } - if (isInputEmpty("draft")) { - is_draft = deploy_release.data.draft; - } - if (isInputEmpty("prerelease")) { - is_prerelease = deploy_release.data.prerelease; + if (is_verbose) { + console.log( + `getRelease and the target release = ${JSON.stringify(release_content_by_id.data)}` + ); + } + } else if (is_verbose) { + console.log(`Call getRelease but not found`); } } @@ -297,7 +299,7 @@ async function run() { `Try to get release by tag ${release_tag_name} from ${target_owner}/${target_repo}` ); - deploy_release = await octokit.rest.repos.getReleaseByTag({ + const release_context_by_tag = await octokit.rest.repos.getReleaseByTag({ owner: target_owner, repo: target_repo, tag: release_tag_name, @@ -306,14 +308,26 @@ async function run() { `Try to get release by tag ${release_tag_name} from ${target_owner}/${target_repo} : ${error.message}` ); }); + + if (release_context_by_tag) { + deploy_release = release_context_by_tag; + if (is_verbose) { + console.log( + `getReleaseByTag and the target release = ${JSON.stringify(release_context_by_tag.data)}` + ); + } + } else if (is_verbose) { + console.log(`Call getReleaseByTag but not found`); + } } // We can not get a draft release by getReleaseByTag, so we try to find the draft release with the same name by if (!(deploy_release && deploy_release.data) && release_tag_name_has_ref) { + let try_draft_release: typeof deploy_release; console.log( `Try to get draft release ${release_tag_name} from ${target_owner}/${target_repo}` ); - deploy_release = await octokit.rest.repos.listReleases({ + try_draft_release = await octokit.rest.repos.listReleases({ owner: target_owner, repo: target_repo, page: 1, @@ -337,24 +351,27 @@ async function run() { console.log( `Try to get draft release ${release_tag_name} from ${target_owner}/${target_repo} : ${error.message}` ); + + return undefined; }); - } - if (is_verbose) { - console.log( - "============================= v3 API: getReleaseByTag =============================" - ); - } - if (deploy_release && deploy_release.headers) { - console.log( - `Get release ${release_tag_name} from ${target_owner}/${target_repo} : ${deploy_release.headers.status || ("HTTP Code: " + deploy_release.status)}` - ); - if (is_verbose) { + if (try_draft_release && try_draft_release.headers) { + deploy_release = try_draft_release; console.log( - `getReleaseByTag.data = ${JSON.stringify(deploy_release.data)}` + `Get release ${release_tag_name} from ${target_owner}/${target_repo} : ${deploy_release.headers.status || ("HTTP Code: " + deploy_release.status)}` ); + if (is_verbose) { + console.log( + `listReleases and the target release = ${JSON.stringify(try_draft_release.data)}` + ); + } + } else if (is_verbose) { + console.log(`Call listReleases but no matched release`); } + } + if (deploy_release && deploy_release.data) { + release_tag_name = deploy_release.data.tag_name; if (deploy_release.data.name) { release_name = deploy_release.data.name; }