Skip to content

Commit

Permalink
Update and fixes #39
Browse files Browse the repository at this point in the history
Signed-off-by: owent <[email protected]>
  • Loading branch information
owent committed Nov 9, 2022
1 parent 485c7e1 commit b19e001
Show file tree
Hide file tree
Showing 5 changed files with 445 additions and 409 deletions.
28 changes: 25 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20651,6 +20651,10 @@ function getInputAsBool(name) {
res != "disable");
}
exports.getInputAsBool = getInputAsBool;
function isInputEmpty(name) {
const res = (0, string_env_interpolation_1.env)(action_core.getInput(name) || "").toLowerCase();
return res.trim().length == 0;
}
function getInputAsString(name) {
return (0, string_env_interpolation_1.env)(action_core.getInput(name) || "").trim();
}
Expand All @@ -20673,8 +20677,8 @@ async function run() {
const upload_files_pattern = getInputAsArray("file");
const delete_files_pattern = getInputAsArray("delete_file");
const is_overwrite = getInputAsBool("overwrite");
const is_draft = getInputAsBool("draft");
const is_prerelease = getInputAsBool("prerelease");
let is_draft = getInputAsBool("draft");
let is_prerelease = getInputAsBool("prerelease");
const with_tags = getInputAsBool("tags");
const with_branches = getInputAsArray("branches");
const is_verbose = getInputAsBool("verbose");
Expand Down Expand Up @@ -20790,6 +20794,15 @@ async function run() {
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 (isInputEmpty("prerelease")) {
is_prerelease = deploy_release.data.prerelease;
}
}
if (!(deploy_release && deploy_release.data)) {
console.log(`Try to get release by tag ${release_tag_name} from ${target_owner}/${target_repo}`);
Expand Down Expand Up @@ -20833,6 +20846,15 @@ async function run() {
if (is_verbose) {
console.log(`getReleaseByTag.data = ${JSON.stringify(deploy_release.data)}`);
}
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;
}
}
const pending_to_delete = [];
const pending_to_upload = [];
Expand Down Expand Up @@ -21134,7 +21156,7 @@ async function run() {
// Environment sample
// GITHUB_ACTION=run
// GITHUB_ACTIONS=true
// GITHUB_ACTOR=owt5008137
// GITHUB_ACTOR=owent
// GITHUB_BASE_REF=
// GITHUB_EVENT_NAME=push
// GITHUB_EVENT_PATH=/home/runner/work/_temp/_github_workflow/event.json
Expand Down
28 changes: 25 additions & 3 deletions lib/index.js.map

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

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "upload-to-github-release",
"version": "1.3.7",
"version": "1.3.8",
"description": "Github Action to deploy files to github release",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -34,16 +34,16 @@
"micromatch": "^4.0.5",
"mime": "^3.0.0",
"string-env-interpolation": "^1.0.1",
"type-fest": "^3.1.0"
"type-fest": "^3.2.0"
},
"devDependencies": {
"@types/jest": "^29.2.0",
"@types/node": "^18.11.3",
"@types/jest": "^29.2.2",
"@types/node": "^18.11.9",
"@vercel/ncc": "^0.34.0",
"jest": "^29.2.1",
"jest-circus": "^29.2.1",
"jest": "^29.3.1",
"jest-circus": "^29.3.1",
"ts-jest": "^29.0.3",
"typescript": "^4.8.4",
"npm-check-updates": "^16.3.14"
"npm-check-updates": "^16.3.18"
}
}
91 changes: 23 additions & 68 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ function getInputAsBool(name: string): boolean {
);
}

function isInputEmpty(name: string): boolean {
const res = env(action_core.getInput(name) || "").toLowerCase();
return res.trim().length == 0;
}

function getInputAsString(name: string): string {
return env(action_core.getInput(name) || "").trim();
}
Expand All @@ -58,8 +63,8 @@ async function run() {
const upload_files_pattern = getInputAsArray("file");
const delete_files_pattern = getInputAsArray("delete_file");
const is_overwrite = getInputAsBool("overwrite");
const is_draft = getInputAsBool("draft");
const is_prerelease = getInputAsBool("prerelease");
let is_draft = getInputAsBool("draft");
let is_prerelease = getInputAsBool("prerelease");
const with_tags = getInputAsBool("tags");
const with_branches = getInputAsArray("branches");
const is_verbose = getInputAsBool("verbose");
Expand Down Expand Up @@ -276,6 +281,15 @@ async function run() {
}

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 (!(deploy_release && deploy_release.data)) {
Expand Down Expand Up @@ -340,76 +354,17 @@ async function run() {
`getReleaseByTag.data = ${JSON.stringify(deploy_release.data)}`
);
}
}

/**
// action_github.context.sha will be the tag's commit, it's usual 1 commit above where the tag create from
// This will always cause update tag's commit, which is not what we expect, so we disable to check and update tag here
// Check tag references
var git_tag_ref:
| Octokit.Octokit.Response<Octokit.Octokit.GitGetRefResponse>
| undefined = undefined;
try {
if (is_verbose) {
console.log(
"============================= v3 API: getRef ============================="
);
if (deploy_release.data.name) {
release_name = deploy_release.data.name;
}
console.log(
`Try to get git tags/${release_tag_name} for ${target_owner}/${target_repo}`
);
git_tag_ref = await octokit.git.getRef({
owner: target_owner,
repo: target_repo,
ref: `tags/${release_tag_name}`,
});
console.log(
`Get git tags/${release_tag_name} for ${target_owner}/${target_repo} success: ${git_tag_ref.data.object.sha}`
);
if (is_verbose) {
console.log(`getRef.data = ${JSON.stringify(git_tag_ref.data)}`);
if (isInputEmpty("draft")) {
is_draft = deploy_release.data.draft;
}
} catch (error) {
var msg = `Get git tags/${release_tag_name} for ${target_owner}/${target_repo}: ${error.message}`;
console.log(msg);
}
if (git_tag_ref && git_tag_ref.data) {
if (git_tag_ref.data.object.sha == action_github.context.sha) {
console.log(
`Ignore commit sha of refs/tags/${release_tag_name} because not changed.`
);
} else {
try {
if (is_verbose) {
console.log(
"============================= v3 API: updateRef ============================="
);
}
console.log(
`Try to update git refs/tags/${release_tag_name} for ${target_owner}/${target_repo} to ${action_github.context.sha}`
);
const res = await octokit.git.updateRef({
owner: target_owner,
repo: target_repo,
ref: `tags/${release_tag_name}`,
sha: action_github.context.sha,
force: true,
});
console.log(
`Update refs/tags/${release_tag_name} for ${target_owner}/${target_repo} success`
);
if (is_verbose) {
console.log(`updateRef.data = ${JSON.stringify(res.data)}`);
}
} catch (error) {
var msg = `Update git refs/tags/${release_tag_name} for ${target_owner}/${target_repo} failed: ${error.message}`;
msg += `\r\n${error.stack}`;
console.log(msg);
}
if (isInputEmpty("prerelease")) {
is_prerelease = deploy_release.data.prerelease;
}
}
**/

type AssertArrayType =
| ValueOf<ValueOf<ValueOf<FakeListReleaseReponse, "data">, 0>, "assets">
Expand Down Expand Up @@ -799,7 +754,7 @@ async function run() {
// Environment sample
// GITHUB_ACTION=run
// GITHUB_ACTIONS=true
// GITHUB_ACTOR=owt5008137
// GITHUB_ACTOR=owent
// GITHUB_BASE_REF=
// GITHUB_EVENT_NAME=push
// GITHUB_EVENT_PATH=/home/runner/work/_temp/_github_workflow/event.json
Expand Down
Loading

0 comments on commit b19e001

Please sign in to comment.