Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 51 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,65 @@
name: release and publish
name: release

on:
workflow_dispatch:
inputs:
mode:
type: choice
required: true
options:
- prerelease
- release
version-type:
type: choice
required: true
options:
- patch
- minor
- major
prerelease-type:
type: choice
required: true
options:
- rc
- beta
- alpha
dry-run:
type: choice
default: ""
options:
- -d
- ""

permissions:
id-token: write
contents: write
packages: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: release/latest
fetch-depth: 0

- name: Install dependencies
run: npm ci
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: initialize git user
- name: git config
run: |
git config --global user.email "shaadcode@gmail.com"
git config --global user.name "shaadcode"
- name: initialize the npm config
run: npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"

- run: bun i --frozen-lockfile
- run: bun i -g npm@latest
- if: inputs.mode == 'prerelease'
run: npm run pre-release -- -i ${{ inputs.version-type }} --preRelease=${{ inputs.prerelease-type }} ${{inputs.dry-run}}
env:
NPM_TOKEN: ${{secrets.NPM_TOKEN}}
- name: Run release
run: npm run release
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- if: inputs.mode == 'release'
run: npm run release -- -i ${{ inputs.version-type }} ${{inputs.dry-run}}
env:
NPM_TOKEN: ${{secrets.NPM_TOKEN}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
147 changes: 82 additions & 65 deletions .release-it.prerelease.ts
Original file line number Diff line number Diff line change
@@ -1,68 +1,85 @@
import type { Config } from 'release-it'
import type { Config } from 'release-it';
import { execSync } from 'child_process';

function getCommitAuthor(commitHash: string): string {
try {
const author = execSync(
`git show -s --format="%an" ${commitHash}`,
{ encoding: 'utf-8' }
).trim();
return author || 'unknown';
} catch {
return 'unknown';
}
}
export default {
git: {
commitMessage: 'chore: release v${version}',
tagName: 'v${version}',
push: true,
},
github: {
releaseName: 'v${version}',
release: true,
preRelease: true,
},
npm: {
publish: true,
},
plugins: {
'@release-it/conventional-changelog': {
infile: 'CHANGELOG.md',
header: '# Changelog',
preset: {
name: 'conventionalcommits',
types: [
{
type: 'feat',
section: '🚀 Features',
hidden: false,
},
{
type: 'fix',
section: '🐞 Bug Fixes',
hidden: false,
},
{
type: 'chore',
section: '🧹 Chores',
hidden: false,
},
{
type: 'docs',
section: '📚 Documentation',
hidden: false,
},
{
type: 'refactor',
section: '🔧 Refactoring',
hidden: false,
},
{
type: 'perf',
section: '⚡ Performance',
hidden: false,
},
{
type: 'test',
section: '✅ Tests',
hidden: false,
},
{
type: 'style',
section: '🎨 Styles',
hidden: false,
},
],
},
git: {
requireBranch: "main"
},
},
} satisfies Config
hooks: {
"before:init": ["git pull"]
},
github: {
"preRelease": true,
release: true,
},
"npm": {
"publish": true,
skipChecks: true,
publishArgs: ["--registry", "https://registry.npmjs.org/"],
},
"plugins": {
"@release-it/conventional-changelog": {
"infile": "CHANGELOG.md",
"header": "# Changelog",
writerOpts: {
commitPartial: (ctx: any, commit: any) => {
const scope = ctx.scope
const subject = ctx.subject
const shortHash = ctx.raw.hash
const hash = ctx.hash
const owner = getCommitAuthor(hash)
const type = ctx.raw.type
return `- ${type}${scope ? `(${scope})` : ""}: ${subject} by **<u>${owner}</u>** in ${shortHash}\n`;
}
},
"preset": {
"name": "conventionalcommits",
"types": [
{
"type": "feat",
"section": "🚀 Features",
},
{
"type": "fix",
"section": "🐞 Bug Fixes",
},
{
"type": "chore",
"section": "🧹 Chores",
},
{
"type": "docs",
"section": "📚 Documentation",
},
{
"type": "refactor",
"section": "🔧 Refactoring",
},
{
"type": "perf",
"section": "⚡ Performance",
},
{
"type": "test",
"section": "✅ Tests",
},
{
"type": "style",
"section": "🎨 Styles",
}
]
}
}
}
} satisfies Config;
110 changes: 60 additions & 50 deletions .release-it.ts
Original file line number Diff line number Diff line change
@@ -1,76 +1,86 @@
import type { Config } from 'release-it'
import { execSync } from 'child_process';
import type { Config } from 'release-it';

function getCommitAuthor(commitHash: string): string {
try {
const author = execSync(
`git show -s --format="%an" ${commitHash}`,
{ encoding: 'utf-8' }
).trim();
return author || 'unknown';
} catch {
return 'unknown';
}
}
export default {
git: {
commitMessage: 'chore: release v${version}',
tagName: 'v${version}',
push: true,
pushRepo: 'origin',
requireBranch: 'release/latest',
getLatestTagFromAllRefs: true
requireBranch: "main"
},
hooks: {
'before:init': ['git fetch --tags', 'git pull'],
"before:init": ["git pull"],
},
github: {
release: true,
releaseName: 'v${version}',
"release": true,
},
npm: {
publish: true,
"npm": {
"publish": true,
skipChecks: true,
publishArgs: ["--registry", "https://registry.npmjs.org/"],

},
plugins: {
'@release-it/conventional-changelog': {
infile: 'CHANGELOG.md',
header: '# Changelog',
"plugins": {
"@release-it/conventional-changelog": {
"infile": "CHANGELOG.md",
"header": "# Changelog",
strictSemVer: true,
writerOpts: {
commitPartial:
'{{subject}}{{#if references}} in {{#each references}}#{{this.issue}}{{/each}}{{/if}} ({{shortHash}})\n',
commitPartial: (ctx: any, commit: any) => {
const scope = ctx.scope
const subject = ctx.subject
const shortHash = ctx.raw.hash
const hash = ctx.hash
const owner = getCommitAuthor(hash)
const type = ctx.raw.type
return `- ${type}${scope ? `(${scope})` : ""}: ${subject} by **<u>${owner}</u>** in ${shortHash}\n`;
}
},
preset: {
name: 'conventionalcommits',
types: [
"preset": {
"name": "conventionalcommits",
"types": [
{
type: 'feat',
section: '🚀 Features',
hidden: false,
"type": "feat",
"section": "🚀 Features",
},
{
type: 'fix',
section: '🐞 Bug Fixes',
hidden: false,
"type": "fix",
"section": "🐞 Bug Fixes",
},
{
type: 'chore',
hidden: true,
"type": "chore",
"section": "🧹 Chores",
},
{
type: 'docs',
section: '📚 Documentation',
hidden: false,
"type": "docs",
"section": "📚 Documentation",
},
{
type: 'refactor',
section: '🔧 Refactoring',
hidden: false,
"type": "refactor",
"section": "🔧 Refactoring",
},
{
type: 'perf',
section: '⚡ Performance',
hidden: false,
"type": "perf",
"section": "⚡ Performance",
},
{
type: 'test',
section: '✅ Tests',
hidden: true,
"type": "test",
"section": "✅ Tests",
},
{
type: 'style',
section: '🎨 Styles',
hidden: true,
},
],
},
},
},
} satisfies Config
"type": "style",
"section": "🎨 Styles",
}
]
}
}
}
} satisfies Config;
Loading
Loading