-
Notifications
You must be signed in to change notification settings - Fork 5
79 lines (71 loc) · 2.96 KB
/
check-submission.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
name: Check Submission
on:
pull_request_target:
branches: [ "main" ]
paths:
- 'plank-holders.md'
jobs:
check-submission:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- name: Checkout Target
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.base.repo.full_name }}
ref: main
path: target
- name: Checkout Source
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
path: source
- name: Check Submission
id: check_submission
run: >-
HASH_INPUT="${{ github.event.pull_request.user.login }}-${{ secrets.SALT1 }}-${{ secrets.SALT2 }}";
echo "Checking diff from ${{ github.event.pull_request.head.ref }} on ${{ github.event.pull_request.head.repo.full_name }}...";
SUBMISSION=`(diff target/plank-holders.md source/plank-holders.md || true) | awk '/\* @${{ github.event.pull_request.user.login }}/{ print $4 }'`;
CHECK=`echo -n "$HASH_INPUT" | openssl dgst -${{ secrets.ALGO }} | awk '/[a-z0-9]+/{ print $2 }'`;
RAW=`echo -n "$HASH_INPUT" | openssl dgst -${{ secrets.ALGO }}`;
if [[ "$SUBMISSION" =~ ^[a-zA-Z0-9]+$ ]]; then
echo "Confirming submission ($SUBMISSION) for ${{ github.event.pull_request.user.login }} equals check...";
echo "Check: $CHECK";
echo "Raw: $RAW";
if [[ "$SUBMISSION" = "$CHECK" ]]; then
echo "Submission match"
echo "RESULT=pass" >> "$GITHUB_OUTPUT";
echo "MESSAGE='🤩 Wow, you are an open source hero! Find a volunteer with the special White House badge to claim your fame!'" >> "$GITHUB_OUTPUT";
else
echo "Submission does not match"
echo "RESULT=fail" >> "$GITHUB_OUTPUT";
echo "MESSAGE='😔 Sorry, but that is not the right hash. Have you found all of the clues?'" >> "$GITHUB_OUTPUT";
fi
else
echo "Invalid submission"
echo "RESULT=fail" >> "$GITHUB_OUTPUT";
echo "MESSAGE='🤔 Sorry, but that hash does not look right. Have you found all of the clues?'" >> "$GITHUB_OUTPUT";
fi
- name: Post Message
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: ${{ steps.check_submission.outputs.MESSAGE }}
})
- name: End Job
env:
RESULT: ${{ steps.check_submission.outputs.RESULT }}
run: >-
echo "RESULT=$RESULT";
if [[ "$RESULT" = "pass" ]]; then
exit 0;
else
exit 1;
fi