feat: support md5sum and sha256

https://gitea.com/actions/gitea-release-action/issues/2
This commit is contained in:
Akkuman 2024-02-21 17:31:04 +08:00
parent 0611a9a1a0
commit 1ab8e7176e
6 changed files with 7342 additions and 10 deletions

View File

@ -12,13 +12,15 @@ The following are optional as `step.with` keys
| `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. Defaults to false |
| `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. | | `target_commitish` | String | Commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. |
| `md5sum` | Boolean | Publish .md5 along with artifacts, Defaults to false |
| `sha256sum` | Boolean | Publish .md5 along with artifacts, Defaults to false |
## Example usage ## Example usage
@ -38,3 +40,4 @@ If you want to ignore ssl verify error, you can set env `NODE_TLS_REJECT_UNAUTHO
- [softprops/action-gh-release: 📦 GitHub Action for creating GitHub Releases](https://github.com/softprops/action-gh-release) - [softprops/action-gh-release: 📦 GitHub Action for creating GitHub Releases](https://github.com/softprops/action-gh-release)
- [sigyl-actions/gitea-action-release-asset](https://github.com/sigyl-actions/gitea-action-release-asset) - [sigyl-actions/gitea-action-release-asset](https://github.com/sigyl-actions/gitea-action-release-asset)
- [actions/release-action: An action written by Golang to support publishing release to Gitea(not Github Actions compatible) - release-action - Gitea: Git with a cup of tea](https://gitea.com/actions/release-action) - [actions/release-action: An action written by Golang to support publishing release to Gitea(not Github Actions compatible) - release-action - Gitea: Git with a cup of tea](https://gitea.com/actions/release-action)
- [wangyoucao577/go-release-action: Automatically publish Go binaries to Github Release Assets through Github Action.](https://github.com/wangyoucao577/go-release-action)

View File

@ -38,6 +38,12 @@ inputs:
target_commitish: target_commitish:
description: 'Commitish value that determines where the Git tag is created from. Can be any branch or commit SHA.' description: 'Commitish value that determines where the Git tag is created from. Can be any branch or commit SHA.'
required: false required: false
md5sum:
description: 'Publish `.md5` along with artifacts.'
required: false
sha256sum:
description: 'Publish `.sha256` along with artifacts.'
required: false
runs: runs:
using: "node16" using: "node16"
main: "dist/index.js" main: "dist/index.js"

7290
dist/index.js vendored

File diff suppressed because it is too large Load Diff

41
main.js
View File

@ -6,6 +6,8 @@ import core from "@actions/core";
import gitea from "gitea-api"; import gitea from "gitea-api";
import path from 'path'; import path from 'path';
import CryptoJS from 'crypto-js';
async function run() { async function run() {
try { try {
@ -19,6 +21,8 @@ async function run() {
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 sha256sum = core.getInput("sha256sum")
const [owner, repo] = (repository).split("/") const [owner, repo] = (repository).split("/")
@ -41,7 +45,10 @@ async function run() {
if (all_files.length == 0) { if (all_files.length == 0) {
console.warn(`${file_patterns} not include valid file.`); console.warn(`${file_patterns} not include valid file.`);
} }
await uploadFiles(gitea_client, owner, repo, response.id, all_files) await uploadFiles(gitea_client, owner, repo, response.id, all_files, {
md5sum: md5sum,
sha256sum: sha256sum,
})
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);
@ -123,7 +130,8 @@ function paths(patterns) {
* @param {Number} release_id * @param {Number} release_id
* @param {Array<String>} all_files * @param {Array<String>} all_files
*/ */
async function uploadFiles(client, owner, repo, release_id, all_files) { async function uploadFiles(client, owner, repo, release_id, all_files, params) {
params = params || {};
const attachments = await client.repository.repoListReleaseAttachments({ const attachments = await client.repository.repoListReleaseAttachments({
owner: owner, owner: owner,
repo: repo, repo: repo,
@ -131,7 +139,8 @@ async function uploadFiles(client, owner, repo, release_id, all_files) {
}) })
for (const filepath of all_files) { for (const filepath of all_files) {
for (const attachment of attachments) { for (const attachment of attachments) {
if (attachment.name === path.basename(filepath)) { let will_deleted = [path.basename(filepath), `${path.basename(filepath)}.md5`, `${path.basename(filepath)}.sha256`]
if (will_deleted.includes(attachment.name)) {
await client.repository.repoDeleteReleaseAttachment({ await client.repository.repoDeleteReleaseAttachment({
owner: owner, owner: owner,
repo: repo, repo: repo,
@ -142,7 +151,7 @@ async function uploadFiles(client, owner, repo, release_id, all_files) {
} }
} }
const content = fs.readFileSync(filepath); const content = fs.readFileSync(filepath);
const blob = new Blob([content]); let blob = new Blob([content]);
await client.repository.repoCreateReleaseAttachment({ await client.repository.repoCreateReleaseAttachment({
owner: owner, owner: owner,
repo: repo, repo: repo,
@ -150,6 +159,30 @@ async function uploadFiles(client, owner, repo, release_id, all_files) {
attachment: blob, attachment: blob,
name: path.basename(filepath), name: path.basename(filepath),
}) })
if (params.md5sum) {
let wordArray = CryptoJS.lib.WordArray.create(content);
let hash = CryptoJS.MD5(wordArray).toString();
blob = new Blob([hash], { type : 'plain/text' });
await client.repository.repoCreateReleaseAttachment({
owner: owner,
repo: repo,
id: release_id,
attachment: blob,
name: `${path.basename(filepath)}.md5`,
})
}
if (params.sha256sum) {
let wordArray = CryptoJS.lib.WordArray.create(content);
let hash = CryptoJS.SHA256(wordArray).toString();
blob = new Blob([hash], { type : 'plain/text' });
await client.repository.repoCreateReleaseAttachment({
owner: owner,
repo: repo,
id: release_id,
attachment: blob,
name: `${path.basename(filepath)}.sha256`,
})
}
console.log(`Successfully uploaded release attachment ${filepath}`) console.log(`Successfully uploaded release attachment ${filepath}`)
} }
} }

6
package-lock.json generated
View File

@ -11,6 +11,7 @@
"dependencies": { "dependencies": {
"@actions/core": "^1.10.1", "@actions/core": "^1.10.1",
"@actions/github": "^6.0.0", "@actions/github": "^6.0.0",
"crypto-js": "^4.2.0",
"gitea-api": "^1.17.3-1", "gitea-api": "^1.17.3-1",
"glob": "^10.3.10" "glob": "^10.3.10"
}, },
@ -276,6 +277,11 @@
"node": ">= 8" "node": ">= 8"
} }
}, },
"node_modules/crypto-js": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz",
"integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q=="
},
"node_modules/deprecation": { "node_modules/deprecation": {
"version": "2.3.1", "version": "2.3.1",
"resolved": "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz", "resolved": "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz",

View File

@ -8,7 +8,8 @@
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"package": "ncc build main.js -o dist", "package": "ncc build main.js -o dist",
"build": "ncc build main.js", "build": "ncc build main.js",
"start": "node main.js" "start": "node main.js",
"test111": "node 111.js"
}, },
"keywords": [], "keywords": [],
"author": "", "author": "",
@ -16,6 +17,7 @@
"dependencies": { "dependencies": {
"@actions/core": "^1.10.1", "@actions/core": "^1.10.1",
"@actions/github": "^6.0.0", "@actions/github": "^6.0.0",
"crypto-js": "^4.2.0",
"gitea-api": "^1.17.3-1", "gitea-api": "^1.17.3-1",
"glob": "^10.3.10" "glob": "^10.3.10"
}, },