Skip to content

Commit 97c23b4

Browse files
committed
chore: test action
1 parent cdb8f23 commit 97c23b4

File tree

10 files changed

+364
-0
lines changed

10 files changed

+364
-0
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/src/releaser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Logger } from './logger.js'
1313
export interface ReleaserOptions {
1414
dryRun?: boolean
1515
silent?: boolean
16+
verbose?: boolean
1617
logger?: Logger
1718
}
1819

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+
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import {
2+
getInput,
3+
setFailed
4+
} from '@actions/core'
5+
import {
6+
context,
7+
getOctokit
8+
} from '@actions/github'
9+
import { exec } from '@actions/exec'
10+
import { Releaser } from '@simple-release/core'
11+
import { PnpmWorkspacesProject } from '@simple-release/pnpm'
12+
13+
const {
14+
owner,
15+
repo
16+
} = context.repo
17+
const branch = getInput('branch') || 'simple-release'
18+
const token = (getInput('token') || process.env.GITHUB_TOKEN)!
19+
20+
await exec('git', [
21+
'config',
22+
'--global',
23+
'user.email',
24+
'github-actions[bot]@users.noreply.github.com'
25+
])
26+
await exec('git', [
27+
'config',
28+
'--global',
29+
'user.name',
30+
'github-actions[bot]'
31+
])
32+
33+
// await exec('git', [
34+
// 'fetch',
35+
// '--prune',
36+
// '--unshallow',
37+
// '--tags',
38+
// 'origin',
39+
// 'HEAD'
40+
// ])
41+
await exec('git', [
42+
'branch',
43+
'-D',
44+
branch
45+
], {
46+
ignoreReturnCode: true
47+
})
48+
await exec('git', [
49+
'checkout',
50+
'-b',
51+
branch
52+
])
53+
54+
const project = new PnpmWorkspacesProject({
55+
mode: 'fixed'
56+
})
57+
const releaser = new Releaser(project, {
58+
verbose: true
59+
})
60+
.bump({
61+
byProject: {
62+
'simple-github-release': {
63+
firstRelease: false
64+
}
65+
}
66+
})
67+
.commit()
68+
const { logger } = releaser
69+
70+
try {
71+
await releaser.run()
72+
} catch (error) {
73+
setFailed((error as Error).message)
74+
throw error
75+
}
76+
77+
if (project.versionUpdates.length) {
78+
logger.info('push', `Pushing changes to ${branch}...`)
79+
80+
await exec('git', [
81+
'push',
82+
'origin',
83+
branch,
84+
'--force'
85+
])
86+
87+
const octokit = getOctokit(token)
88+
const { data: [pr] } = await octokit.rest.pulls.list({
89+
owner,
90+
repo,
91+
head: `${owner}:${branch}`,
92+
state: 'open'
93+
})
94+
const [title] = project.getCommitMessage().split('\n')
95+
const body = `
96+
${project.versionUpdates.map(({ name, notes }) => `# ${name}\n\n${notes.trim()}`).join('\n\n')}
97+
98+
---
99+
This PR was generated with [simple-release](https://github.com/TrigenSoftware/simple-release).
100+
`
101+
102+
if (pr) {
103+
logger.info('pr', 'Updating existing pull request...')
104+
await octokit.rest.pulls.update({
105+
owner,
106+
repo,
107+
pull_number: pr.number,
108+
title,
109+
body
110+
})
111+
} else {
112+
logger.info('pr', 'Creating existing pull request...')
113+
114+
const { data: { default_branch } } = await octokit.rest.repos.get({
115+
owner,
116+
repo
117+
})
118+
119+
await octokit.rest.pulls.create({
120+
owner,
121+
repo,
122+
title,
123+
base: default_branch,
124+
head: branch,
125+
body
126+
})
127+
}
128+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "dist"
5+
},
6+
"include": [
7+
"src"
8+
],
9+
"exclude": [
10+
"**/*.spec.ts"
11+
]
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.build.json",
3+
"include": [
4+
"src"
5+
],
6+
"exclude": []
7+
}

0 commit comments

Comments
 (0)