Skip to content

Commit 232dbcd

Browse files
README関連修正 (#103)
* README修正 * action.ymlを元にREADMEを生成する * token周り修正 * 条件修正 * inputsの順番変更 * README修正 (#108) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent d87153a commit 232dbcd

4 files changed

Lines changed: 128 additions & 16 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
name: update-readme
3+
4+
on:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
10+
jobs:
11+
update-readme:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
pull-requests: write
16+
steps:
17+
- uses: actions/checkout@v3.0.2
18+
with:
19+
fetch-depth: 0
20+
ref: ${{ github.event.pull_request.head.sha }}
21+
- uses: actions/setup-node@v3.3.0
22+
with:
23+
cache: npm
24+
- run: npm ci --prefer-offline
25+
- run: echo "DESCRIPTION=$(yq '.description' action.yml)" >> "${GITHUB_ENV}"
26+
- name: Get inputs markdown
27+
id: get_inputs_markdown
28+
uses: actions/github-script@v6.1.0
29+
env:
30+
HEAD_REF: ${{github.event.pull_request.head.ref}}
31+
with:
32+
github-token: ${{secrets.GITHUB_TOKEN}}
33+
result-encoding: string
34+
script: |
35+
const fs = require('fs')
36+
const yaml = require('js-yaml')
37+
38+
const yml_file = yaml.load(fs.readFileSync('action.yml', 'utf8'))
39+
const inputs = yml_file.inputs
40+
const rows = ['| 引数名 | 説明 | 必須 |', '|:---:|:---:|:---:|']
41+
42+
for (const input_name of Object.keys(inputs)) {
43+
let row = `| ${input_name} | ${inputs[input_name].description} | `
44+
45+
if (inputs[input_name].default === undefined && inputs[input_name].required) {
46+
row += 'O'
47+
}
48+
49+
row += ' |'
50+
rows.push(row)
51+
}
52+
53+
return rows.join("\n")
54+
- env:
55+
DESCRIPTION: ${{env.DESCRIPTION}}
56+
INPUTS: ${{steps.get_inputs_markdown.outputs.result}}
57+
run: envsubst < README.template.md > README.md
58+
- uses: ./
59+
with:
60+
github-token: ${{secrets.GITHUB_TOKEN}}
61+
branch-name-prefix: fix-readme
62+
pr-title-prefix: README修正
63+
pr-description-prefix: READMEを修正しました。
64+
repo-name: ${{ github.event.pull_request.head.repo.full_name }}

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# actions-diff-pr-management
22

3-
PRのブランチに対して、フォーマッタによって修正された結果を、PRにするGitHub Actionsです。
3+
PRのブランチに対して、フォーマッタを実行した結果をPRにするGitHub Actionsです。
44

55
本Actionsを使わずにフォーマットを修正した場合、自動的にPRを閉じます。
66

@@ -38,13 +38,13 @@ jobs:
3838
3939
## 引数
4040
41-
| 引数名 | 説明 | 必須 |
42-
|:---------------------:|:-------------------------------------------------------:|:---:|
43-
| github-token | GitHubのトークン。 | O |
44-
| repo-name | リポジトリ名。 `pull_request` 以外のトリガーも設定している場合はリポジトリ名を決め打ちで入力。 | O |
45-
| branch-name-prefix | branch名の接頭語。 | |
46-
| pr-title-prefix | PRのタイトルの接頭語。 | |
47-
| pr-description-prefix | 本文の接頭語。 | |
41+
| 引数名 | 説明 | 必須 |
42+
|:---:|:---:|:---:|
43+
| github-token | GitHubのトークン。 | O |
44+
| repo-name | リポジトリ名。 `pull_request` 以外のトリガーも設定している場合はリポジトリ名を決め打ちで入力。 | O |
45+
| branch-name-prefix | branch名の接頭語。 | |
46+
| pr-title-prefix | PRのタイトルの接頭語。 | |
47+
| pr-description-prefix | 本文の接頭語。 | |
4848

4949
## 開発
5050

README.template.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# actions-diff-pr-management
2+
3+
${DESCRIPTION}
4+
5+
本Actionsを使わずにフォーマットを修正した場合、自動的にPRを閉じます。
6+
7+
## 注意点
8+
9+
元のPRを閉じた場合、本Actionsが立てたPRは残ります。
10+
このような場合、 <https://github.com/dev-hato/actions-close-pr> を併用することで自動的にPRを閉じることができます。
11+
12+
## 使い方
13+
14+
```yaml
15+
on:
16+
pull_request:
17+
18+
jobs:
19+
diff-pr-management:
20+
runs-on: ubuntu-latest
21+
if: github.event_name == 'pull_request'
22+
steps:
23+
- uses: actions/checkout@v3
24+
with:
25+
fetch-depth: 0
26+
ref: ${{ github.event.pull_request.head.sha }}
27+
- run: hoge fmt # FIXME フォーマッタを走らせる
28+
- uses: dev-hato/actions-diff-pr-management@v1
29+
with:
30+
github-token: ${{secrets.GITHUB_TOKEN}}
31+
repo-name: ${{ github.event.pull_request.head.repo.full_name }}
32+
```
33+
34+
## 例
35+
36+
* 元のPR: <https://github.com/dev-hato/actions-diff-pr-management/pull/96>
37+
* 本Actionsによって作成されたPR: <https://github.com/dev-hato/actions-diff-pr-management/pull/98>
38+
39+
## 引数
40+
41+
${INPUTS}
42+
43+
## 開発
44+
45+
### 設定
46+
47+
<https://pre-commit.com/> の手順に従って `pre-commit` をインストールします。
48+
これにより、コミット時にクレデンシャルが含まれていないかの検査が行われるようになります。

action.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
name: 'diff-pr-management'
22
author: 'dev-hato Development Team'
3-
description: '差分があればPRを作り、差分がなければPRを閉じます'
3+
description: 'PRのブランチに対して、フォーマッタを実行した結果をPRにするGitHub Actionsです。'
44
inputs:
55
github-token: # id of input
6-
description: 'GITHUB_TOKEN'
6+
description: 'GitHubのトークン。'
7+
required: true
8+
repo-name:
9+
description: 'リポジトリ名。 `pull_request` 以外のトリガーも設定している場合はリポジトリ名を決め打ちで入力。'
710
required: true
811
branch-name-prefix:
9-
description: 'Prefix of PR branch name'
12+
description: 'branch名の接頭語。'
1013
required: true
1114
default: fix
1215
pr-title-prefix:
13-
description: 'Prefix of PR title'
16+
description: 'PRのタイトルの接頭語。'
1417
required: true
1518
default: fix
1619
pr-description-prefix:
17-
description: 'Prefix of PR description'
20+
description: '本文の接頭語。'
1821
required: true
1922
default: ""
20-
repo-name:
21-
description: 'Repository name'
22-
required: true
2323
runs:
2424
using: "composite"
2525
steps:

0 commit comments

Comments
 (0)