Skip to content

Commit 5a80c6a

Browse files
committed
💚 Alternate implement instead of actions/create-release
Signed-off-by: kei-g <km.8k6ce+github@gmail.com>
1 parent fa95fa9 commit 5a80c6a

File tree

2 files changed

+45
-25
lines changed

2 files changed

+45
-25
lines changed

.cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"asynciterable",
55
"autobuild",
66
"codeql",
7+
"commitish",
78
"devel",
89
"esbuild",
910
"linebreak",

.github/workflows/release.yml

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,56 @@ jobs:
88
uses: actions/checkout@v3
99
with:
1010
fetch-depth: 1
11-
- id: commit_summary
12-
name: Get commit summary
11+
- name: Create a release
1312
uses: actions/github-script@v6
1413
with:
1514
script: |
15+
const { owner, repo } = context.repo
16+
const { ref, sha } = context
17+
const version = ref.slice(11)
1618
const child_process = require('node:child_process')
17-
const { ref } = context
18-
core.setOutput('version', ref.slice(11))
19-
child_process.execSync(`git fetch --depth 1 origin +${ref}:${ref}`)
2019
child_process.exec(
21-
`git for-each-ref --format='%(contents)' ${ref}`,
22-
{},
23-
(err, stdout, stderr) => {
24-
const i = stdout.search(/Signed\-off\-by\:\ /g)
25-
if (i < 0)
26-
core.setFailed('There is no signature')
27-
else
28-
core.setOutput('message', stdout.slice(0, i))
29-
}
20+
`git fetch --depth 1 origin +${ref}:${ref}`,
21+
{}
22+
() => child_process.exec(
23+
`git for-each-ref --format='%(contents)' ${ref}`,
24+
{},
25+
async (err, stdout, stderr) => {
26+
if (err)
27+
return core.setFailed(err)
28+
const i = stdout.search(/^Signed\-off\-by\:\ /g)
29+
const j = stdout.search(/^\-{5}BEGIN\ PGP\ SIGNATURE\-{5}$/g)
30+
const body = i < 0 ? j < 0 ? stdout : stdout.slice(0, j) : stdout.slice(0, i)
31+
const response = await github.request(
32+
`POST /repos/${owner}/${repo}/releases`,
33+
{
34+
body,
35+
draft: false,
36+
name: `Version ${version}`,
37+
owner,
38+
prerelease: false,
39+
repo,
40+
tag_name: `v${version}`,
41+
target_commitish: sha,
42+
}
43+
)
44+
switch (response.status) {
45+
case 201:
46+
core.setOutput('result', 'success')
47+
break
48+
case 404:
49+
core.setFailed('Not Found if the discussion category name is invalid')
50+
break
51+
case 422:
52+
core.setFailed('Validation failed, or the endpoint has been spammed')
53+
break
54+
default:
55+
core.setFailed(`Unknown error, status=${response.status}`)
56+
break
57+
}
58+
}
59+
)
3060
)
31-
- env:
32-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33-
name: Create Release
34-
uses: actions/create-release@v1
35-
with:
36-
body: |
37-
${{ steps.commit_summary.outputs.message }}
38-
draft: false
39-
prerelease: false
40-
release_name: Version ${{ steps.commit_summary.outputs.version }}
41-
tag_name: v${{ steps.commit_summary.outputs.version }}
4261
npm:
4362
if: github.ref_type == 'tag'
4463
name: npm

0 commit comments

Comments
 (0)