Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 62 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,76 @@
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*.*.*' # Push events to matching v*, i.e. v1.0, v20.15.10
branches:
- main
- func
- lint

name: Create Release

jobs:
build:
name: Create Release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.23.2"

- name: Install dependencies
run: go get gopkg.in/yaml.v3

- name: Build binary
run: go build -o keploy-runner main.go

- name: Extract commit information
id: commit_info
run: |
COMMIT_MSG=$(git log -1 --pretty=%s)
COMMIT_BODY=$(git log -1 --pretty=%b)
# Get the latest tag if it exists
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "No previous tags")

echo "message<<EOF" >> $GITHUB_OUTPUT
echo "$COMMIT_MSG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "body<<EOF" >> $GITHUB_OUTPUT
echo "$COMMIT_BODY" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT

- name: Create latest tag
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Create or update the 'latest' tag
git tag -fa latest -m "Latest release"
# Push the latest tag
git push origin latest --force

- name: Create Latest Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
tag_name: latest
name: Latest Release
body: |
Changes in this Release
- First Change
- Second Change
# Latest Release

This is an automatically updated release that always points to the most recent build.

Latest commit: ${{ steps.commit_info.outputs.message }}

This release includes the pre-built binary for the TestGPT GitHub Action.
draft: false
prerelease: false
prerelease: false
files: |
keploy-runner
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work
go.work.sum

# env file
.env
163 changes: 127 additions & 36 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: 'Keploy TestGPT'
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'
icon: "aperture"
color: "orange"

inputs:
working-directory:
Expand All @@ -19,71 +19,162 @@ inputs:
delay:
description: Time to start application
required: true
default: 10
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
default: "50"
runner-version:
description: Version of the runner to use
default: "latest"
github-token:
description: GitHub token for API access to fetch PR details
default: ${{ github.token }}

runs:
using: "composite"
steps:
- name: Setup GITHUB_PATH for script
run: |
echo "${{ github.action_path }}" >> $GITHUB_PATH
echo "${{ inputs.working-directory }}"
echo "Working directory: ${{ inputs.working-directory }}"
echo "Keploy path: ${{ inputs.keploy-path }}"
shell: bash
- name: Grant permissions
run: chmod +x ${GITHUB_ACTION_PATH}/install.sh

- name: Run MegaLinter
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
run: |
docker run -v $(pwd):/tmp/lint \
-e GITHUB_TOKEN=${{ inputs.github-token }} \
-e REPORT_OUTPUT_FOLDER=/tmp/lint/megalinter-reports \
-e DISABLE_ERRORS=true \
-e PARALLEL=true \
-e JSON_REPORTER=true \
-e MARKDOWN_SUMMARY_REPORTER=true \
-e EXCLUDED_DIRECTORIES="keploy,megalinter-reports" \
-e SHOW_SKIPPED_LINTERS=false \
-e SHOW_ELAPSED_TIME=true \
oxsecurity/megalinter-cupcake:v8.5.0
working-directory: ${{ inputs.working-directory }}

- name: Upload MegaLinter Report
uses: actions/upload-artifact@v4
with:
name: megalinter-report
path: ${{ inputs.working-directory }}/megalinter-reports/
retention-days: 1
id: upload-megalinter

- name: Set MegaLinter artifact link
shell: bash
run: |
echo "MEGALINTER_ARTIFACT_URL=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts" >> $GITHUB_ENV

# 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
- name: Download pre-built runner
run: |
echo "Downloading from: https://github.com/rycerzes/testGPT/releases/download/latest/keploy-runner"
curl -L -o ${GITHUB_ACTION_PATH}/keploy-runner https://github.com/rycerzes/testGPT/releases/download/latest/keploy-runner
chmod +x ${GITHUB_ACTION_PATH}/keploy-runner
shell: bash

# 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
- name: Run Keploy TestGPT
run: |
cd ${GITHUB_ACTION_PATH}
./keploy-runner > ${GITHUB_WORKSPACE}/${WORKDIR}/console-output.txt
shell: bash
env:
WORKDIR: ${{ inputs.working-directory }}
DELAY: ${{ inputs.delay }}
COMMAND : ${{ inputs.command }}
KEPLOY_PATH: ${{inputs.keploy-path}}
COMMAND: ${{ inputs.command }}
KEPLOY_PATH: ${{ inputs.keploy-path }}
CONTAINER_NAME: ${{ inputs.container-name }}
BUILD_DELAY: ${{ inputs.build-delay }}
GITHUB_TOKEN: ${{ inputs.github-token }}
MEGALINTER_ARTIFACT_URL: ${{ env.MEGALINTER_ARTIFACT_URL }}

- id: keploy-test-report
name: Process Test Results
run: |
if [ -f "${GITHUB_WORKSPACE}/${WORKDIR}/github_output.txt" ]; then
cat "${GITHUB_WORKSPACE}/${WORKDIR}/github_output.txt" >> $GITHUB_OUTPUT
else
echo "Error: GitHub output file not found at: ${GITHUB_WORKSPACE}/${WORKDIR}/github_output.txt" >&2
exit 1
fi
shell: bash
env:
WORKDIR: ${{ inputs.working-directory }}

- name: Check if report is generated
run: |
if [ -s ${GITHUB_WORKSPACE}/${WORKDIR}/final.out ]; then
if [ -f "${GITHUB_WORKSPACE}/${WORKDIR}/final.out" ]; then
echo "Report generated successfully."
else
echo "Error: Report not generated." >&2
exit 1
fi
shell: bash
env:
WORKDIR: ${{ inputs.working-directory }}

- name: Comment on PR
if: success()
if: success() && github.event_name == 'pull_request'
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);
try {
if (!process.env.KEPLOY_REPORT) {
console.error('Error: KEPLOY_REPORT not found.');
process.exit(1);
}

await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: process.env.KEPLOY_REPORT
});
console.log('Successfully commented on PR');
} catch (error) {
console.error('Error commenting on PR:', error.message);
console.log('Report content (for reference):');
console.log(process.env.KEPLOY_REPORT);

// Don't fail the workflow if commenting fails
if (error.status === 403) {
console.log('Permission issue: Make sure your workflow has proper permissions.');
console.log('Add the following to your workflow file:');
console.log('permissions:');
console.log(' contents: read');
console.log(' issues: write');
console.log(' pull-requests: write');
}
}
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: process.env.KEPLOY_REPORT
})

- name: Display Test Results
if: always()
run: |
echo "============ KEPLOY TEST RESULTS ============"
if [ -f "${GITHUB_WORKSPACE}/${WORKDIR}/final.out" ]; then
cat "${GITHUB_WORKSPACE}/${WORKDIR}/final.out"
echo ""
echo "============ SUMMARY ============"
if [ -f "${GITHUB_WORKSPACE}/${WORKDIR}/final_total_tests.out" ]; then
cat "${GITHUB_WORKSPACE}/${WORKDIR}/final_total_tests.out"
fi
if [ -f "${GITHUB_WORKSPACE}/${WORKDIR}/final_total_passed.out" ]; then
cat "${GITHUB_WORKSPACE}/${WORKDIR}/final_total_passed.out"
fi
if [ -f "${GITHUB_WORKSPACE}/${WORKDIR}/final_total_failed.out" ]; then
cat "${GITHUB_WORKSPACE}/${WORKDIR}/final_total_failed.out"
fi
else
echo "No test results found"
fi
shell: bash
env:
WORKDIR: ${{ inputs.working-directory }}
11 changes: 11 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module testGPT

go 1.23.2

require (
github.com/google/go-github/v70 v70.0.0
golang.org/x/oauth2 v0.28.0
gopkg.in/yaml.v3 v3.0.1
)

require github.com/google/go-querystring v1.1.0 // indirect
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/go-github/v70 v70.0.0 h1:/tqCp5KPrcvqCc7vIvYyFYTiCGrYvaWoYMGHSQbo55o=
github.com/google/go-github/v70 v70.0.0/go.mod h1:xBUZgo8MI3lUL/hwxl3hlceJW1U8MVnXP3zUyI+rhQY=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
golang.org/x/oauth2 v0.28.0 h1:CrgCKl8PPAVtLnU3c+EDw6x11699EWlsDeWNWKdIOkc=
golang.org/x/oauth2 v0.28.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading