-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yaml
59 lines (59 loc) · 2.31 KB
/
action.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
name: 'Verify PR Template is filled out'
description: 'Verifies that the PR description is not identical to the PR template, impliying that it wasnt filled out'
color: 'green'
inputs:
comment:
description: 'A message to comment on the PR if the template wasnt filled out'
required: false
fail:
description: 'Whether to fail if the PR description matches the template'
required: false
default: "true"
convert-to-draft:
description: 'Whether to convert the PR to a draft if the template wasnt filled out'
required: false
default: "false"
template-path:
description: 'The path of the PR template file to compare to'
required: false
default: "./docs/pull_request_template.md"
runs:
using: "composite"
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Read PR Template
id: template
uses: juliangruber/read-file-action@b549046febe0fe86f8cb4f93c24e284433f9ab58
with:
path: ${{ inputs.template-path }}
# This step is required because the PR body is CRLF, and the read file from the previous step is just LF
- name: clean pr content
shell: bash
id: clean
env:
# Needs to be stored in an ENV so that bash is aware it is a self-contained value and we don't need to worry about quotes
PR_BODY: ${{ github.event.pull_request.body }}
run: |
{
echo 'cleaned<<EOF'
echo "${PR_BODY}" | tr -d '\r'
echo EOF
} >> "$GITHUB_OUTPUT"
- name: Check equality and comment
if: inputs.comment && steps.template.outputs.content == steps.clean.outputs.cleaned
uses: mshick/add-pr-comment@b8f338c590a895d50bcbfa6c5859251edc8952fc
with:
message: ${{ inputs.comment }}
- name: Check equality and convert to draft
shell: bash
if: inputs.convert-to-draft && steps.template.outputs.content == steps.clean.outputs.cleaned
env:
GH_TOKEN: ${{ github.token }}
run: gh pr ready ${{ github.event.pull_request.number }} --undo
- name: Check equality and fail
if: inputs.fail && steps.template.outputs.content == steps.clean.outputs.cleaned
uses: actions/github-script@v3
with:
script: |
core.setFailed('Your PR body appears to be the same as the PR template file, please fill out the PR.')