|
8 | 8 | uses: actions/checkout@v3
|
9 | 9 | with:
|
10 | 10 | fetch-depth: 1
|
11 |
| - - id: commit_summary |
12 |
| - name: Get commit summary |
| 11 | + - name: Create a release |
13 | 12 | uses: actions/github-script@v6
|
14 | 13 | with:
|
15 | 14 | script: |
|
| 15 | + const { owner, repo } = context.repo |
| 16 | + const { ref, sha } = context |
| 17 | + const version = ref.slice(11) |
16 | 18 | 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}`) |
20 | 19 | 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 | + ) |
30 | 60 | )
|
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 }} |
42 | 61 | npm:
|
43 | 62 | if: github.ref_type == 'tag'
|
44 | 63 | name: npm
|
|
0 commit comments