Skip to content

Commit 610c9f9

Browse files
committed
chore: test action
1 parent cdb8f23 commit 610c9f9

File tree

9 files changed

+342
-0
lines changed

9 files changed

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