Skip to content

Commit d8b6563

Browse files
committed
chore: test action
1 parent cdb8f23 commit d8b6563

File tree

16 files changed

+609
-35
lines changed

16 files changed

+609
-35
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: simple-release
2+
description: A simple tool to release projects with monorepo support.
3+
inputs:
4+
action:
5+
description: |
6+
Action that simple-release should do:
7+
- pr - create pull request with release changes
8+
- release - create tags, release notes and publish, only if pull request with fresh release was merged
9+
default: pr
10+
token:
11+
description: GitHub Token
12+
branch:
13+
description: Branch name to store release changes
14+
default: simple-release
15+
runs:
16+
using: node20
17+
main: dist/index.js

.github/workflows/release.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Release
2+
on:
3+
push:
4+
branches:
5+
- action
6+
jobs:
7+
release:
8+
runs-on: ubuntu-latest
9+
name: Release
10+
steps:
11+
- name: Checkout the repository
12+
uses: actions/checkout@v4
13+
# with:
14+
# fetch-depth: 0
15+
# fetch-tags: true
16+
- name: Install pnpm
17+
uses: pnpm/action-setup@v2
18+
with:
19+
version: 10
20+
- name: Install Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: 18
24+
cache: 'pnpm'
25+
- name: Install dependencies
26+
run: pnpm install
27+
- name: Create pull request with release changes
28+
run: pnpm tsm --no-warnings ./packages/github-action/src/index.ts
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ node_modules
2323
dist
2424
packages/*/package
2525
build
26+
!.github/actions/*/dist
27+
!.github/actions/*/dist/node_modules
2628

2729
# Env files
2830
.env

packages/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"dependencies": {
6161
"@conventional-changelog/git-client": "^2.4.0",
6262
"@simple-libs/child-process-utils": "^1.0.0",
63+
"@simple-libs/hosted-git-info": "^1.0.0",
6364
"@simple-libs/stream-utils": "^1.0.0",
6465
"conventional-changelog": "^7.0.2",
6566
"conventional-changelog-conventionalcommits": "^9.0.0",

packages/core/src/project/monorepo.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export interface GenericMonorepoProjectOptions extends GenericProjectOptions {
5151
gitClient?: ConventionalGitClient
5252
}
5353

54+
export type GenericMonorepoProjectBumpByProjectOptions = Pick<GenericProjectBumpOptions, 'version' | 'as' | 'prerelease' | 'firstRelease' | 'skip'>
55+
5456
export interface GenericMonorepoProjectBumpOptions extends Omit<GenericProjectBumpOptions, 'tagPrefix'> {
5557
/**
5658
* Force bump projects without changes in the monorepo with fixed mode.
@@ -59,7 +61,7 @@ export interface GenericMonorepoProjectBumpOptions extends Omit<GenericProjectBu
5961
/**
6062
* Bump options for specific projects.
6163
*/
62-
byProject?: Record<string, Pick<GenericProjectBumpOptions, 'version' | 'as' | 'prerelease' | 'firstRelease'>>
64+
byProject?: Record<string, GenericMonorepoProjectBumpByProjectOptions>
6365
}
6466

6567
export abstract class GenericMonorepoProject extends GenericProject {

packages/core/src/project/project.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ConventionalGitClient } from '@conventional-changelog/git-client'
44
import { Bumper } from 'conventional-recommended-bump'
55
import { ConventionalChangelog } from 'conventional-changelog'
66
import { concatStringStream } from '@simple-libs/stream-utils'
7+
import { parseHostedGitUrl } from '@simple-libs/hosted-git-info'
78
import semver, { type ReleaseType } from 'semver'
89
import {
910
type ProjectManifestVersionUpdate,
@@ -63,6 +64,10 @@ export interface GenericProjectBumpOptions {
6364
* By default will be auto detected based on tag existence.
6465
*/
6566
firstRelease?: boolean
67+
/**
68+
* Skip bumping.
69+
*/
70+
skip?: boolean
6671
preset?: PresetParams
6772
/**
6873
* The prefix to use for the tag.
@@ -152,6 +157,17 @@ export abstract class GenericProject {
152157
this.gitClient = gitClient
153158
}
154159

160+
/**
161+
* Get the hosted git information for the project.
162+
* @returns The hosted git information.
163+
*/
164+
async getHostedGitInfo() {
165+
const remote = await this.gitClient.getConfig('remote.origin.url')
166+
const info = parseHostedGitUrl(remote)
167+
168+
return info
169+
}
170+
155171
/**
156172
* Get the commit message for the version updates.
157173
* @returns The commit message.
@@ -249,7 +265,7 @@ export abstract class GenericProject {
249265
manifest
250266
} = this
251267

252-
if (await manifest.isPrivate()) {
268+
if (options.skip || await manifest.isPrivate()) {
253269
return null
254270
}
255271

packages/core/src/releaser.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ import {
1010
import { type GenericReleaseCreator } from './release/index.js'
1111
import { Logger } from './logger.js'
1212

13+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
14+
type GetParameter<T extends (...args: any[]) => any> = Exclude<Parameters<T>[0], undefined>
15+
1316
export interface ReleaserOptions {
1417
dryRun?: boolean
1518
silent?: boolean
19+
verbose?: boolean
1620
logger?: Logger
1721
}
1822

@@ -27,13 +31,13 @@ export class Releaser<P extends GenericProject = GenericProject> {
2731
/**
2832
* The git client used to interact with the repository.
2933
*/
30-
gitClient: ConventionalGitClient
34+
readonly gitClient: ConventionalGitClient
3135
/**
3236
* The logger used to log messages during the release process.
3337
*/
34-
logger: Logger
38+
readonly logger: Logger
39+
readonly isMonorepo: boolean
3540
private readonly queue: (() => Promise<unknown>)[] = []
36-
private readonly isMonorepo: boolean
3741

3842
/**
3943
* Creates a project releaser.
@@ -49,13 +53,18 @@ export class Releaser<P extends GenericProject = GenericProject> {
4953
this.isMonorepo = project instanceof GenericMonorepoProject
5054
}
5155

56+
enqueue(fn: () => Promise<void>) {
57+
this.queue.push(fn)
58+
return this
59+
}
60+
5261
/**
5362
* Enqueue a task to bump the version of the project.
5463
* @param options
5564
* @returns Project releaser instance for chaining.
5665
*/
57-
bump(options?: Omit<Parameters<P['bump']>[0], 'dryRun' | 'logger'>) {
58-
this.queue.push(async () => {
66+
bump(options?: Omit<GetParameter<P['bump']>, 'dryRun' | 'logger'>) {
67+
return this.enqueue(async () => {
5968
const { isMonorepo } = this
6069
const { dryRun } = this.options
6170
const logger = this.logger.createChild('bump')
@@ -72,8 +81,6 @@ export class Releaser<P extends GenericProject = GenericProject> {
7281
logger.info(`No version${isMonorepo ? 's' : ''} changes detected.`)
7382
}
7483
})
75-
76-
return this
7784
}
7885

7986
/**
@@ -82,7 +89,7 @@ export class Releaser<P extends GenericProject = GenericProject> {
8289
* @returns Project releaser instance for chaining.
8390
*/
8491
commit(options?: ReleaserCommitOptions) {
85-
this.queue.push(async () => {
92+
return this.enqueue(async () => {
8693
const { dryRun } = this.options
8794

8895
this.logger.info('commit', `Committing changes...`)
@@ -100,15 +107,18 @@ export class Releaser<P extends GenericProject = GenericProject> {
100107
this.logger.verbose('commit', `- ${file}`)
101108
})
102109

103-
this.logger.verbose('commit', `Commit message:\n\n${params.message}`)
110+
this.logger.verbose(
111+
'commit',
112+
params.message.includes('\n')
113+
? `Commit message:\n\n${params.message}`
114+
: `Commit message: ${params.message}`
115+
)
104116

105117
if (!dryRun) {
106118
await this.gitClient.add(files)
107119
await this.gitClient.commit(params)
108120
}
109121
})
110-
111-
return this
112122
}
113123

114124
/**
@@ -117,7 +127,7 @@ export class Releaser<P extends GenericProject = GenericProject> {
117127
* @returns Project releaser instance for chaining.
118128
*/
119129
tag(options?: ReleaserTagOptions) {
120-
this.queue.push(async () => {
130+
return this.enqueue(async () => {
121131
const { isMonorepo } = this
122132
const { dryRun } = this.options
123133

@@ -144,8 +154,6 @@ export class Releaser<P extends GenericProject = GenericProject> {
144154
}
145155
}
146156
})
147-
148-
return this
149157
}
150158

151159
/**
@@ -154,7 +162,7 @@ export class Releaser<P extends GenericProject = GenericProject> {
154162
* @returns Project releaser instance for chaining.
155163
*/
156164
push(branch?: string) {
157-
this.queue.push(async () => {
165+
return this.enqueue(async () => {
158166
const { dryRun } = this.options
159167
const targetBranch = branch || await this.gitClient.getDefaultBranch()
160168

@@ -170,17 +178,15 @@ export class Releaser<P extends GenericProject = GenericProject> {
170178
})
171179
}
172180
})
173-
174-
return this
175181
}
176182

177183
/**
178184
* Enqueue a task to publish the project.
179185
* @param options
180186
* @returns Project releaser instance for chaining.
181187
*/
182-
publish(options?: Omit<Parameters<P['publish']>[0], 'dryRun' | 'logger'>) {
183-
this.queue.push(async () => {
188+
publish(options?: Omit<GetParameter<P['publish']>, 'dryRun' | 'logger'>) {
189+
return this.enqueue(async () => {
184190
const { isMonorepo } = this
185191
const { dryRun } = this.options
186192
const logger = this.logger.createChild('package')
@@ -193,8 +199,6 @@ export class Releaser<P extends GenericProject = GenericProject> {
193199
...options
194200
})
195201
})
196-
197-
return this
198202
}
199203

200204
/**
@@ -203,7 +207,7 @@ export class Releaser<P extends GenericProject = GenericProject> {
203207
* @returns Project releaser instance for chaining.
204208
*/
205209
release(releaseCreator: GenericReleaseCreator) {
206-
this.queue.push(async () => {
210+
return this.enqueue(async () => {
207211
const { isMonorepo } = this
208212
const { dryRun } = this.options
209213
const logger = this.logger.createChild('release')
@@ -216,8 +220,6 @@ export class Releaser<P extends GenericProject = GenericProject> {
216220
logger
217221
})
218222
})
219-
220-
return this
221223
}
222224

223225
/**
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": [
3+
"@trigen/eslint-config/typescript",
4+
"@trigen/eslint-config/typescript-requiring-type-checking",
5+
"@trigen/eslint-config/jest"
6+
],
7+
"parserOptions": {
8+
"tsconfigRootDir": "./packages/github-action",
9+
"project": ["./tsconfig.json"]
10+
},
11+
"rules": {
12+
"@typescript-eslint/naming-convention": "off"
13+
}
14+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "@simple-release/github-action",
3+
"type": "module",
4+
"private": true,
5+
"version": "0.0.0",
6+
"description": "A simple-release github action.",
7+
"author": {
8+
"name": "Dan Onoshko",
9+
"email": "[email protected]",
10+
"url": "https://github.com/dangreen"
11+
},
12+
"license": "MIT",
13+
"homepage": "https://github.com/TrigenSoftware/simple-release/tree/master/packages/github-action#readme",
14+
"funding": "https://ko-fi.com/dangreen",
15+
"repository": {
16+
"type": "git",
17+
"url": "https://github.com/TrigenSoftware/simple-release.git",
18+
"directory": "packages/github-action"
19+
},
20+
"bugs": {
21+
"url": "https://github.com/TrigenSoftware/simple-release/issues"
22+
},
23+
"keywords": [],
24+
"engines": {
25+
"node": ">=18"
26+
},
27+
"exports": "./src/index.ts",
28+
"scripts": {
29+
"lint": "eslint --parser-options tsconfigRootDir:. '**/*.{js,ts}'",
30+
"test:types": "tsc --noEmit",
31+
"test": "run -p lint test:types"
32+
},
33+
"dependencies": {
34+
"@actions/core": "^1.11.1",
35+
"@actions/exec": "^1.1.1",
36+
"@actions/github": "^6.0.1",
37+
"@simple-release/core": "workspace:^",
38+
"@simple-release/pnpm": "workspace:^"
39+
}
40+
}

0 commit comments

Comments
 (0)