Skip to content

Commit 2ff8260

Browse files
committed
feat(@skyroc/cli): ✨ enhance changelog generation with dynamic tag retrieval and update release workflow
1 parent cfcb01a commit 2ff8260

File tree

4 files changed

+40
-69
lines changed

4 files changed

+40
-69
lines changed

.github/workflows/release.yml

Lines changed: 10 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,25 @@
11
name: Release
22

3+
permissions:
4+
contents: write
5+
36
on:
47
push:
5-
branches:
6-
- main
8+
tags:
9+
- "v*"
710

811
jobs:
912
release:
10-
# ✅ Only run in your main repository (prevent auto-release from forks)
11-
if: ${{ github.repository_owner == 'Ohh-889' }}
12-
name: Version & Publish Changed Packages
1313
runs-on: ubuntu-latest
14-
permissions:
15-
contents: write
16-
pull-requests: write
17-
1814
steps:
19-
# 🧩 Checkout full repository (with history)
20-
- name: Checkout repository
21-
uses: actions/checkout@v4
15+
- uses: actions/checkout@v3
2216
with:
2317
fetch-depth: 0
2418

25-
# 🧰 Setup Node + pnpm environment
26-
- name: Setup Node.js 20
27-
uses: actions/setup-node@v4
28-
with:
29-
node-version: 20
30-
cache: "pnpm"
31-
32-
- name: Setup pnpm
33-
uses: pnpm/action-setup@v4
19+
- uses: actions/setup-node@v3
3420
with:
35-
version: 9.0.6
21+
node-version: 18.x
3622

37-
# 📦 Install dependencies
38-
- name: Install dependencies
39-
run: pnpm install --frozen-lockfile
40-
41-
# 🔍 Detect which packages will be published
42-
- name: Detect changed packages
43-
id: changed
44-
run: |
45-
CHANGED=$(pnpm changeset status --json | jq -r '.changesets[].releases[].name' | sort | uniq)
46-
echo "changed=$CHANGED" >> $GITHUB_OUTPUT
47-
shell: bash
48-
49-
# 🏗️ Build only changed packages (and their dependencies)
50-
- name: Build changed packages
51-
if: steps.changed.outputs.changed != ''
52-
run: |
53-
for pkg in ${{ steps.changed.outputs.changed }}; do
54-
echo "🏗️ Building $pkg..."
55-
pnpm install --filter "./packages/$pkg..." --frozen-lockfile
56-
pnpm build --filter "./packages/$pkg"
57-
done
58-
shell: bash
59-
60-
# 🏷️ Create version PR or publish to npm
61-
- name: Create Version PR or Publish to npm
62-
id: changesets
63-
uses: changesets/action@v1
64-
with:
65-
commit: "chore(release): version packages"
66-
title: "chore(release): version packages"
67-
version: node .github/changeset-version.js
68-
publish: pnpm changeset publish
23+
- run: npx githublogen
6924
env:
70-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
72-
NODE_ENV: "production"
25+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { generateChangelog, generateTotalChangelog } from '@soybeanjs/changelog';
22
import type { ChangelogOption } from '@soybeanjs/changelog';
33

4-
export async function genChangelog(options?: Partial<ChangelogOption>, total = false) {
4+
export async function genChangelog(options?: Partial<ChangelogOption>, total = false, tag?: string) {
55
if (total) {
6-
await generateTotalChangelog(options);
6+
await generateTotalChangelog(Object.assign(options ?? {}, { to: tag }));
77
} else {
8-
await generateChangelog(options);
8+
await generateChangelog(Object.assign(options ?? {}, { to: tag }));
99
}
1010
}

internal/cli/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ interface CommandArg {
4141
push?: boolean;
4242
/** The release type (e.g. "conventional", "npm", "yarn", "pnpm"). Defaults to "conventional" */
4343
release?: string;
44+
/** The tag to generate changelog */
45+
tag?: string;
4446
/** Generate changelog by total tags */
4547
total?: boolean;
4648
}
@@ -66,6 +68,7 @@ export async function setupCli() {
6668
.option('-l, --lang <lang>', 'display lang of cli', { default: 'en-us', type: [String] })
6769
.option('-m, --gitEmoji <emoji>', 'git commit emoji')
6870
.option('-pr, --preid <preid>', 'The prerelease type (e.g. "alpha", "beta", "next"). Defaults to "beta"')
71+
.option('-tg, --tag <tag>', 'The tag to generate changelog')
6972
.option(
7073
'-re, --release <release>',
7174
'The release type (e.g. "conventional", "npm", "yarn", "pnpm"). Defaults to "conventional"'
@@ -75,7 +78,7 @@ export async function setupCli() {
7578
const commands: CommandWithAction<CommandArg> = {
7679
changelog: {
7780
action: async args => {
78-
await genChangelog(cliOptions.changelogOptions, args?.total);
81+
await genChangelog(cliOptions.changelogOptions, args?.total, args?.tag);
7982
},
8083
desc: 'generate changelog'
8184
},

skyroc.config.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ import path from 'node:path';
44

55
import { defineConfig } from '@skyroc/cli';
66

7-
let tag = '';
7+
function getLastTag() {
8+
const tag = execSync('git tag -l --sort=v:refname | tail -n 1').toString().trim();
9+
10+
return tag;
11+
}
12+
13+
getLastTag();
814

915
export default defineConfig({
1016
changelogOptions: {
11-
to: tag
17+
from: getLastTag()
1218
},
1319
// Custom git commit scopes
1420
// If not set, will use default scopes from locale
@@ -52,23 +58,32 @@ export default defineConfig({
5258

5359
const pkgName = pkg.name;
5460

61+
// eslint-disable-next-line no-console
5562
console.log(`🔍 Current version: ${pkgName}@${current}`);
5663

5764
return {
5865
commit: `chore(${pkgName}): release v%s`,
5966
confirm: false,
6067
cwd,
61-
execute: op => {
62-
console.log('New version:', op.state.newVersion);
68+
// Use function to access op.state.newVersion and pass it to changelog command
69+
execute: async op => {
70+
const { execSync: execSync2 } = await import('node:child_process');
71+
const tag = `${pkgName}@${op.state.newVersion}`;
6372

64-
tag = `${pkgName}@${op.state.newVersion}`;
65-
execSync(`npx sr changelog`);
73+
console.log(`📝 Generating changelog for tag: ${tag}`);
74+
75+
// Execute changelog command in the root directory with the tag parameter
76+
execSync2(`pnpm sr changelog --tag ${tag}`, {
77+
cwd: process.cwd(),
78+
env: { ...process.env, CHANGELOG_TAG: tag },
79+
stdio: 'inherit'
80+
});
6681
},
67-
files: ['package.json'],
82+
files: ['**/package.json', '!**/node_modules'],
6883
preid,
6984
progress(info) {
7085
// Log release progress events
71-
86+
// eslint-disable-next-line no-console
7287
console.log(`[${info.event}] ${info.newVersion ?? ''} ${info.commit ?? ''}`);
7388
},
7489
// Automatic commit type analysis

0 commit comments

Comments
 (0)