Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature]: generate GitHub Actions automatically when keploy runs #1479

Merged
merged 28 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
60fd941
Feat: Automatically Generate Github Actions File on Keploy record
Akash-Singh04 Feb 1, 2024
13f5feb
Merge branch 'main' of https://github.com/keploy/keploy into generate…
Akash-Singh04 Feb 2, 2024
ae136e3
Merge branch 'main' of https://github.com/keploy/keploy into generate…
Akash-Singh04 Feb 5, 2024
b1aa00b
Merge branch 'main' into generateGithubActions
Akash-Singh04 Feb 5, 2024
50310b8
Merge branch 'main' into generateGithubActions
Akash-Singh04 Feb 6, 2024
9c0a464
Merge branch 'main' into generateGithubActions
Akash-Singh04 Feb 6, 2024
75bcfa0
Merge branch 'main' into generateGithubActions
Akash-Singh04 Feb 7, 2024
c32931c
Merge branch 'main' into generateGithubActions
Akash-Singh04 Feb 8, 2024
59762ae
Merge branch 'main' into generateGithubActions
Akash-Singh04 Feb 8, 2024
0baf215
Merge branch 'main' of https://github.com/keploy/keploy into generate…
Akash-Singh04 Feb 9, 2024
07e60ed
Addressed review comments and accounted for docker env
Akash-Singh04 Feb 9, 2024
8ebf3fe
Merge branch 'main' into generateGithubActions
Akash-Singh04 Feb 14, 2024
2eb6a28
Merge branch 'main' into generateGithubActions
Akash-Singh04 Feb 16, 2024
8259573
Merge branch 'main' into generateGithubActions
Akash-Singh04 Feb 17, 2024
73dcb5e
updated import
Akash-Singh04 Feb 17, 2024
541289c
Merge branch 'main' into generateGithubActions
Akash-Singh04 Mar 2, 2024
ba768f7
Removed Depricated package
Akash-Singh04 Mar 2, 2024
575378e
Fixed Lint
Akash-Singh04 Mar 2, 2024
7521d55
Merge branch 'main' into generateGithubActions
Akash-Singh04 Mar 6, 2024
0cee209
Merge branch 'main' of https://github.com/keploy/keploy into generate…
Akash-Singh04 Mar 14, 2024
2767dfc
Refactored for Keploy v2
Akash-Singh04 Mar 14, 2024
f6d0a46
Merge branch 'main' into generateGithubActions
Akash-Singh04 Mar 20, 2024
3ffc9ee
Merge branch 'main' of https://github.com/keploy/keploy into generate…
Akash-Singh04 Mar 22, 2024
09b6b4a
Fixed merge conflicts and fixed keploy folder path
Akash-Singh04 Mar 22, 2024
5cc3590
Merge branch 'generateGithubActions' of https://github.com/Akash-Sing…
Akash-Singh04 Mar 22, 2024
72ff4da
Merge branch 'main' into generateGithubActions
Akash-Singh04 Mar 24, 2024
b522517
Merge branch 'main' into generateGithubActions
Akash-Singh04 Mar 29, 2024
3b69b9a
Merge branch 'main' into generateGithubActions
Akash-Singh04 Mar 30, 2024
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
2 changes: 2 additions & 0 deletions cmd/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ func (r *Record) GetCmd() *cobra.Command {

r.logger.Info("", zap.Any("keploy test and mock path", path))

defer utils.GenerateGithubActions(r.logger, path, appCmd)

var hasContainerName bool
if isDockerCmd {
if strings.Contains(appCmd, "--name") {
Expand Down
52 changes: 52 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,58 @@ func HandlePanic() {
}
}

// GenerateGithubActions generates a GitHub Actions workflow file for Keploy
func GenerateGithubActions(logger *zap.Logger, path string, appCmd string) {
// Determine the path based on the alias "keploy"
var keployPath string
isDockerCmd := len(os.Getenv("IS_DOCKER_CMD")) > 0
if isDockerCmd {
logger.Info("Running in docker environment, skipping the path determination")
keployPath = "./"
} else {
logger.Info("Determining the path of the keploy binary based on the alias \"keploy\"")
keployPath = "/usr/local/bin/keploybin" // Default path
aliasCmd := exec.Command("which", "keploy")
aliasOutput, err := aliasCmd.Output()
if err == nil && len(aliasOutput) > 0 {
keployPath = strings.TrimSpace(string(aliasOutput))
}
logger.Info("Path of the keploy binary determined successfully", zap.String("path", keployPath))
}
// Define the content of the GitHub Actions workflow file
actionsFileContent := `name: Keploy
on:
push:
branches:
- main
pull_request:
types: [opened, reopened, synchronize]
jobs:
e2e-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Test-Report
uses: keploy/testgpt@main
Sarthak160 marked this conversation as resolved.
Show resolved Hide resolved
with:
working-directory: ./
keploy-path: ` + keployPath + `
Sarthak160 marked this conversation as resolved.
Show resolved Hide resolved
command: ` + appCmd + `
`

// Define the file path where the GitHub Actions workflow file will be saved
filePath := "/githubactions/keploy.yml"

// Write the content to the file
if err := ioutil.WriteFile(filePath, []byte(actionsFileContent), 0644); err != nil {
logger.Error("Error writing GitHub Actions workflow file", zap.Error(err))
return
}

logger.Info("GitHub Actions workflow file generated successfully", zap.String("path", filePath))
}

// getLatestGitHubRelease fetches the latest version and release body from GitHub releases with a timeout.
func GetLatestGitHubRelease() (GitHubRelease, error) {
// GitHub repository details
Expand Down
Loading