Skip to content

Commit

Permalink
fix Gitee release
Browse files Browse the repository at this point in the history
  • Loading branch information
volatile-static committed Jun 12, 2024
1 parent 965f5e6 commit 092a168
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 38 deletions.
77 changes: 57 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"zotero-plugin-toolkit": "^2.3.32"
},
"devDependencies": {
"@gitee/typescript-sdk-v5": "^5.4.84",
"@tsconfig/node-lts": "^20.1.3",
"@types/animejs": "^3.1.12",
"@types/bluebird": "^3.5.42",
Expand All @@ -77,7 +78,6 @@
"eslint-plugin-mozilla": "^3.7.1",
"eslint-plugin-vue": "^9.26.0",
"lodash": "^4.17.21",
"node-fetch": "^3.3.2",
"prettier": "3.3.2",
"tdesign-icons-vue-next": "^0.2.2",
"ts-node": "^10.9.2",
Expand Down
44 changes: 27 additions & 17 deletions tools/release.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import fs from 'fs';
import path from 'path';
import fetch from 'node-fetch';
//@ts-expect-error no types
import NodeFormData from 'form-data';
import { GiteeClient } from '@gitee/typescript-sdk-v5';
import { Release } from 'zotero-plugin-scaffold';
import loadConfig from './config';

Expand All @@ -12,25 +14,33 @@ async function main() {
await releaser.run();
if (!process.env.GITHUB_ACTIONS) return;

const changelog = releaser.getChangelog(),
tag = releaser.ctx.release.bumpp.tag,
res = await releaseGitee({
tag_name: tag,
name: 'Release ' + tag,
const changelog = await releaser.getChangelog(),
client = new GiteeClient({ TOKEN: process.env.GITEE_TOKEN }),
release = await client.repositories.postV5ReposOwnerRepoReleases({
owner: 'const_volatile',
repo: 'chartero',
tagName: 'v' + releaser.version,
name: 'Release' + releaser.version,
targetCommitish: 'main',
body: changelog,
prerelease: 'false',
target_commitish: 'main',
}),
xpi = fs.readFileSync(path.join(releaser.dist, `${releaser.xpiName}.xpi`));
releaser.logger.info({ changelog, tag, res });
releaseGitee({ file: xpi }, `/${res.id}/attach_files`);
}
form = new NodeFormData(),
xpi = fs.createReadStream(path.join(releaser.dist, `${releaser.xpiName}.xpi`));
form.append('file', xpi);

async function releaseGitee(body: Record<string, unknown>, path: string = '') {
const res = await fetch('https://gitee.com/api/v5/repos/const_volatile/chartero/releases' + path, {
const response = await client.repositories.httpRequest.request({
method: 'POST',
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
body: JSON.stringify({ ...body, access_token: process.env.GITEE_TOKEN }),
url: '/v5/repos/{owner}/{repo}/releases/{release_id}/attach_files',
path: {
owner: 'const_volatile',
repo: 'chartero',
release_id: release.id,
},
// formData: { file: xpi },
// 因为gitee的api有问题,这里只能手动实现
// gitee要求不是Blob就转string,但调用form-data时必须是stream。。
headers: form.getHeaders(),
body: form,
});
return (await res.json()) as Record<string, string>;
releaser.logger.info(response);
}

0 comments on commit 092a168

Please sign in to comment.