You've already forked gitea-release-action
mirror of
https://gitea.com/actions/gitea-release-action.git
synced 2025-07-17 07:50:27 +07:00
Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
69c9a2be62 | |||
e672383659 | |||
91415bf0a8 | |||
f6b3ef8321 | |||
3ac6d530d3 | |||
a21af5d066 | |||
1050fbf050 | |||
3494e663be | |||
e458649bef | |||
ce62ea769e | |||
5951579e82 | |||
74c59ef00c | |||
d2833c6905 | |||
1def5c9f21 | |||
0a1d8705a2 | |||
1652635ed8 | |||
1e8f8cc30e | |||
9ed6f482bf |
33
.github/workflows/publish.yml
vendored
Normal file
33
.github/workflows/publish.yml
vendored
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
name: Update Main Version
|
||||||
|
run-name: Move ${{ github.event.inputs.major_version }} to ${{ github.event.inputs.target }}
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
target:
|
||||||
|
description: The tag or reference to use
|
||||||
|
required: true
|
||||||
|
major_version:
|
||||||
|
type: choice
|
||||||
|
description: The major version to update
|
||||||
|
options:
|
||||||
|
- v1
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
tag:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Git config
|
||||||
|
run: |
|
||||||
|
git config user.name github-actions
|
||||||
|
git config user.email github-actions@github.com
|
||||||
|
- name: Tag new target
|
||||||
|
run: git tag -f ${{ github.event.inputs.major_version }} ${{ github.event.inputs.target }}
|
||||||
|
- name: Push new tag
|
||||||
|
run: git push origin ${{ github.event.inputs.major_version }} --force
|
22
LICENSE
Normal file
22
LICENSE
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2023 The Gitea Authors
|
||||||
|
Copyright (c) 2023 akkuman
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
27
README.md
27
README.md
@ -6,23 +6,24 @@ 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
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
uses: akkuman/gitea-release-action@v1.0.0
|
uses: akkuman/gitea-release-action@v1
|
||||||
env:
|
env:
|
||||||
NODE_OPTIONS: '--experimental-fetch' # if nodejs < 18
|
NODE_OPTIONS: '--experimental-fetch' # if nodejs < 18
|
||||||
with:
|
with:
|
||||||
|
@ -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"
|
||||||
|
64
dist/index.js
vendored
64
dist/index.js
vendored
@ -40898,13 +40898,14 @@ async function run() {
|
|||||||
try {
|
try {
|
||||||
const server_url = core.getInput("server_url")
|
const server_url = core.getInput("server_url")
|
||||||
const name = core.getInput("name")
|
const name = core.getInput("name")
|
||||||
const body = core.getInput("body")
|
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 = Boolean(core.getInput("draft"))
|
const draft = Boolean(core.getInput("draft"))
|
||||||
const prerelease = Boolean(core.getInput("prerelease"))
|
const prerelease = Boolean(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 [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,
|
||||||
@ -40971,7 +40997,7 @@ async function createOrGetRelease(client, owner, repo, body) {
|
|||||||
function paths(patterns) {
|
function paths(patterns) {
|
||||||
return patterns.reduce((acc, pattern) => {
|
return patterns.reduce((acc, pattern) => {
|
||||||
return acc.concat(
|
return acc.concat(
|
||||||
sync(pattern).filter((path) => statSync(path).isFile())
|
sync(pattern).filter((path) => external_fs_.statSync(path).isFile())
|
||||||
);
|
);
|
||||||
}, []);
|
}, []);
|
||||||
};
|
};
|
||||||
@ -40990,32 +41016,38 @@ async function uploadFiles(client, owner, repo, release_id, all_files) {
|
|||||||
repo: repo,
|
repo: repo,
|
||||||
id: release_id,
|
id: release_id,
|
||||||
})
|
})
|
||||||
for (const filepath in all_files) {
|
for (const filepath of all_files) {
|
||||||
for (const attachment in attachments) {
|
for (const attachment of attachments) {
|
||||||
if (attachment.name === external_path_.basename(filepath)) {
|
if (attachment.name === external_path_.basename(filepath)) {
|
||||||
await client.repository.repoDeleteReleaseAttachment({
|
await client.repository.repoDeleteReleaseAttachment({
|
||||||
owner: owner,
|
owner: owner,
|
||||||
repo: repo,
|
repo: repo,
|
||||||
id: id,
|
id: release_id,
|
||||||
attachmentId: attachment.id,
|
attachmentId: attachment.id,
|
||||||
})
|
})
|
||||||
console.log(`Successfully deleted old release attachment ${attachment.name}`)
|
console.log(`Successfully deleted old release attachment ${attachment.name}`)
|
||||||
}
|
}
|
||||||
const content = external_fs_.readFileSync(filepath);
|
|
||||||
const blob = new external_buffer_.Blob([content]);
|
|
||||||
await client.repository.repoCreateReleaseAttachment({
|
|
||||||
owner: owner,
|
|
||||||
repo: repo,
|
|
||||||
id: release_id,
|
|
||||||
attachment: blob,
|
|
||||||
name: external_path_.basename(filepath),
|
|
||||||
})
|
|
||||||
console.log(`Successfully uploaded release attachment ${filepath}`)
|
|
||||||
}
|
}
|
||||||
|
const content = external_fs_.readFileSync(filepath);
|
||||||
|
const blob = new external_buffer_.Blob([content]);
|
||||||
|
await client.repository.repoCreateReleaseAttachment({
|
||||||
|
owner: owner,
|
||||||
|
repo: repo,
|
||||||
|
id: release_id,
|
||||||
|
attachment: blob,
|
||||||
|
name: external_path_.basename(filepath),
|
||||||
|
})
|
||||||
|
console.log(`Successfully uploaded release attachment ${filepath}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
run();
|
function getReleaseBody(body, body_path) {
|
||||||
|
return (
|
||||||
|
(body_path && external_fs_.readFileSync(body_path).toString("utf8")) || body
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
run()
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
64
main.js
64
main.js
@ -11,13 +11,14 @@ async function run() {
|
|||||||
try {
|
try {
|
||||||
const server_url = core.getInput("server_url")
|
const server_url = core.getInput("server_url")
|
||||||
const name = core.getInput("name")
|
const name = core.getInput("name")
|
||||||
const body = core.getInput("body")
|
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 = Boolean(core.getInput("draft"))
|
const draft = Boolean(core.getInput("draft"))
|
||||||
const prerelease = Boolean(core.getInput("prerelease"))
|
const prerelease = Boolean(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 [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,
|
||||||
@ -84,7 +110,7 @@ async function createOrGetRelease(client, owner, repo, body) {
|
|||||||
function paths(patterns) {
|
function paths(patterns) {
|
||||||
return patterns.reduce((acc, pattern) => {
|
return patterns.reduce((acc, pattern) => {
|
||||||
return acc.concat(
|
return acc.concat(
|
||||||
glob.sync(pattern).filter((path) => statSync(path).isFile())
|
glob.sync(pattern).filter((path) => fs.statSync(path).isFile())
|
||||||
);
|
);
|
||||||
}, []);
|
}, []);
|
||||||
};
|
};
|
||||||
@ -103,29 +129,35 @@ async function uploadFiles(client, owner, repo, release_id, all_files) {
|
|||||||
repo: repo,
|
repo: repo,
|
||||||
id: release_id,
|
id: release_id,
|
||||||
})
|
})
|
||||||
for (const filepath in all_files) {
|
for (const filepath of all_files) {
|
||||||
for (const attachment in attachments) {
|
for (const attachment of attachments) {
|
||||||
if (attachment.name === path.basename(filepath)) {
|
if (attachment.name === path.basename(filepath)) {
|
||||||
await client.repository.repoDeleteReleaseAttachment({
|
await client.repository.repoDeleteReleaseAttachment({
|
||||||
owner: owner,
|
owner: owner,
|
||||||
repo: repo,
|
repo: repo,
|
||||||
id: id,
|
id: release_id,
|
||||||
attachmentId: attachment.id,
|
attachmentId: attachment.id,
|
||||||
})
|
})
|
||||||
console.log(`Successfully deleted old release attachment ${attachment.name}`)
|
console.log(`Successfully deleted old release attachment ${attachment.name}`)
|
||||||
}
|
}
|
||||||
const content = fs.readFileSync(filepath);
|
|
||||||
const blob = new Blob([content]);
|
|
||||||
await client.repository.repoCreateReleaseAttachment({
|
|
||||||
owner: owner,
|
|
||||||
repo: repo,
|
|
||||||
id: release_id,
|
|
||||||
attachment: blob,
|
|
||||||
name: path.basename(filepath),
|
|
||||||
})
|
|
||||||
console.log(`Successfully uploaded release attachment ${filepath}`)
|
|
||||||
}
|
}
|
||||||
|
const content = fs.readFileSync(filepath);
|
||||||
|
const blob = new Blob([content]);
|
||||||
|
await client.repository.repoCreateReleaseAttachment({
|
||||||
|
owner: owner,
|
||||||
|
repo: repo,
|
||||||
|
id: release_id,
|
||||||
|
attachment: blob,
|
||||||
|
name: path.basename(filepath),
|
||||||
|
})
|
||||||
|
console.log(`Successfully uploaded release attachment ${filepath}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
run();
|
function getReleaseBody(body, body_path) {
|
||||||
|
return (
|
||||||
|
(body_path && fs.readFileSync(body_path).toString("utf8")) || body
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
run()
|
||||||
|
Reference in New Issue
Block a user