Skip to content

Commit 70798c9

Browse files
committed
chore: test action
1 parent cdb8f23 commit 70798c9

File tree

9 files changed

+345
-0
lines changed

9 files changed

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