Skip to content

Commit 4f76ebc

Browse files
committed
chore: test action
1 parent cdb8f23 commit 4f76ebc

File tree

10 files changed

+353
-0
lines changed

10 files changed

+353
-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: 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/index.ts
26+
env:
27+
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: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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+
.bump()
59+
.commit()
60+
const { logger } = releaser
61+
62+
try {
63+
await releaser.run()
64+
} catch (error) {
65+
setFailed((error as Error).message)
66+
throw error
67+
}
68+
69+
if (project.versionUpdates.length) {
70+
logger.info('push', `Pushing changes to ${branch}...`)
71+
72+
await exec('git', [
73+
'push',
74+
'origin',
75+
branch,
76+
'--force'
77+
])
78+
79+
const octokit = getOctokit(token)
80+
const { data: [pr] } = await octokit.rest.pulls.list({
81+
owner,
82+
repo,
83+
head: `${owner}:${branch}`,
84+
state: 'open'
85+
})
86+
const [title] = project.getCommitMessage().split('\n')
87+
const body = `
88+
${project.versionUpdates.map(({ name, notes }) => `# ${name}\n\n${notes.trim()}`).join('\n\n')}
89+
90+
---
91+
This PR was generated with [simple-release](https://github.com/TrigenSoftware/simple-release).
92+
`
93+
94+
if (pr) {
95+
logger.info('pr', 'Updating existing pull request...')
96+
await octokit.rest.pulls.update({
97+
owner,
98+
repo,
99+
pull_number: pr.number,
100+
title,
101+
body
102+
})
103+
} else {
104+
logger.info('pr', 'Creating existing pull request...')
105+
106+
const { data: { default_branch } } = await octokit.rest.repos.get({
107+
owner,
108+
repo
109+
})
110+
111+
await octokit.rest.pulls.create({
112+
owner,
113+
repo,
114+
title,
115+
base: default_branch,
116+
head: branch,
117+
body
118+
})
119+
}
120+
}
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)