|
| 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 }} |
0 commit comments