Compare commits

..

No commits in common. "main" and "v1.1.4" have entirely different histories.
main ... v1.1.4

8 changed files with 56 additions and 7472 deletions

View File

@ -1,33 +1,37 @@
name: Update Main Version
run-name: Move ${{ github.event.inputs.major_version }} to ${{ github.event.inputs.target }}
name: Build and Publish
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
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
jobs:
tag:
build:
runs-on: ubuntu-latest
name: 构建
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
- name: Checkout
uses: actions/checkout@v4
with:
ref: 'main'
- uses: actions/setup-node@v4
with:
node-version: 16
cache: 'npm'
cache-dependency-path: package-lock.json
- run: npm install -D
- run: npm run package
- run: |
git config user.name github-actions
git config user.email github-actions@github.com
- run: |
git add .
git commit -m "Auto Build"
- id: get_version
uses: battila7/get-version-action@v2
- run: git tag -f "v${{ steps.get_version.outputs.major }}"
- run: git push
- run: git push --tags -f

22
LICENSE
View File

@ -1,22 +0,0 @@
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.

View File

@ -6,21 +6,18 @@ An action to support publishing release to Gitea.
The following are optional as `step.with` keys
| Name | Type | Description |
| ------------------ | ------- | --------------------------------------------------------------------------------------------------- |
| `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_path` | String | Path to load text communicating notable changes in this release |
| `draft` | Boolean | Creates a draft release. Defaults to false |
| `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 |
| `name` | String | Name of the release. Defaults to tag 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` |
| `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. |
| `md5sum` | Boolean | Publish .md5 along with artifacts, Defaults to false |
| `sha256sum` | Boolean | Publish .md5 along with artifacts, Defaults to false |
| Name | Type | Description |
| -------------- | ------- | ------------------------------------------------------------------------------------------- |
| `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_path` | String | Path to load text communicating notable changes in this release |
| `draft` | Boolean | Creates a draft release. Defaults to false |
| `prerelease` | Boolean | Indicator of whether or not is a prerelease |
| `files` | String | Newline-delimited globs of paths to assets to upload for release |
| `name` | String | Name of the release. Defaults to tag 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` |
| `token` | String | Gitea Token. Defaults to `${{ github.token }}` |
## Example usage
@ -40,4 +37,3 @@ 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)
- [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)
- [wangyoucao577/go-release-action: Automatically publish Go binaries to Github Release Assets through Github Action.](https://github.com/wangyoucao577/go-release-action)

View File

@ -35,15 +35,6 @@ inputs:
description: "Gitea Token"
required: false
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
md5sum:
description: 'Publish `.md5` along with artifacts.'
required: false
sha256sum:
description: 'Publish `.sha256` along with artifacts.'
required: false
runs:
using: "node16"
main: "dist/index.js"

7327
dist/index.js vendored

File diff suppressed because it is too large Load Diff

80
main.js
View File

@ -5,13 +5,7 @@ import * as glob from "glob";
import core from "@actions/core";
import gitea from "gitea-api";
import path from 'path';
import CryptoJS from 'crypto-js';
function getIsTrue(v) {
const trueValue = ['true', 'True', 'TRUE']
return trueValue.includes(v)
}
import path from 'path'
async function run() {
try {
@ -19,14 +13,11 @@ async function run() {
const name = core.getInput("name")
const body = getReleaseBody(core.getInput("body"), core.getInput("body_path"))
const tag_name = core.getInput("tag_name")
const draft = getIsTrue(core.getInput("draft"))
const prerelease = getIsTrue(core.getInput("prerelease"))
const draft = Boolean(core.getInput("draft"))
const prerelease = Boolean(core.getInput("prerelease"))
const files = core.getInput("files")
const repository = core.getInput("repository")
const token = core.getInput("token")
const target_commitish = core.getInput("target_commitish")
const md5sum = getIsTrue(core.getInput("md5sum"))
const sha256sum = getIsTrue(core.getInput("sha256sum"))
const [owner, repo] = (repository).split("/")
@ -42,17 +33,13 @@ async function run() {
name: name,
prerelease: prerelease,
tag_name: tag_name,
target_commitish: target_commitish,
})
const file_patterns = files.split('\n')
const all_files = paths(file_patterns);
if (all_files.length == 0) {
console.warn(`${file_patterns} not include valid file.`);
}
await uploadFiles(gitea_client, owner, repo, response.id, all_files, {
md5sum: md5sum,
sha256sum: sha256sum,
})
await uploadFiles(gitea_client, owner, repo, response.id, all_files)
console.log(`🎉 Release ready at ${response.html_url}`);
} catch (error) {
console.log(error);
@ -75,36 +62,12 @@ async function createOrGetRelease(client, owner, repo, body) {
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,
}
})
return release
} catch (error) {
if (!(error instanceof gitea.ApiError) || error.status !== 404) {
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({
owner: owner,
repo: repo,
@ -133,10 +96,8 @@ function paths(patterns) {
* @param {String} repo
* @param {Number} release_id
* @param {Array<String>} all_files
* @param {Map<String, Any>} additional parameters
*/
async function uploadFiles(client, owner, repo, release_id, all_files, params) {
params = params || {};
async function uploadFiles(client, owner, repo, release_id, all_files) {
const attachments = await client.repository.repoListReleaseAttachments({
owner: owner,
repo: repo,
@ -144,19 +105,18 @@ async function uploadFiles(client, owner, repo, release_id, all_files, params) {
})
for (const filepath of all_files) {
for (const attachment of attachments) {
let will_deleted = [path.basename(filepath), `${path.basename(filepath)}.md5`, `${path.basename(filepath)}.sha256`]
if (will_deleted.includes(attachment.name)) {
if (attachment.name === path.basename(filepath)) {
await client.repository.repoDeleteReleaseAttachment({
owner: owner,
repo: repo,
id: release_id,
id: id,
attachmentId: attachment.id,
})
console.log(`Successfully deleted old release attachment ${attachment.name}`)
}
}
const content = fs.readFileSync(filepath);
let blob = new Blob([content]);
const blob = new Blob([content]);
await client.repository.repoCreateReleaseAttachment({
owner: owner,
repo: repo,
@ -164,30 +124,6 @@ async function uploadFiles(client, owner, repo, release_id, all_files, params) {
attachment: blob,
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}`)
}
}

6
package-lock.json generated
View File

@ -11,7 +11,6 @@
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0",
"crypto-js": "^4.2.0",
"gitea-api": "^1.17.3-1",
"glob": "^10.3.10"
},
@ -277,11 +276,6 @@
"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": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz",

View File

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