-
Notifications
You must be signed in to change notification settings - Fork 0
76 lines (65 loc) · 2.33 KB
/
tests.yml
File metadata and controls
76 lines (65 loc) · 2.33 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
name: Run Tests
on:
pull_request:
types: [opened, synchronize]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout Student Code
uses: actions/checkout@v3
- name: Checkout Test Repo
env:
TOKEN: ${{ secrets.TEST_REPO_TOKEN }}
run: |
if git clone https://$TOKEN@github.com/kmatycin/Dunice-JAdvanced-tests.git tests; then
echo "Test repository cloned successfully."
else
echo "Failed to clone the test repository."
exit 1
fi
- name: Move Tests to Default Test Directory
run: |
mkdir -p src/test/java
if [ -d "tests/src/test/java" ]; then
cp -r tests/src/test/java/* src/test/java/
echo "Tests moved to the default test directory."
else
echo "No tests found in the expected directory."
exit 1
fi
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Build and Test
id: test
run: mvn clean test -DtrimStackTrace=true | tee test-results.txt
- name: List target directory
run: ls -R target
- name: Verify Test Reports Directory
run: |
if [ -d "target/surefire-reports" ]; then
echo "Reports directory exists";
else
echo "Reports directory not found";
exit 1;
fi
- name: Upload Test Report
uses: actions/upload-artifact@v3
with:
name: test-report
path: target/surefire-reports
- name: Post Results to PR via API
if: ${{ github.event_name == 'pull_request' }}
env:
TOKEN: ${{ secrets.TEST_REPO_TOKEN }}
run: |
TEST_RESULTS=$(grep -E "expected|but was|Tests run|Failures|Errors|Skipped" test-results.txt | grep -v "is started..." | tail -n 50)
COMMENT_BODY=$(echo -e "### Test Results\n\`\`\`\n$TEST_RESULTS\n\`\`\`" | jq -Rsa .)
PR_NUMBER=${{ github.event.pull_request.number }}
curl -s -X POST -H "Authorization: token $TOKEN" \
-H "Content-Type: application/json" \
-d "{\"body\": $COMMENT_BODY}" \
"https://api.github.com/repos/${{ github.repository }}/issues/$PR_NUMBER/comments"