Skip to content

Commit

Permalink
chore(ci): add release
Browse files Browse the repository at this point in the history
  • Loading branch information
kokororin committed Jan 16, 2025
1 parent 7f63f19 commit 6d22650
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 28 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ jobs:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
VSCE_TOKEN: ${{ secrets.VSCE_TOKEN }}
OVSX_TOKEN: ${{ secrets.OVSX_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@
"devDependencies": {
"@antfu/ni": "^23.2.0",
"@kokororin/prettierrc": "^0.1.1",
"@octokit/rest": "^21.1.0",
"@types/adm-zip": "^0.5.7",
"@types/debug": "^4.1.12",
"@types/got": "^9.6.12",
Expand Down
132 changes: 132 additions & 0 deletions pnpm-lock.yaml

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

79 changes: 51 additions & 28 deletions scripts/release.mts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { simpleGit } from 'simple-git';
import { consola } from 'consola';
import { dirname } from 'dirname-filename-esm';
import { got } from 'got';
import { Octokit } from '@octokit/rest';
import isInCi from 'is-in-ci';
import { $ } from 'execa';

Expand Down Expand Up @@ -117,38 +118,60 @@ ${changelogData}`;
.push()
.pushTags();

// Publish to NPM
try {
await $({
stdio: 'inherit',
env: {
NODE_AUTH_TOKEN: process.env.NODE_AUTH_TOKEN
}
})`npm publish --ignore-scripts`;
} catch (err) {
consola.error(err);
if (process.env.GITHUB_TOKEN) {
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN
});
try {
await octokit.rest.repos.createRelease({
owner: pkg.author,
repo: pkg.name,
tag_name: `v${newVersion}`,
body: `Please refer to [CHANGELOG.md](https://github.com/kokororin/vscode-phpfmt/blob/master/CHANGELOG.md) for details.`, // 可选的 release 描述
draft: false,
prerelease: false
});
} catch (err) {
consola.error(err);
}
}

// Publish to VSCE
try {
await $({
stdio: 'inherit',
preferLocal: true
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
})`vsce publish -p ${process.env.VSCE_TOKEN!} --no-dependencies`;
} catch (err) {
consola.error(err);
if (process.env.NODE_AUTH_TOKEN) {
// Publish to NPM
try {
await $({
stdio: 'inherit',
env: {
NODE_AUTH_TOKEN: process.env.NODE_AUTH_TOKEN
}
})`npm publish --ignore-scripts`;
} catch (err) {
consola.error(err);
}
}

// Publish to OVSX
try {
await $({
stdio: 'inherit',
preferLocal: true
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
})`ovsx publish -p ${process.env.OVSX_TOKEN!} --no-dependencies`;
} catch (err) {
consola.error(err);
if (process.env.VSCE_TOKEN) {
// Publish to VSCE
try {
await $({
stdio: 'inherit',
preferLocal: true
})`vsce publish -p ${process.env.VSCE_TOKEN} --no-dependencies`;
} catch (err) {
consola.error(err);
}
}

if (process.env.OVSX_TOKEN) {
// Publish to OVSX
try {
await $({
stdio: 'inherit',
preferLocal: true
})`ovsx publish -p ${process.env.OVSX_TOKEN} --no-dependencies`;
} catch (err) {
consola.error(err);
}
}
} catch (err) {
consola.error(err);
Expand Down

0 comments on commit 6d22650

Please sign in to comment.