|
1 |
| -# Usage: | `/usage` | `/usage` | Show usage message. | |
2 | 1 | name: usage command
|
3 | 2 | on:
|
4 | 3 | repository_dispatch:
|
|
7 | 6 | usage:
|
8 | 7 | runs-on: ubuntu-latest
|
9 | 8 | steps:
|
10 |
| - - uses: actions/checkout@v2 |
11 |
| - - name: Install yq |
12 |
| - run: | |
13 |
| - sudo wget -O /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/v4.6.3/yq_linux_amd64 |
14 |
| - sudo chmod a+x /usr/local/bin/yq |
15 |
| - - name: Update gh |
16 |
| - run: | |
17 |
| - # Current gh in ubuntu-latest doesn't support -F option |
18 |
| - sudo wget -O gh_1.8.1_linux_amd64.tar.gz https://github.com/cli/cli/releases/download/v1.8.1/gh_1.8.1_linux_amd64.tar.gz |
19 |
| - sudo tar xvfz gh_1.8.1_linux_amd64.tar.gz |
20 |
| - sudo cp gh_1.8.1_linux_amd64/bin/gh /usr/local/bin/gh |
21 |
| - sudo chmod a+x /usr/local/bin/gh |
22 |
| - - name: Show usage |
23 |
| - run: | |
24 |
| - wdir=".github/workflows/" |
25 |
| - dfile="slash-command-dispatch.yml" |
26 |
| - dpath="${wdir}${dfile}" |
27 |
| - query='.jobs.slashCommandDispatch.steps[0].with.commands' |
28 |
| -
|
29 |
| - function usage_msg() { |
30 |
| - echo '| Command | Example | Description |' |
31 |
| - echo '| --- | --- | --- |' |
32 |
| - while read cmd;do |
33 |
| - cpath="${wdir}command-${cmd}.yml" |
34 |
| - if [ -e "${cpath}" ];then |
35 |
| - grep '^# Usage: ' "${cpath}" | sed 's/# Usage: //' |
36 |
| - fi |
37 |
| - done <<< $(yq eval "${query}" "${dpath}" | sed '/^$/d') |
38 |
| - } |
39 |
| -
|
40 |
| - if [ -n "${PR_NUM}" ];then |
41 |
| - usage_msg | /usr/local/bin/gh pr comment "${PR_NUM}" -R ${REPO} -F - |
42 |
| - else |
43 |
| - usage_msg | /usr/local/bin/gh issue comment "${ISSUE_NUM}" -R ${REPO} -F - |
44 |
| - fi |
45 |
| - env: |
46 |
| - REPO: ${{ github.event.client_payload.github.payload.repository.full_name }} |
47 |
| - ISSUE_NUM: ${{ github.event.client_payload.github.payload.issue.number }} |
48 |
| - PR_NUM: ${{ github.event.client_payload.pull_request.number }} |
49 |
| - GITHUB_TOKEN: ${{secrets.PAT}} |
| 9 | + - uses: mkimuram/test-gha/plugins/usage@main |
0 commit comments