Skip to content

Commit 8a8dc44

Browse files
committed
chore: test action
1 parent cdb8f23 commit 8a8dc44

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1547
-498
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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
- name: Install pnpm
14+
uses: pnpm/action-setup@v2
15+
with:
16+
version: 10
17+
- name: Install Node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: 18
21+
cache: 'pnpm'
22+
- name: Install dependencies
23+
run: pnpm install
24+
- name: Create pull request with release changes
25+
run: pnpm tsm --no-warnings ./packages/github-action/src/index.ts
26+
env:
27+
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

.simple-release.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { PnpmWorkspacesProject } from './packages/pnpm/src/index.js'
2+
// import { GithubHosting } from './packages/github/src/index.js'
3+
4+
export const project = new PnpmWorkspacesProject({
5+
mode: 'fixed'
6+
})
7+
8+
// export const hosting = new GithubHosting({
9+
// token: process.env.GITHUB_TOKEN
10+
// })
11+
12+
export const releaser = {
13+
verbose: true
14+
}
15+
16+
export const bump = {
17+
byProject: {
18+
'simple-github-release': {
19+
firstRelease: false
20+
}
21+
}
22+
}

packages/config/.eslintrc.json

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/config",
9+
"project": ["./tsconfig.json"]
10+
},
11+
"rules": {
12+
"@typescript-eslint/naming-convention": "off"
13+
}
14+
}

packages/config/package.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "@simple-release/config",
3+
"type": "module",
4+
"private": true,
5+
"version": "0.0.0",
6+
"description": "A simple-release config loader.",
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/config#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/config"
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+
"@simple-release/core": "workspace:^",
35+
"find-up-simple": "^1.0.1"
36+
}
37+
}

packages/config/src/index.ts

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
import { findUp } from 'find-up-simple'
3+
import type {
4+
PickOverridableOptions,
5+
Project,
6+
GitRepositoryHosting,
7+
ReleaserOptions,
8+
ReleaserCheckoutOptions,
9+
ReleaserCommitOptions,
10+
ReleaserTagOptions,
11+
ReleaserPushOptions
12+
} from '@simple-release/core'
13+
14+
const VARIANTS = [
15+
'.simple-release.js',
16+
'.simple-release.mjs',
17+
'.simple-release.cjs'
18+
]
19+
20+
export interface SimpleReleaseConfig<
21+
P extends Project = Project,
22+
G extends GitRepositoryHosting = GitRepositoryHosting
23+
> {
24+
project?: P
25+
hosting?: G
26+
releaser?: Omit<ReleaserOptions, 'project' | 'hosting'>
27+
checkout?: {
28+
branch?: string
29+
} & ReleaserCheckoutOptions
30+
bump?: PickOverridableOptions<P['bump']>
31+
commit?: ReleaserCommitOptions
32+
tag?: ReleaserTagOptions
33+
push?: ReleaserPushOptions
34+
publish?: PickOverridableOptions<P['publish']>
35+
release?: PickOverridableOptions<G['createRelease']>
36+
pullRequest?: PickOverridableOptions<G['createPullRequest']>
37+
}
38+
39+
export type SimpleReleaseConfigRequirements = {
40+
config?: boolean
41+
} & {
42+
[K in keyof SimpleReleaseConfig]?: boolean
43+
}
44+
45+
type ApplyRequirements<T extends Record<string, any>, R extends Record<string, any>> = {
46+
[K in keyof T as K extends keyof R ? R[K] extends true ? K : never : never]-?: Exclude<T[K], undefined>
47+
} & {
48+
[K in keyof T as K extends keyof R ? R[K] extends true ? never : K : K]: T[K]
49+
}
50+
51+
type ApplyConfigRequirement<R extends { config?: boolean }, T> = R extends { config: true }
52+
? T
53+
: T | null
54+
55+
type Result<
56+
P extends Project = Project,
57+
G extends GitRepositoryHosting = GitRepositoryHosting,
58+
R extends SimpleReleaseConfigRequirements = SimpleReleaseConfigRequirements
59+
> = ApplyRequirements<SimpleReleaseConfig<P, G>, R> extends infer C
60+
? ApplyConfigRequirement<R, C>
61+
: never
62+
63+
function validate(target: Record<string, any>, rules: Record<string, any>) {
64+
for (const [rule, required] of Object.entries(rules)) {
65+
if (required && target[rule] === undefined) {
66+
throw new Error(`Faild to load config: '${rule}' is required`)
67+
}
68+
}
69+
}
70+
71+
/**
72+
* Load simple-release config.
73+
* @param requirements
74+
* @returns simple-release config
75+
*/
76+
export async function load<
77+
P extends Project = Project,
78+
G extends GitRepositoryHosting = GitRepositoryHosting,
79+
R extends SimpleReleaseConfigRequirements = SimpleReleaseConfigRequirements
80+
>(requirements?: R): Promise<Result<P, G, R>>
81+
82+
export async function load(requirements: Record<string, any> = {}) {
83+
console.log(requirements)
84+
85+
for (const variant of VARIANTS) {
86+
const foundPath = await findUp(variant)
87+
88+
if (foundPath) {
89+
console.log(foundPath)
90+
91+
try {
92+
const module = await import(foundPath) as SimpleReleaseConfig | { default: SimpleReleaseConfig }
93+
const config = 'default' in module ? module.default : module
94+
95+
console.log(config)
96+
97+
validate(config, requirements)
98+
99+
return config
100+
} catch (err) {
101+
if (requirements.config) {
102+
throw err
103+
}
104+
105+
return null
106+
}
107+
}
108+
}
109+
110+
if (requirements.config) {
111+
throw new Error('Config not found')
112+
}
113+
114+
return null
115+
}
File renamed without changes.

packages/core/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,14 @@ Project is a class that represents the project and provides methods to work with
155155
- publish the project
156156
- etc.
157157

158-
Most of the methods are implemented in base class [GenericProject](./src/project/project.ts) and you can extend it to create your own project class.
158+
Most of the methods are implemented in base class [Project](./src/project/project.ts) and you can extend it to create your own project class.
159159

160160
In most casses you need just prepare options for the base class and implement `publish` method (like it is done in [PackageJsonProject](./src/project/packageJson.ts)).
161161

162162
```js
163-
import { GenericProject } from '@simple-release/core'
163+
import { Project } from '@simple-release/core'
164164

165-
export class CustomProject extends GenericProject {
165+
export class CustomProject extends Project {
166166
constructor(options) {
167167
super({
168168
...options,
@@ -176,7 +176,7 @@ export class CustomProject extends GenericProject {
176176
}
177177
```
178178

179-
There also is a base class for monorepo projects - [GenericMonorepoProject](./src/project/monorepo.ts). It provides methods to work with monorepo projects and you can extend it to create your own monorepo project class (alos see [PackageJsonMonorepoProject](./src/project/packageJsonMonorepo.ts)).
179+
There also is a base class for monorepo projects - [MonorepoProject](./src/project/monorepo.ts). It provides methods to work with monorepo projects and you can extend it to create your own monorepo project class (alos see [PackageJsonMonorepoProject](./src/project/packageJsonMonorepo.ts)).
180180

181181
### Release creator
182182

@@ -185,9 +185,9 @@ Release creator is a class that creates a release in the remote repository (like
185185
Signature of the class is very simple, you just need to implement `create` method:
186186

187187
```js
188-
import { GenericReleaseCreator } from '@simple-release/core'
188+
import { ReleaseCreator } from '@simple-release/core'
189189

190-
export class CustomReleaseCreator extends GenericReleaseCreator {
190+
export class CustomReleaseCreator extends ReleaseCreator {
191191
async create({ project, dryRun, logger }) {
192192
// Create the release in the remote repository
193193
// You can use `project` to get information about the project

0 commit comments

Comments
 (0)