-
Notifications
You must be signed in to change notification settings - Fork 3
/
action.yml
89 lines (85 loc) · 3.51 KB
/
action.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
name: 'Keploy TestGPT'
description: "TestGPT is a GitHub Action designed to execute Keploy test cases and generate detailed test reports."
author: Sonichigo
branding:
icon: 'aperture'
color: 'orange'
inputs:
working-directory:
description: Relative path under $GITHUB_WORKSPACE where the repository was checked out
required: true
command:
description: Command to run the application
required: true
keploy-path:
description: Path to keploy
required: true
default: ./
delay:
description: Time to start application
required: true
default: 10
container-name:
description: Name of the container in case of "docker compose" command
build-delay:
description: Time to wait for docker container build
default: 50s
runs:
using: "composite"
steps:
- name: Setup GITHUB_PATH for script
run: |
echo "${{ github.action_path }}" >> $GITHUB_PATH
echo "${{ inputs.working-directory }}"
shell: bash
- name: Grant permissions
run: chmod +x ${GITHUB_ACTION_PATH}/install.sh
shell: bash
- id: keploy-test-report
name: Run Script
run: |
${GITHUB_ACTION_PATH}/install.sh > ${GITHUB_WORKSPACE}/${WORKDIR}/report.txt
cat ${GITHUB_WORKSPACE}/${WORKDIR}/report.txt
# Search for the complete testrun summary and extract total tests, total test passed, and total test failed data
grep -oE "COMPLETE TESTRUN SUMMARY\.\s+Total tests: [0-9]+" ${GITHUB_WORKSPACE}/${WORKDIR}/report.txt | sed -r "s/\x1B\[[0-9;]*[mGK]//g" > ${GITHUB_WORKSPACE}/${WORKDIR}/final_total_tests.out
grep -oE "COMPLETE TESTRUN SUMMARY\.\s+Total test passed: [0-9]+" ${GITHUB_WORKSPACE}/${WORKDIR}/report.txt | sed -r "s/\x1B\[[0-9;]*[mGK]//g" > ${GITHUB_WORKSPACE}/${WORKDIR}/final_total_passed.out
grep -oE "COMPLETE TESTRUN SUMMARY\.\s+Total test failed: [0-9]+" ${GITHUB_WORKSPACE}/${WORKDIR}/report.txt | sed -r "s/\x1B\[[0-9;]*[mGK]//g" > ${GITHUB_WORKSPACE}/${WORKDIR}/final_total_failed.out
# Combine the results into a single file and prepare output
cat ${GITHUB_WORKSPACE}/${WORKDIR}/final_total_tests.out ${GITHUB_WORKSPACE}/${WORKDIR}/final_total_passed.out ${GITHUB_WORKSPACE}/${WORKDIR}/final_total_failed.out > ${GITHUB_WORKSPACE}/${WORKDIR}/final.out
echo 'KEPLOY_REPORT<<EOF' > $GITHUB_OUTPUT
cat ${GITHUB_WORKSPACE}/${WORKDIR}/final.out >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
shell: bash
env:
WORKDIR: ${{ inputs.working-directory }}
DELAY: ${{ inputs.delay }}
COMMAND : ${{ inputs.command }}
KEPLOY_PATH: ${{inputs.keploy-path}}
- name: Check if report is generated
run: |
if [ -s ${GITHUB_WORKSPACE}/${WORKDIR}/final.out ]; then
echo "Report generated successfully."
else
echo "Error: Report not generated." >&2
exit 1
fi
shell: bash
- name: Comment on PR
if: success()
uses: actions/github-script@v6
env:
KEPLOY_REPORT: ${{ steps.keploy-test-report.outputs.KEPLOY_REPORT }}
with:
github-token: ${{ github.token }}
script: |
if (!process.env.KEPLOY_REPORT) {
console.error('Error: KEPLOY_REPORT not found.');
process.exit(1);
}
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: process.env.KEPLOY_REPORT
})