init auto release project
This commit is contained in:
parent
2078da51c7
commit
28e5c163bf
@ -10,6 +10,9 @@ inputs:
|
|||||||
default: ${{ gitea.repository }}
|
default: ${{ gitea.repository }}
|
||||||
token:
|
token:
|
||||||
description: "Gitea token to create a release"
|
description: "Gitea token to create a release"
|
||||||
|
initial-version:
|
||||||
|
description: "Initial version to start from"
|
||||||
|
default: "v0.0.0"
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: node20
|
using: node20
|
||||||
|
@ -2,6 +2,8 @@ import core from "@actions/core";
|
|||||||
|
|
||||||
import gitea from "gitea-api";
|
import gitea from "gitea-api";
|
||||||
|
|
||||||
|
import type { Release } from "gitea-api/dist/models/release";
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
const host = core.getInput("host");
|
const host = core.getInput("host");
|
||||||
@ -16,38 +18,14 @@ async function run() {
|
|||||||
TOKEN: token,
|
TOKEN: token,
|
||||||
});
|
});
|
||||||
|
|
||||||
let release = await client.repository.repoGetReleaseByTag({
|
let releases = await client.repository.repoListReleases({
|
||||||
owner: owner,
|
owner,
|
||||||
repo: repo,
|
repo,
|
||||||
tag: body.tag_name,
|
|
||||||
});
|
|
||||||
const release_id = release.id;
|
|
||||||
let target_commitish = release.target_commitish;
|
|
||||||
if (
|
|
||||||
body.target_commitish &&
|
|
||||||
body.target_commitish !== release.target_commitish
|
|
||||||
) {
|
|
||||||
console.log(
|
|
||||||
`Updating commit from "${release.target_commitish}" to "${body.target_commitish}"`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
target_commitish = body.target_commitish;
|
|
||||||
release = client.repository.repoEditRelease({
|
|
||||||
owner: owner,
|
|
||||||
repo: repo,
|
|
||||||
id: release_id,
|
|
||||||
body: {
|
|
||||||
body: body.body || release.body,
|
|
||||||
draft: body.draft !== undefined ? body.draft : release.draft,
|
|
||||||
name: body.name || release.name,
|
|
||||||
prerelease:
|
|
||||||
body.prerelease !== undefined ? body.prerelease : release.prerelease,
|
|
||||||
tag_name: body.tag_name || release.tag_name,
|
|
||||||
target_commitish: target_commitish,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`TEST ${host} ${token} ${repository} ${owner} ${repo}`);
|
let newVersion = getNewestRelease(releases);
|
||||||
|
|
||||||
|
console.log(`NEW RELEASE ${newVersion}`);
|
||||||
// console.log(`🎉 Release ready at ${response.html_url}`);
|
// console.log(`🎉 Release ready at ${response.html_url}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
@ -55,4 +33,37 @@ async function run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {Release[]} releases
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
async function getNewestRelease(releases) {
|
||||||
|
const initialVersion = core.getInput("initial-version");
|
||||||
|
|
||||||
|
const semVerParser = ([major, minor, patch]) => {
|
||||||
|
return version.replace("v", "").split(".").map(parseFloat);
|
||||||
|
};
|
||||||
|
|
||||||
|
const isSemVerGreater = (a, b) => {
|
||||||
|
return (
|
||||||
|
a[0] > b[0] ||
|
||||||
|
(a[0] === b[0] && a[1] > b[1]) ||
|
||||||
|
(a[0] === b[0] && a[1] === b[1] && a[2] > b[2])
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
let version = semVerParser(initialVersion);
|
||||||
|
|
||||||
|
for (let release of releases) {
|
||||||
|
let releaseVersion = semVerParser(release.tag_name);
|
||||||
|
|
||||||
|
if (isSemVerGreater(releaseVersion, version)) {
|
||||||
|
version = releaseVersion;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return `v${version[0]}.${version[1]}.${version[2] + 1}`;
|
||||||
|
}
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user