-
Notifications
You must be signed in to change notification settings - Fork 7
109 lines (91 loc) · 3.85 KB
/
signature-test.yml
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
name: Signature Test
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
signature-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
pip install poetry
poetry install
- name: Check for specific string in PR title and creator
id: check_conditions
run: |
pr_title="${{ github.event.pull_request.title }}"
pr_creator="${{ github.event.pull_request.user.login }}"
echo "Pull Request title: $pr_title" > signaturetest.log
echo "Pull Request creator: $pr_creator" >> signaturetest.log
if [[ "$pr_title" == "[SignatureBot]"* ]]; then
echo "::set-output name=is_new_signature_pr::true"
echo "PR $pr_title Qualified" >> signaturetest.log
else
echo "::set-output name=is_new_signature_pr::false"
echo "PR $pr_title NOT Qualified" >> signaturetest.log
fi
env:
GH_TOKEN: ${{ secrets.DNSBOT_TOKEN }}
- name: Run signature test
if: steps.check_conditions.outputs.is_new_signature_pr == 'true'
id: signature_test
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
FILE=$(gh pr diff $PR_NUMBER --name-only | grep -v "signature_history.txt")
echo "Running signature test against: $FILE" >> signaturetest.log
OUTPUT=$(poetry run python3 baddns/scripts/signaturetest.py $FILE)
echo "$OUTPUT" > output.json
echo "Run finished with this output: $OUTPUT" >> signaturetest.log
echo "::set-output name=result::$OUTPUT"
SIGNATURE_PASS=$(echo "$OUTPUT" | jq -r '.signature_pass')
if [ "$SIGNATURE_PASS" == "true" ]
then
echo "Signature test passed, adding 'tests-passed' label to PR..." >> signaturetest.log
gh pr edit $PR_NUMBER --remove-label "tests-failed"
gh pr edit $PR_NUMBER --add-label "tests-passed"
else
echo "Signature test failed, adding 'tests-failed' label to PR..." >> signaturetest.log
gh pr edit $PR_NUMBER --remove-label "tests-passed"
gh pr edit $PR_NUMBER --add-label "tests-failed"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Post result comment
if: always() && steps.check_conditions.outputs.is_new_signature_pr == 'true'
run: |
output=$(cat output.json)
signature_pass=$(echo $output | jq -r '.signature_pass')
match_table=$(echo $output | jq -r '.match_table')
error=$(echo $output | jq -r '.error')
if [[ "$signature_pass" == "true" ]]; then
emoji=":heavy_check_mark:"
else
emoji=":x:"
fi
comment="**Test results**:
Signature Pass: **$signature_pass** $emoji"
if [[ "$match_table" != "{}" ]]; then
comment+=$'\n\nMatch Table:\n\n| Domain | Match |\n| --- | --- |'
while IFS="|" read -r domain match; do
comment+=$'\n| '"$domain"' | '"$match"' |'
done < <(echo "$match_table" | jq -r 'to_entries[] | "\(.key)|\(.value)"')
fi
if [[ "$signature_pass" == "false" ]]; then
comment+="
Error: **$error**"
fi
echo "Attempting to add comment to PR..." >> signaturetest.log
gh pr comment "${{ github.event.pull_request.number }}" --body "$comment"
env:
GH_TOKEN: ${{ secrets.DNSBOT_TOKEN }}
- name: Upload Signature Test Log
uses: actions/upload-artifact@v4
if: always()
with:
name: signature-test-log
path: signaturetest.log