chore: publish release to gitee

This commit is contained in:
xiaojunnuo
2026-01-13 23:58:50 +08:00
parent 6660161cec
commit 3ab45c91e1
6 changed files with 86 additions and 23 deletions

View File

@@ -0,0 +1,30 @@
import fs from 'fs'
export function getVersionContent() {
// CHANGELOG.md
const changelog = fs.readFileSync('./CHANGELOG.md', 'utf8')
// 解析CHANGELOG.md
let lines = changelog.split('\n')
const versionLineIndex = lines.findIndex(line => line.startsWith('## '))
const versionLine = lines[versionLineIndex]
// ## [1.37.16](https://github.com/certd/certd/compare/v1.37.15...v1.37.16) (2025-12-15)
const versionTitle = versionLine.match(/\[(.*?)\]/)[1]
const contentStart = versionLineIndex + 1
lines = lines.slice(contentStart)
const contentEnd = lines.findIndex(line => {
return line.startsWith('## ')
})
const content = lines.slice(0, contentEnd).join('\n')
console.log("-------title------/n")
console.log(versionTitle)
console.log("-------content------/n")
console.log(content)
return {
versionTitle,
content
}
}

View File

@@ -1,27 +1,11 @@
import fs from 'fs'
import axios from 'axios'
import { getVersionContent } from './get-new-version.js'
const AtomgitAccessToken = process.env.ATOMGIT_TOKEN
// CHANGELOG.md
const changelog = fs.readFileSync('./CHANGELOG.md', 'utf8')
// 解析CHANGELOG.md
let lines = changelog.split('\n')
const versionLineIndex = lines.findIndex(line => line.startsWith('## '))
const versionLine = lines[versionLineIndex]
// ## [1.37.16](https://github.com/certd/certd/compare/v1.37.15...v1.37.16) (2025-12-15)
const versionTitle = versionLine.match(/\[(.*?)\]/)[1]
const contentStart = versionLineIndex + 1
lines = lines.slice(contentStart)
const contentEnd = lines.findIndex(line => {
return line.startsWith('## ')
})
const content = lines.slice(0, contentEnd).join('\n')
console.log("-------title------/n")
console.log(versionTitle)
console.log("-------content------/n")
console.log(content)
/**
* 创建仓库Release
@@ -68,7 +52,7 @@ string
*/
// 创建release
async function createRelease() {
async function createRelease(versionTitle, content) {
const response = await axios.request({
method: 'POST',
url: `https://api.atomgit.com/api/v5/repos/certd/certd/releases`,
@@ -138,7 +122,7 @@ headers
object
*/
async function getUploadUrl() {
async function getUploadUrl(versionTitle) {
const response = await axios.request({
method: 'GET',
url: `https://api.atomgit.com/api/v5/repos/certd/certd/releases/v${versionTitle}/upload_url`,
@@ -167,8 +151,9 @@ async function uploadFile(url, headers, data) {
}
async function publishToAtomgit() {
const release = await createRelease()
const uploadUrl = await getUploadUrl()
const { versionTitle, content } = getVersionContent()
const release = await createRelease(versionTitle, content)
const uploadUrl = await getUploadUrl(versionTitle)
const fileName = `./packages/ui/certd-client/ui.zip`
const fileData = fs.createReadStream(fileName)
const contentLength = fs.statSync(fileName).size

36
scripts/publish-gitee.js Normal file
View File

@@ -0,0 +1,36 @@
import axios from 'axios'
import { getVersionContent } from './get-new-version.js'
const GiteeAccessToken = process.env.GITEE_TOKEN
if (!GiteeAccessToken) {
console.log("GiteeAccessToken is empty")
throw new Error("GiteeAccessToken is empty")
}
// 创建release
async function createRelease(versionTitle, content) {
const response = await axios.request({
method: 'POST',
url: `https://gitee.com/api/v5/repos/certd/certd/releases`,
headers: {
"Content-Type": "application/json"
},
data: {
access_token: GiteeAccessToken,
tag_name: `v${versionTitle}`,
name: `v${versionTitle}`,
body: content,
target_commitish: 'v2'
},
})
console.log("createRelease success")
return response.data
}
async function publishToGitee() {
const { versionTitle, content } = getVersionContent()
const release = await createRelease(versionTitle, content)
console.log("publishToGitee success")
}
publishToGitee()