Skip to content

Commit 93ed2e0

Browse files
committed
chore: test action
1 parent cdb8f23 commit 93ed2e0

File tree

9 files changed

+347
-0
lines changed

9 files changed

+347
-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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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: tsm --no-warnings ./packages/github-action/src/index.ts

.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
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: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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+
console.log({
21+
owner,
22+
repo,
23+
branch
24+
})
25+
process.exit(0)
26+
27+
await exec('git', [
28+
'config',
29+
'--global',
30+
'user.email',
31+
'github-actions[bot]@users.noreply.github.com'
32+
])
33+
await exec('git', [
34+
'config',
35+
'--global',
36+
'user.name',
37+
'github-actions[bot]'
38+
])
39+
40+
await exec('git', [
41+
'branch',
42+
'-D',
43+
branch
44+
])
45+
await exec('git', [
46+
'checkout',
47+
'-b',
48+
branch
49+
])
50+
51+
const project = new PnpmWorkspacesProject({
52+
mode: 'fixed'
53+
})
54+
const releaser = new Releaser(project)
55+
.bump()
56+
.commit()
57+
const { logger } = releaser
58+
59+
try {
60+
await releaser.run()
61+
} catch (error) {
62+
setFailed((error as Error).message)
63+
throw error
64+
}
65+
66+
if (project.versionUpdates.length) {
67+
logger.info('push', `Pushing changes to ${branch}...`)
68+
69+
await exec('git', [
70+
'push',
71+
'origin',
72+
branch,
73+
'--force'
74+
])
75+
76+
const octokit = getOctokit(token)
77+
const { data: [pr] } = await octokit.rest.pulls.list({
78+
owner,
79+
repo,
80+
head: `${owner}:${branch}`,
81+
state: 'open'
82+
})
83+
const [title] = project.getCommitMessage().split('\n')
84+
const body = `
85+
${project.versionUpdates.map(({ name, notes }) => `# ${name}\n\n${notes.trim()}`).join('\n\n')}
86+
87+
---
88+
This PR was generated with [simple-release](https://github.com/TrigenSoftware/simple-release).
89+
`
90+
91+
if (pr) {
92+
logger.info('pr', 'Updating existing pull request...')
93+
await octokit.rest.pulls.update({
94+
owner,
95+
repo,
96+
pull_number: pr.number,
97+
title,
98+
body
99+
})
100+
} else {
101+
logger.info('pr', 'Creating existing pull request...')
102+
103+
const { data: { default_branch } } = await octokit.rest.repos.get({
104+
owner,
105+
repo
106+
})
107+
108+
await octokit.rest.pulls.create({
109+
owner,
110+
repo,
111+
title,
112+
base: default_branch,
113+
head: branch,
114+
body
115+
})
116+
}
117+
}
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)