-
Notifications
You must be signed in to change notification settings - Fork 42
109 lines (89 loc) · 3.67 KB
/
Copy pathsignature-test.yml
File metadata and controls
109 lines (89 loc) · 3.67 KB
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]
permissions:
pull-requests: write
contents: read
jobs:
signature-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v6
- name: Set up Python
run: uv python install 3.10
- name: Install dependencies
run: uv sync --group dev
- name: Check for specific string in PR title and creator
run: |
pr_title=$(printf '%q' "${{ 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 "IS_NEW_SIGNATURE_PR=true" >> "$GITHUB_ENV"
echo "PR $pr_title Qualified" >> signaturetest.log
else
echo "IS_NEW_SIGNATURE_PR=false" >> "$GITHUB_ENV"
echo "PR $pr_title NOT Qualified" >> signaturetest.log
fi
env:
GH_TOKEN: ${{ secrets.DNSBOT_TOKEN }}
- name: Run signature test
if: env.IS_NEW_SIGNATURE_PR == 'true'
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
FILE=$(gh pr diff "$PR_NUMBER" --name-only | grep -v "signature_history.txt" || true)
if [[ -z "$FILE" ]]; then
echo "No valid files to process." >> signaturetest.log
exit 1
fi
echo "Running signature test against: $FILE" >> signaturetest.log
OUTPUT=$(uv run python3 baddns/scripts/signaturetest.py "$FILE" | jq .)
echo "$OUTPUT" > output.json
echo "Run finished with this output: $OUTPUT" >> signaturetest.log
echo "SIGNATURE_TEST_RESULT=$OUTPUT" >> "$GITHUB_ENV"
SIGNATURE_PASS=$(echo "$OUTPUT" | jq -r '.signature_pass')
if [[ "$SIGNATURE_PASS" == "true" ]]; then
gh pr edit "$PR_NUMBER" --remove-label "tests-failed" --add-label "tests-passed"
else
gh pr edit "$PR_NUMBER" --remove-label "tests-passed" --add-label "tests-failed"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Post result comment
if: always() && env.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