Skip to content

Commit fa6929a

Browse files
committed
Move logics to action.yml
Signed-off-by: Masaki Kimura <[email protected]>
1 parent 0ea9f99 commit fa6929a

20 files changed

+382
-168
lines changed

.github/workflows/command-assign.yml

+7-22
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,10 @@ jobs:
77
assign:
88
runs-on: ubuntu-latest
99
steps:
10-
- name: Assign to issue or pr
11-
run: |
12-
if [ -n "${ARGS}" ];then
13-
i=0
14-
for person in ${ARGS};do
15-
if [ $i -ne 0 ];then
16-
people="${people}, "
17-
fi
18-
people="${people}\"${person}\""
19-
i=`expr $i + 1`
20-
done
21-
else
22-
people="\"${{ github.actor }}\""
23-
fi
24-
25-
echo "{\"assignees\":[${people}]}" | \
26-
gh api repos/${REPO}/issues/${ISSUE_NUM}/assignees -X POST --input -
27-
env:
28-
REPO: ${{ github.event.client_payload.github.payload.repository.full_name }}
29-
ISSUE_NUM: ${{ github.event.client_payload.github.payload.issue.number }}
30-
ARGS: ${{ github.event.client_payload.slash_command.args.unnamed.all }}
31-
GITHUB_TOKEN: ${{secrets.PAT}}
10+
- uses: mkimuram/test-gha/plugins/assign@main
11+
with:
12+
repo: ${{ github.event.client_payload.github.payload.repository.full_name }}
13+
issue_num: ${{ github.event.client_payload.github.payload.issue.number }}
14+
args: ${{ github.event.client_payload.slash_command.args.unnamed.all }}
15+
actor: ${{ github.actor }}
16+
token: ${{secrets.PAT}}

.github/workflows/command-close.yml

+6-12
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,9 @@ jobs:
77
close:
88
runs-on: ubuntu-latest
99
steps:
10-
- name: Close issue or pr
11-
run: |
12-
if [ -n "${PR_NUM}" ];then
13-
gh pr close "${PR_NUM}" -R ${REPO}
14-
else
15-
gh issue close ${ISSUE_NUM} -R ${REPO}
16-
fi
17-
env:
18-
REPO: ${{ github.event.client_payload.github.payload.repository.full_name }}
19-
ISSUE_NUM: ${{ github.event.client_payload.github.payload.issue.number }}
20-
PR_NUM: ${{ github.event.client_payload.pull_request.number }}
21-
GITHUB_TOKEN: ${{secrets.PAT}}
10+
- uses: mkimuram/test-gha/plugins/close@main
11+
with:
12+
repo: ${{ github.event.client_payload.github.payload.repository.full_name }}
13+
issue_num: ${{ github.event.client_payload.github.payload.issue.number }}
14+
pr_num: ${{ github.event.client_payload.pull_request.number }}
15+
token: ${{secrets.PAT}}

.github/workflows/command-harray.yml

-15
This file was deleted.

.github/workflows/command-kind.yml

+6-14
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,9 @@ jobs:
77
kind:
88
runs-on: ubuntu-latest
99
steps:
10-
- name: Add kind label to issue or pr
11-
run: |
12-
# args should not be empty
13-
[ -n "${ARGS}" ] || false
14-
# args should only contain one value
15-
[[ "${ARGS}" != *" "* ]] || false
16-
label="kind/${ARGS}"
17-
echo "{\"labels\":[\"${label}\"]}" | \
18-
gh api repos/${REPO}/issues/${ISSUE_NUM}/labels -X POST --input -
19-
env:
20-
REPO: ${{ github.event.client_payload.github.payload.repository.full_name }}
21-
ISSUE_NUM: ${{ github.event.client_payload.github.payload.issue.number }}
22-
ARGS: ${{ github.event.client_payload.slash_command.args.unnamed.all }}
23-
GITHUB_TOKEN: ${{secrets.PAT}}
10+
- uses: mkimuram/test-gha/plugins/kind@main
11+
with:
12+
repo: ${{ github.event.client_payload.github.payload.repository.full_name }}
13+
issue_num: ${{ github.event.client_payload.github.payload.issue.number }}
14+
args: ${{ github.event.client_payload.slash_command.args.unnamed.all }}
15+
token: ${{secrets.PAT}}

.github/workflows/command-pony.yml

+6-14
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,9 @@ jobs:
77
pony:
88
runs-on: ubuntu-latest
99
steps:
10-
- name: Show a pony image
11-
run: |
12-
img=$(curl -s 'https://theponyapi.com/api/v1/pony/random' | jq '.pony.representations.small')
13-
msg="<img src=${img} width=\"150\">"
14-
if [ -n "${PR_NUM}" ];then
15-
gh pr comment "${PR_NUM}" -R ${REPO} -b "${msg}"
16-
else
17-
gh issue comment "${ISSUE_NUM}" -R ${REPO} -b "${msg}"
18-
fi
19-
env:
20-
REPO: ${{ github.event.client_payload.github.payload.repository.full_name }}
21-
ISSUE_NUM: ${{ github.event.client_payload.github.payload.issue.number }}
22-
PR_NUM: ${{ github.event.client_payload.pull_request.number }}
23-
GITHUB_TOKEN: ${{secrets.PAT}}
10+
- uses: mkimuram/test-gha/plugins/pony@main
11+
with:
12+
repo: ${{ github.event.client_payload.github.payload.repository.full_name }}
13+
issue_num: ${{ github.event.client_payload.github.payload.issue.number }}
14+
pr_num: ${{ github.event.client_payload.pull_request.number }}
15+
token: ${{secrets.PAT}}

.github/workflows/command-remove-kind.yml

+6-13
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,9 @@ jobs:
77
remove-kind:
88
runs-on: ubuntu-latest
99
steps:
10-
- name: Remove kind label from issue or pr
11-
run: |
12-
# args should not be empty
13-
[ -n "${ARGS}" ] || false
14-
# args should only contain one value
15-
[[ "${ARGS}" != *" "* ]] || false
16-
label="kind/${ARGS}"
17-
gh api repos/${REPO}/issues/${ISSUE_NUM}/labels/${label} -X DELETE
18-
env:
19-
REPO: ${{ github.event.client_payload.github.payload.repository.full_name }}
20-
ISSUE_NUM: ${{ github.event.client_payload.github.payload.issue.number }}
21-
ARGS: ${{ github.event.client_payload.slash_command.args.unnamed.all }}
22-
GITHUB_TOKEN: ${{secrets.PAT}}
10+
- uses: mkimuram/test-gha/plugins/remove-kind@main
11+
with:
12+
repo: ${{ github.event.client_payload.github.payload.repository.full_name }}
13+
issue_num: ${{ github.event.client_payload.github.payload.issue.number }}
14+
args: ${{ github.event.client_payload.slash_command.args.unnamed.all }}
15+
token: ${{secrets.PAT}}

.github/workflows/command-reopen.yml

+6-12
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,9 @@ jobs:
77
reopen:
88
runs-on: ubuntu-latest
99
steps:
10-
- name: Reopen issue or pr
11-
run: |
12-
if [ -n "${PR_NUM}" ];then
13-
gh pr reopen "${PR_NUM}" -R ${REPO}
14-
else
15-
gh issue reopen ${ISSUE_NUM} -R ${REPO}
16-
fi
17-
env:
18-
REPO: ${{ github.event.client_payload.github.payload.repository.full_name }}
19-
ISSUE_NUM: ${{ github.event.client_payload.github.payload.issue.number }}
20-
PR_NUM: ${{ github.event.client_payload.pull_request.number }}
21-
GITHUB_TOKEN: ${{secrets.PAT}}
10+
- uses: mkimuram/test-gha/plugins/reopen@main
11+
with:
12+
repo: ${{ github.event.client_payload.github.payload.repository.full_name }}
13+
issue_num: ${{ github.event.client_payload.github.payload.issue.number }}
14+
pr_num: ${{ github.event.client_payload.pull_request.number }}
15+
token: ${{secrets.PAT}}

.github/workflows/command-retest.yml

+5-18
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,8 @@ jobs:
77
retest:
88
runs-on: ubuntu-latest
99
steps:
10-
- name: Retest jobs
11-
run: |
12-
# TODO: make workflow_id auto detect and allow multiple ones
13-
workflow_id="test.yml"
14-
if [ -n "${SHA}" ];then
15-
run_id=$(gh api repos/${REPO}/actions/workflows/${workflow_id}/runs | \
16-
jq '.workflow_runs[] | select(.head_sha=="'${SHA}'") | .id')
17-
echo ${run_id}
18-
if [ -n "${run_id}" ];then
19-
# TODO: rerun only for failed jobs
20-
gh api repos/${REPO}/actions/runs/${run_id}/rerun -X POST
21-
fi
22-
fi
23-
env:
24-
REPO: ${{ github.event.client_payload.github.payload.repository.full_name }}
25-
SHA: ${{ github.event.client_payload.pull_request.head.sha }}
26-
GITHUB_TOKEN: ${{secrets.PAT}}
27-
10+
- uses: mkimuram/test-gha/plugins/retest@main
11+
with:
12+
repo: ${{ github.event.client_payload.github.payload.repository.full_name }}
13+
sha: ${{ github.event.client_payload.pull_request.head.sha }}
14+
token: ${{secrets.PAT}}
+8-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Usage: | `/unassgin` | `/unassign`<br> `/unassign spongebob patrick` | Unassigns assignee(s) from the PR. |
1+
# Usage: | `/unassign` | `/unassign`<br> `/unassign spongebob patrick` | Unassigns assignee(s) from the PR. |
22
name: unassign command
33
on:
44
repository_dispatch:
@@ -7,25 +7,10 @@ jobs:
77
unassign:
88
runs-on: ubuntu-latest
99
steps:
10-
- name: Unassign from issue or pr
11-
run: |
12-
if [ -n "${ARGS}" ];then
13-
i=0
14-
for person in ${ARGS};do
15-
if [ $i -ne 0 ];then
16-
people="${people}, "
17-
fi
18-
people="${people}\"${person}\""
19-
i=`expr $i + 1`
20-
done
21-
else
22-
people="\"${{ github.actor }}\""
23-
fi
24-
25-
echo "{\"assignees\":[${people}]}" | \
26-
gh api repos/${REPO}/issues/${ISSUE_NUM}/assignees -X DELETE --input -
27-
env:
28-
REPO: ${{ github.event.client_payload.github.payload.repository.full_name }}
29-
ISSUE_NUM: ${{ github.event.client_payload.github.payload.issue.number }}
30-
ARGS: ${{ github.event.client_payload.slash_command.args.unnamed.all }}
31-
GITHUB_TOKEN: ${{secrets.PAT}}
10+
- uses: mkimuram/test-gha/plugins/unassign@main
11+
with:
12+
repo: ${{ github.event.client_payload.github.payload.repository.full_name }}
13+
issue_num: ${{ github.event.client_payload.github.payload.issue.number }}
14+
args: ${{ github.event.client_payload.slash_command.args.unnamed.all }}
15+
actor: ${{ github.actor }}
16+
token: ${{secrets.PAT}}

.github/workflows/command-woof.yml

+6-24
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,9 @@ jobs:
77
woof:
88
runs-on: ubuntu-latest
99
steps:
10-
- name: Show a dog image
11-
run: |
12-
for i in $(seq 20);do
13-
res=$(curl -s 'https://random.dog/woof.json?filter=mp4,webm')
14-
size=$(echo ${res} | jq '.fileSizeBytes')
15-
img=$(echo ${res} | jq '.url')
16-
if [ "$size" -lt "$(( 1024 * 1024 ))" ];then
17-
echo "Image:$img is good size($size)"
18-
break
19-
else
20-
echo "Image:$img too big($size)"
21-
fi
22-
done
23-
msg="<img src=${img} width=\"150\">"
24-
if [ -n "${PR_NUM}" ];then
25-
gh pr comment "${PR_NUM}" -R ${REPO} -b "${msg}"
26-
else
27-
gh issue comment "${ISSUE_NUM}" -R ${REPO} -b "${msg}"
28-
fi
29-
env:
30-
REPO: ${{ github.event.client_payload.github.payload.repository.full_name }}
31-
ISSUE_NUM: ${{ github.event.client_payload.github.payload.issue.number }}
32-
PR_NUM: ${{ github.event.client_payload.pull_request.number }}
33-
GITHUB_TOKEN: ${{secrets.PAT}}
10+
- uses: mkimuram/test-gha/plugins/woof@main
11+
with:
12+
repo: ${{ github.event.client_payload.github.payload.repository.full_name }}
13+
issue_num: ${{ github.event.client_payload.github.payload.issue.number }}
14+
pr_num: ${{ github.event.client_payload.pull_request.number }}
15+
token: ${{secrets.PAT}}

.github/workflows/slash-command-dispatch.yml

-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ jobs:
2222
meow
2323
woof
2424
pony
25-
hooray
2625
ensure-labels

plugins/assign/action.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: 'Assign'
2+
description: 'Assign to issue or pr'
3+
inputs:
4+
repo:
5+
description: 'Repository name to assign'
6+
required: true
7+
issue_num:
8+
description: 'Issue number to assign'
9+
required: true
10+
args:
11+
description: 'Arguments for slash command'
12+
required: false
13+
actor:
14+
description: 'Github actor'
15+
required: false
16+
token:
17+
description: 'GITHUB_TOKEN to run this action'
18+
required: true
19+
runs:
20+
using: "composite"
21+
steps:
22+
- name: Assign to issue or pr
23+
shell: bash
24+
run: |
25+
if [ -n "${ARGS}" ];then
26+
i=0
27+
for person in ${ARGS};do
28+
if [ $i -ne 0 ];then
29+
people="${people}, "
30+
fi
31+
people="${people}\"${person}\""
32+
i=`expr $i + 1`
33+
done
34+
else
35+
people="\"${{ github.actor }}\""
36+
fi
37+
38+
echo "{\"assignees\":[${people}]}" | \
39+
gh api repos/${REPO}/issues/${ISSUE_NUM}/assignees -X POST --input -
40+
env:
41+
REPO: ${{ inputs.repo }}
42+
ISSUE_NUM: ${{ inputs.issue_num }}
43+
ARGS: ${{ inputs.args }}
44+
ACTOR: ${{ inputs.actor }}
45+
GITHUB_TOKEN: ${{ inputs.token }}

plugins/close/action.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: 'Close'
2+
description: 'Close issue or pr'
3+
inputs:
4+
repo:
5+
description: 'Repository name to close'
6+
required: true
7+
issue_num:
8+
description: 'Issue number to close'
9+
required: true
10+
pr_num:
11+
description: 'PR number to close'
12+
required: false
13+
token:
14+
description: 'GITHUB_TOKEN to run this action'
15+
required: true
16+
runs:
17+
using: "composite"
18+
steps:
19+
- name: Close issue or pr
20+
shell: bash
21+
run: |
22+
if [ -n "${PR_NUM}" ];then
23+
gh pr close "${PR_NUM}" -R "${REPO}"
24+
else
25+
gh issue close "${ISSUE_NUM}" -R "${REPO}"
26+
fi
27+
env:
28+
REPO: ${{ inputs.repo }}
29+
ISSUE_NUM: ${{ inputs.issue_num }}
30+
PR_NUM: ${{ inputs.pr_num }}
31+
GITHUB_TOKEN: ${{ inputs.token }}

plugins/kind/action.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: 'Kind'
2+
description: 'Add kind label to issue or pr'
3+
inputs:
4+
repo:
5+
description: 'Repository name to add kind label'
6+
required: true
7+
issue_num:
8+
description: 'Issue number to add kind label'
9+
required: true
10+
args:
11+
description: 'Arguments for slash command'
12+
required: true
13+
token:
14+
description: 'GITHUB_TOKEN to run this action'
15+
required: true
16+
runs:
17+
using: "composite"
18+
steps:
19+
- name: Add kind label to issue or pr
20+
shell: bash
21+
run: |
22+
# args should not be empty
23+
[ -n "${ARGS}" ] || false
24+
# args should only contain one value
25+
[[ "${ARGS}" != *" "* ]] || false
26+
label="kind/${ARGS}"
27+
echo "{\"labels\":[\"${label}\"]}" | \
28+
gh api repos/${REPO}/issues/${ISSUE_NUM}/labels -X POST --input -
29+
env:
30+
REPO: ${{ inputs.repo }}
31+
ISSUE_NUM: ${{ inputs.issue_num }}
32+
ARGS: ${{ inputs.args }}
33+
GITHUB_TOKEN: ${{ inputs.token }}

0 commit comments

Comments
 (0)