Skip to content

Commit d2bac7f

Browse files
committed
chore: test action
1 parent 97965d2 commit d2bac7f

File tree

15 files changed

+564
-2
lines changed

15 files changed

+564
-2
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/_pr.ts
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.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+
// }
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+
}

packages/github-action/README.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# @simple-release/github-action
2+
3+
[![ESM-only package][package]][package-url]
4+
[![NPM version][npm]][npm-url]
5+
[![Node version][node]][node-url]
6+
[![Dependencies status][deps]][deps-url]
7+
[![Install size][size]][size-url]
8+
[![Build status][build]][build-url]
9+
[![Coverage status][coverage]][coverage-url]
10+
11+
[package]: https://img.shields.io/badge/package-ESM--only-ffe536.svg
12+
[package-url]: https://nodejs.org/api/esm.html
13+
14+
[npm]: https://img.shields.io/npm/v/@simple-release/github-action.svg
15+
[npm-url]: https://www.npmjs.com/package/@simple-release/github-action
16+
17+
[node]: https://img.shields.io/node/v/@simple-release/github-action.svg
18+
[node-url]: https://nodejs.org
19+
20+
[deps]: https://img.shields.io/librariesio/release/npm/@simple-release/github-action
21+
[deps-url]: https://libraries.io/npm/@simple-release%2Fgithub-actions/tree
22+
23+
[size]: https://packagephobia.com/badge?p=@simple-release/github-action
24+
[size-url]: https://packagephobia.com/result?p=@simple-release/github-action
25+
26+
[build]: https://img.shields.io/github/actions/workflow/status/TrigenSoftware/simple-release/tests.yml?branch=main
27+
[build-url]: https://github.com/TrigenSoftware/simple-release/actions
28+
29+
[coverage]: https://coveralls.io/repos/github/TrigenSoftware/simple-release/badge.svg?branch=main
30+
[coverage-url]: https://coveralls.io/github/TrigenSoftware/simple-release?branch=main
31+
32+
A simple-release api for github action.
33+
34+
## Install
35+
36+
```bash
37+
# pnpm
38+
pnpm add @simple-release/github-action
39+
# yarn
40+
yarn add @simple-release/github-action
41+
# npm
42+
npm i @simple-release/github-action
43+
```
44+
45+
## Usage
46+
47+
```js
48+
import { getOctokit } from '@actions/github'
49+
import { load } from '@simple-release/config'
50+
import { ReleaserGithubAction, ifReleaseCommit } from '@simple-release/github-action'
51+
52+
const {
53+
project,
54+
releaser,
55+
...options
56+
} = await load({
57+
config: true,
58+
project: true
59+
})
60+
61+
// Create pull request with version bump
62+
await new Releaser({
63+
project,
64+
octokit: getOctokit(token),
65+
...releaser
66+
})
67+
.setOptions(options)
68+
.checkout()
69+
.fetchOptions()
70+
.bump()
71+
.commit()
72+
.push()
73+
.pullRequest()
74+
.run()
75+
76+
// Publish release and project
77+
await new Releaser({
78+
project,
79+
octokit: getOctokit(token),
80+
...releaser
81+
})
82+
.setOptions(options)
83+
.tag()
84+
.push()
85+
.release()
86+
.publish()
87+
.run(ifReleaseCommit)
88+
```
89+
90+
### fethchOptions
91+
92+
You can pass additional options to releaser via comment in your pull request. Your comment should start with `!simple-release/set-options` and contain JSON object with options. For example:
93+
94+
````
95+
!simple-release/set-options
96+
97+
```json
98+
{
99+
"bump": {
100+
"prerelease": "alpha"
101+
}
102+
}
103+
```
104+
````
105+
106+
To fetch and parse comments you should use `fetchOptions` step after `checkout` step.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"name": "@simple-release/github-action",
3+
"type": "module",
4+
"version": "1.0.0",
5+
"description": "A simple-release api for github action.",
6+
"author": {
7+
"name": "Dan Onoshko",
8+
"email": "[email protected]",
9+
"url": "https://github.com/dangreen"
10+
},
11+
"license": "MIT",
12+
"homepage": "https://github.com/TrigenSoftware/simple-release/tree/master/packages/github-action#readme",
13+
"funding": "https://ko-fi.com/dangreen",
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/TrigenSoftware/simple-release.git",
17+
"directory": "packages/github-action"
18+
},
19+
"bugs": {
20+
"url": "https://github.com/TrigenSoftware/simple-release/issues"
21+
},
22+
"keywords": [
23+
"simple-release",
24+
"github",
25+
"github-action",
26+
"release",
27+
"changelog"
28+
],
29+
"engines": {
30+
"node": ">=18"
31+
},
32+
"exports": "./src/index.ts",
33+
"publishConfig": {
34+
"exports": {
35+
"types": "./dist/index.d.ts",
36+
"import": "./dist/index.js"
37+
},
38+
"directory": "package",
39+
"linkDirectory": false
40+
},
41+
"files": [
42+
"dist"
43+
],
44+
"scripts": {
45+
"clear:package": "del ./package",
46+
"clear:dist": "del ./dist",
47+
"clear": "del ./package ./dist ./coverage",
48+
"prepublishOnly": "run build clear:package clean-publish",
49+
"postpublish": "pnpm clear:package",
50+
"build": "tsc -p tsconfig.build.json",
51+
"lint": "eslint --parser-options tsconfigRootDir:. '**/*.{js,ts}'",
52+
"test:types": "tsc --noEmit",
53+
"test": "run -p lint test:types"
54+
},
55+
"dependencies": {
56+
"@actions/github": "^6.0.1",
57+
"@simple-release/config": "workspace:^",
58+
"@simple-release/core": "workspace:^",
59+
"@simple-release/github": "workspace:^"
60+
},
61+
"devDependencies": {
62+
"@simple-release/pnpm": "workspace:^"
63+
}
64+
}

packages/github-action/src/_pr.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { getOctokit } from '@actions/github'
2+
import { load } from '@simple-release/config'
3+
import { ReleaserGithubAction } from './index.js'
4+
5+
const token = process.env.GITHUB_TOKEN!
6+
const {
7+
project,
8+
releaser: releaserOptions,
9+
...options
10+
} = await load({
11+
config: true,
12+
project: true
13+
})
14+
const releaser = new ReleaserGithubAction({
15+
project,
16+
octokit: getOctokit(token),
17+
...releaserOptions
18+
})
19+
.setOptions(options)
20+
.checkout()
21+
.fetchOptions()
22+
.bump()
23+
.commit()
24+
.push()
25+
.pullRequest()
26+
27+
await releaser.run()
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { getOctokit } from '@actions/github'
2+
import { load } from '@simple-release/config'
3+
import {
4+
ReleaserGithubAction,
5+
ifReleaseCommit
6+
} from './index.js'
7+
8+
const token = process.env.GITHUB_TOKEN!
9+
const {
10+
project,
11+
releaser: releaserOptions,
12+
...options
13+
} = await load({
14+
config: true,
15+
project: true
16+
})
17+
const releaser = new ReleaserGithubAction({
18+
project,
19+
octokit: getOctokit(token),
20+
...releaserOptions
21+
})
22+
.setOptions(options)
23+
.tag()
24+
.push()
25+
.release()
26+
// .publish()
27+
28+
await releaser.run(ifReleaseCommit)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
interface Comment {
2+
body?: string
3+
author_association: string
4+
}
5+
6+
const ALLOWED_AUTHOR_ASSOCIATIONS = [
7+
'OWNER',
8+
'COLLABORATOR',
9+
'MEMBER'
10+
]
11+
const JSON_START = '```json'
12+
const JSON_START_OFFSET = JSON_START.length
13+
const JSON_END = '```'
14+
const SET_OPTION_COMMAND = '!simple-release/set-options'
15+
16+
export function parseSetOptionsComment(comment: Comment): string | null {
17+
if (ALLOWED_AUTHOR_ASSOCIATIONS.includes(comment.author_association)) {
18+
const { body } = comment
19+
20+
if (body?.startsWith(SET_OPTION_COMMAND)) {
21+
const start = body.indexOf(JSON_START)
22+
const end = body.lastIndexOf(JSON_END)
23+
const json = body.substring(start + JSON_START_OFFSET, end).trim()
24+
25+
return json
26+
}
27+
}
28+
29+
return null
30+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { ReleaserGithubAction } from './releaser.js'
2+
3+
export async function ifReleaseCommit(releaser: ReleaserGithubAction) {
4+
const {
5+
gitClient,
6+
project
7+
} = releaser
8+
const message = await gitClient.exec('log', '-1', '--pretty=%B')
9+
const tags = await project.getTags()
10+
11+
return tags.length > 0 && message.startsWith('chore(release):')
12+
}

0 commit comments

Comments
 (0)