Skip to content

Commit

Permalink
Find draft release in all mode.
Browse files Browse the repository at this point in the history
Signed-off-by: WenTao Ou <[email protected]>
  • Loading branch information
owent committed Feb 12, 2023
1 parent fee74e6 commit 05116ac
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ inputs:
description: "Set target repository(default: current repository)."
required: false
default: ""
find_draft_release_count:
description: "How many releases to check when we find a existing draft release.(default: 32)."
required: false
default: "32"

outputs:
release_id:
Expand Down
8 changes: 3 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20689,6 +20689,7 @@ async function run() {
var release_id = getInputAsInteger("release_id");
var target_owner = getInputAsString("target_owner");
var target_repo = getInputAsString("target_owner");
const find_draft_release_count = getInputAsInteger("find_draft_release_count") || 32;
if (typeof github_token != "string") {
action_core.setFailed("token is invalid");
return;
Expand All @@ -20713,10 +20714,8 @@ async function run() {
// action_github.context.repo.owner = xresloader
var release_tag_name = "Release-" + action_github.context.sha.substring(0, 8);
var release_name = release_tag_name;
var release_tag_name_has_ref = false;
if (custom_tag_name) {
release_tag_name = custom_tag_name;
release_tag_name_has_ref = true;
}
else if ((with_branches && with_branches.length > 0) || with_tags) {
// check branches or tags
Expand All @@ -20725,7 +20724,6 @@ async function run() {
const match_tag = action_github.context.ref.match(/refs\/tags\/(.*)/);
if (match_tag) {
match_filter = true;
release_tag_name_has_ref = true;
release_tag_name = match_tag[1];
console.log(`Found tag to push: ${match_tag[1]}.`);
}
Expand Down Expand Up @@ -20841,14 +20839,14 @@ async function run() {
}
}
// 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) {
if (!(deploy_release && deploy_release.data)) {
let try_draft_release;
console.log(`Try to get draft release ${release_tag_name} from ${target_owner}/${target_repo}`);
try_draft_release = await octokit.rest.repos.listReleases({
owner: target_owner,
repo: target_repo,
page: 1,
per_page: 100,
per_page: find_draft_release_count,
}).then((rsp) => {
for (const release of rsp.data || []) {
if (release.name == release_tag_name ||
Expand Down
8 changes: 3 additions & 5 deletions lib/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ async function run() {
var release_id = getInputAsInteger("release_id");
var target_owner = getInputAsString("target_owner");
var target_repo = getInputAsString("target_owner");
const find_draft_release_count = getInputAsInteger("find_draft_release_count") || 32;

if (typeof github_token != "string") {
action_core.setFailed("token is invalid");
Expand Down Expand Up @@ -104,18 +105,15 @@ async function run() {

var release_tag_name = "Release-" + action_github.context.sha.substring(0, 8);
var release_name = release_tag_name;
var release_tag_name_has_ref = false;
if (custom_tag_name) {
release_tag_name = custom_tag_name;
release_tag_name_has_ref = true;
} else if ((with_branches && with_branches.length > 0) || with_tags) {
// check branches or tags
var match_filter = false;
if (with_tags) {
const match_tag = action_github.context.ref.match(/refs\/tags\/(.*)/);
if (match_tag) {
match_filter = true;
release_tag_name_has_ref = true;
release_tag_name = match_tag[1];
console.log(`Found tag to push: ${match_tag[1]}.`);
} else {
Expand Down Expand Up @@ -335,7 +333,7 @@ async function run() {
}

// 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) {
if (!(deploy_release && deploy_release.data)) {
let try_draft_release: typeof deploy_release;
console.log(
`Try to get draft release ${release_tag_name} from ${target_owner}/${target_repo}`
Expand All @@ -344,7 +342,7 @@ async function run() {
owner: target_owner,
repo: target_repo,
page: 1,
per_page: 100,
per_page: find_draft_release_count,
}).then((rsp) => {
for (const release of rsp.data || []) {
if (
Expand Down

0 comments on commit 05116ac

Please sign in to comment.