Akkuman 2024-02-21 16:30:15 +08:00
parent 3ac6d530d3
commit e672383659
4 changed files with 68 additions and 12 deletions

View File

@ -6,18 +6,19 @@ An action to support publishing release to Gitea.
The following are optional as `step.with` keys The following are optional as `step.with` keys
| Name | Type | Description | | Name | Type | Description |
| -------------- | ------- | ------------------------------------------------------------------------------------------- | | ------------------ | ------- | --------------------------------------------------------------------------------------------------- |
| `server_url` | String | the base url of the gitea API. Defaults to `github.server_url` | | `server_url` | String | the base url of the gitea API. Defaults to `github.server_url` |
| `body` | String | Text communicating notable changes in this release | | `body` | String | Text communicating notable changes in this release |
| `body_path` | String | Path to load text communicating notable changes in this release | | `body_path` | String | Path to load text communicating notable changes in this release |
| `draft` | Boolean | Creates a draft release. Defaults to false | | `draft` | Boolean | Creates a draft release. Defaults to false |
| `prerelease` | Boolean | Indicator of whether or not is a prerelease | | `prerelease` | Boolean | Indicator of whether or not is a prerelease |
| `files` | String | Newline-delimited globs of paths to assets to upload for release | | `files` | String | Newline-delimited globs of paths to assets to upload for release |
| `name` | String | Name of the release. Defaults to tag name | | `name` | String | Name of the release. Defaults to tag name |
| `tag_name` | String | Name of a tag. Defaults to `github.ref_name` | | `tag_name` | String | Name of a tag. Defaults to `github.ref_name` |
| `repository` | String | Name of a target repository in `<owner>/<repo>` format. Defaults to `github.repository` | | `repository` | String | Name of a target repository in `<owner>/<repo>` format. Defaults to `github.repository` |
| `token` | String | Gitea Token. Defaults to `${{ github.token }}` | | `token` | String | Gitea Token. Defaults to `${{ github.token }}` |
| `target_commitish` | String | Commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. |
## Example usage ## Example usage

View File

@ -35,6 +35,9 @@ inputs:
description: "Gitea Token" description: "Gitea Token"
required: false required: false
default: ${{ github.token }} default: ${{ github.token }}
target_commitish:
description: 'Commitish value that determines where the Git tag is created from. Can be any branch or commit SHA.'
required: false
runs: runs:
using: "node16" using: "node16"
main: "dist/index.js" main: "dist/index.js"

26
dist/index.js vendored
View File

@ -40905,6 +40905,7 @@ async function run() {
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 [owner, repo] = (repository).split("/") const [owner, repo] = (repository).split("/")
@ -40920,6 +40921,7 @@ async function run() {
name: name, name: name,
prerelease: prerelease, prerelease: prerelease,
tag_name: tag_name, tag_name: tag_name,
target_commitish: target_commitish,
}) })
const file_patterns = files.split('\n') const file_patterns = files.split('\n')
const all_files = paths(file_patterns); const all_files = paths(file_patterns);
@ -40949,12 +40951,36 @@ async function createOrGetRelease(client, owner, repo, body) {
repo: repo, repo: repo,
tag: body.tag_name, 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: body.target_commitish || release.target_commitish,
}
})
return release return release
} catch (error) { } catch (error) {
if (!(error instanceof dist/* ApiError */.MS) || error.status !== 404) { if (!(error instanceof dist/* ApiError */.MS) || error.status !== 404) {
throw error throw error
} }
} }
let commit_message = "";
if (body.target_commitish) {
commit_message = ` using commit "${body.target_commitish}"`;
}
console.log(`👩‍🏭 Creating new GitHub release for tag ${body.tag_name}${commit_message}...`);
let release = await client.repository.repoCreateRelease({ let release = await client.repository.repoCreateRelease({
owner: owner, owner: owner,
repo: repo, repo: repo,

26
main.js
View File

@ -18,6 +18,7 @@ async function run() {
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 [owner, repo] = (repository).split("/") const [owner, repo] = (repository).split("/")
@ -33,6 +34,7 @@ async function run() {
name: name, name: name,
prerelease: prerelease, prerelease: prerelease,
tag_name: tag_name, tag_name: tag_name,
target_commitish: target_commitish,
}) })
const file_patterns = files.split('\n') const file_patterns = files.split('\n')
const all_files = paths(file_patterns); const all_files = paths(file_patterns);
@ -62,12 +64,36 @@ async function createOrGetRelease(client, owner, repo, body) {
repo: repo, repo: repo,
tag: body.tag_name, 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: body.target_commitish || release.target_commitish,
}
})
return release return release
} catch (error) { } catch (error) {
if (!(error instanceof gitea.ApiError) || error.status !== 404) { if (!(error instanceof gitea.ApiError) || error.status !== 404) {
throw error throw error
} }
} }
let commit_message = "";
if (body.target_commitish) {
commit_message = ` using commit "${body.target_commitish}"`;
}
console.log(`👩‍🏭 Creating new GitHub release for tag ${body.tag_name}${commit_message}...`);
let release = await client.repository.repoCreateRelease({ let release = await client.repository.repoCreateRelease({
owner: owner, owner: owner,
repo: repo, repo: repo,