5 Commits

Author SHA1 Message Date
akkuman
fe8e032280 Merge pull request #7 from n08i40k/main
Declare missing body_path input in action.yml
2025-07-28 09:19:09 +08:00
Nikita
3dbdc45d61 docs: declare body_path input 2025-07-26 14:35:12 +04:00
Akkuman
f66c1c98f1 fix: deletion of old releases
Duplicate deletions occur when users generate their own .md5 and .sha256 files and do not use action's built-in md5sum and sha256sum functions.
issue: https://github.com/akkuman/gitea-release-action/issues/5
2025-06-25 10:53:06 +08:00
Akkuman
65a502e85c fix: delete old release attachments 2025-06-23 15:10:15 +08:00
Akkuman
f119011bd6 fix: bool value parse 2024-05-06 23:15:48 +08:00
3 changed files with 64 additions and 31 deletions

View File

@@ -10,6 +10,9 @@ inputs:
body: body:
description: "Note-worthy description of changes in release" description: "Note-worthy description of changes in release"
required: false required: false
body_path:
description: "Path to load description of changes in this release"
required: false
name: name:
description: "Gives the release a custom name. Defaults to tag name" description: "Gives the release a custom name. Defaults to tag name"
required: false required: false

27
dist/index.js vendored
View File

@@ -48144,6 +48144,10 @@ var crypto_js = __nccwpck_require__(4134);
function getIsTrue(v) {
const trueValue = ['true', 'True', 'TRUE']
return trueValue.includes(v)
}
async function run() { async function run() {
try { try {
@@ -48151,14 +48155,14 @@ async function run() {
const name = core.getInput("name") const name = core.getInput("name")
const body = getReleaseBody(core.getInput("body"), core.getInput("body_path")) const body = getReleaseBody(core.getInput("body"), core.getInput("body_path"))
const tag_name = core.getInput("tag_name") const tag_name = core.getInput("tag_name")
const draft = core.getInput("draft") === 'true' const draft = getIsTrue(core.getInput("draft"))
const prerelease = core.getInput("prerelease") === 'true' const prerelease = getIsTrue(core.getInput("prerelease"))
const files = core.getInput("files") const files = core.getInput("files")
const repository = core.getInput("repository") const repository = core.getInput("repository")
const token = core.getInput("token") const token = core.getInput("token")
const target_commitish = core.getInput("target_commitish") const target_commitish = core.getInput("target_commitish")
const md5sum = core.getInput("md5sum") const md5sum = getIsTrue(core.getInput("md5sum"))
const sha256sum = core.getInput("sha256sum") const sha256sum = getIsTrue(core.getInput("sha256sum"))
const [owner, repo] = (repository).split("/") const [owner, repo] = (repository).split("/")
@@ -48274,10 +48278,19 @@ async function uploadFiles(client, owner, repo, release_id, all_files, params) {
repo: repo, repo: repo,
id: release_id, id: release_id,
}) })
// deleted old release attachment
const will_deleted = new Set();
for (const filepath of all_files) { for (const filepath of all_files) {
will_deleted.add(external_path_.basename(filepath));
if (params.md5sum) {
will_deleted.add(`${external_path_.basename(filepath)}.md5`);
}
if (params.sha256sum) {
will_deleted.add(`${external_path_.basename(filepath)}.sha256`);
}
}
for (const attachment of attachments) { for (const attachment of attachments) {
let will_deleted = [external_path_.basename(filepath), `${external_path_.basename(filepath)}.md5`, `${external_path_.basename(filepath)}.sha256`] if (will_deleted.has(attachment.name)) {
if (will_deleted.includes(attachment.name)) {
await client.repository.repoDeleteReleaseAttachment({ await client.repository.repoDeleteReleaseAttachment({
owner: owner, owner: owner,
repo: repo, repo: repo,
@@ -48287,6 +48300,8 @@ async function uploadFiles(client, owner, repo, release_id, all_files, params) {
console.log(`Successfully deleted old release attachment ${attachment.name}`) console.log(`Successfully deleted old release attachment ${attachment.name}`)
} }
} }
// upload new release attachment
for (const filepath of all_files) {
const content = external_fs_.readFileSync(filepath); const content = external_fs_.readFileSync(filepath);
let blob = new external_buffer_.Blob([content]); let blob = new external_buffer_.Blob([content]);
await client.repository.repoCreateReleaseAttachment({ await client.repository.repoCreateReleaseAttachment({

27
main.js
View File

@@ -8,6 +8,10 @@ import gitea from "gitea-api";
import path from 'path'; import path from 'path';
import CryptoJS from 'crypto-js'; import CryptoJS from 'crypto-js';
function getIsTrue(v) {
const trueValue = ['true', 'True', 'TRUE']
return trueValue.includes(v)
}
async function run() { async function run() {
try { try {
@@ -15,14 +19,14 @@ async function run() {
const name = core.getInput("name") const name = core.getInput("name")
const body = getReleaseBody(core.getInput("body"), core.getInput("body_path")) const body = getReleaseBody(core.getInput("body"), core.getInput("body_path"))
const tag_name = core.getInput("tag_name") const tag_name = core.getInput("tag_name")
const draft = core.getInput("draft") === 'true' const draft = getIsTrue(core.getInput("draft"))
const prerelease = core.getInput("prerelease") === 'true' const prerelease = getIsTrue(core.getInput("prerelease"))
const files = core.getInput("files") const files = core.getInput("files")
const repository = core.getInput("repository") const repository = core.getInput("repository")
const token = core.getInput("token") const token = core.getInput("token")
const target_commitish = core.getInput("target_commitish") const target_commitish = core.getInput("target_commitish")
const md5sum = core.getInput("md5sum") const md5sum = getIsTrue(core.getInput("md5sum"))
const sha256sum = core.getInput("sha256sum") const sha256sum = getIsTrue(core.getInput("sha256sum"))
const [owner, repo] = (repository).split("/") const [owner, repo] = (repository).split("/")
@@ -138,10 +142,19 @@ async function uploadFiles(client, owner, repo, release_id, all_files, params) {
repo: repo, repo: repo,
id: release_id, id: release_id,
}) })
// deleted old release attachment
const will_deleted = new Set();
for (const filepath of all_files) { for (const filepath of all_files) {
will_deleted.add(path.basename(filepath));
if (params.md5sum) {
will_deleted.add(`${path.basename(filepath)}.md5`);
}
if (params.sha256sum) {
will_deleted.add(`${path.basename(filepath)}.sha256`);
}
}
for (const attachment of attachments) { for (const attachment of attachments) {
let will_deleted = [path.basename(filepath), `${path.basename(filepath)}.md5`, `${path.basename(filepath)}.sha256`] if (will_deleted.has(attachment.name)) {
if (will_deleted.includes(attachment.name)) {
await client.repository.repoDeleteReleaseAttachment({ await client.repository.repoDeleteReleaseAttachment({
owner: owner, owner: owner,
repo: repo, repo: repo,
@@ -151,6 +164,8 @@ async function uploadFiles(client, owner, repo, release_id, all_files, params) {
console.log(`Successfully deleted old release attachment ${attachment.name}`) console.log(`Successfully deleted old release attachment ${attachment.name}`)
} }
} }
// upload new release attachment
for (const filepath of all_files) {
const content = fs.readFileSync(filepath); const content = fs.readFileSync(filepath);
let blob = new Blob([content]); let blob = new Blob([content]);
await client.repository.repoCreateReleaseAttachment({ await client.repository.repoCreateReleaseAttachment({