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

fix: Made Automatic generation of github action workflow for keploy configurable #1784

Merged
merged 6 commits into from
Apr 8, 2024
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/test_workflow_scripts/golang-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ docker rm -f ginApp 2>/dev/null || true

for i in {1..2}; do
container_name="ginApp_${i}"
sudo -E env PATH=$PATH ./../../keployv2 record -c "docker run -p8080:8080 --net keploy-network --rm --name ${container_name} gin-mongo" --containerName "${container_name}" &
sudo -E env PATH=$PATH ./../../keployv2 record -c "docker run -p8080:8080 --net keploy-network --rm --name ${container_name} gin-mongo" --containerName "${container_name}" --generateGithubActions=false &

sleep 5

Expand Down Expand Up @@ -63,7 +63,7 @@ for i in {1..2}; do
done

# Start the keploy in test mode.
sudo -E env PATH=$PATH ./../../keployv2 test -c 'docker run -p8080:8080 --net keploy-network --name ginApp_test gin-mongo' --containerName "ginApp_test" --apiTimeout 60 --delay 20
sudo -E env PATH=$PATH ./../../keployv2 test -c 'docker run -p8080:8080 --net keploy-network --name ginApp_test gin-mongo' --containerName "ginApp_test" --apiTimeout 60 --delay 20 --generateGithubActions=false
docker rm -f ginApp_test

# Get the test results from the testReport file.
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_workflow_scripts/golang-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ go build -o ginApp

for i in {1..2}; do
# Start the gin-mongo app in record mode and record testcases and mocks.
sudo -E env PATH="$PATH" ./../../keployv2 record -c "./ginApp" &
sudo -E env PATH="$PATH" ./../../keployv2 record -c "./ginApp" --generateGithubActions=false &

# Wait for the application to start.
app_started=false
Expand Down Expand Up @@ -81,7 +81,7 @@ sleep 5
done

# Start the gin-mongo app in test mode.
sudo -E env PATH="$PATH" ./../../keployv2 test -c "./ginApp" --delay 7
sudo -E env PATH="$PATH" ./../../keployv2 test -c "./ginApp" --delay 7 --generateGithubActions=false

# # move keployv2 to /usr/local/bin/keploy
# mv ./../../keployv2 /usr/local/bin/keploy
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_workflow_scripts/java-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ docker exec mypostgres psql -U petclinic -d petclinic -f /initDB.sql
for i in {1..2}; do
# Start keploy in record mode.
mvn clean install -Dmaven.test.skip=true
sudo -E env PATH=$PATH ./../../../keployv2 record -c 'java -jar target/spring-petclinic-rest-3.0.2.jar' &
sudo -E env PATH=$PATH ./../../../keployv2 record -c 'java -jar target/spring-petclinic-rest-3.0.2.jar' --generateGithubActions=false &

# Wait for the application to start.
app_started=false
Expand Down Expand Up @@ -72,7 +72,7 @@ sleep 5
done

# Start keploy in test mode.
sudo -E env PATH=$PATH ./../../../keployv2 test -c 'java -jar target/spring-petclinic-rest-3.0.2.jar' --delay 20
sudo -E env PATH=$PATH ./../../../keployv2 test -c 'java -jar target/spring-petclinic-rest-3.0.2.jar' --delay 20 --generateGithubActions=false

# Get the test results from the testReport file.
report_file="./keploy/reports/test-run-0/test-set-0-report.yaml"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_workflow_scripts/node-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ docker build -t node-app:1.0 .

for i in {1..2}; do
# Start keploy in record mode.
sudo -E env PATH=$PATH ./../../keployv2 record -c "docker run -p 8000:8000 --name nodeMongoApp --network keploy-network node-app:1.0" --containerName nodeMongoApp &
sudo -E env PATH=$PATH ./../../keployv2 record -c "docker run -p 8000:8000 --name nodeMongoApp --network keploy-network node-app:1.0" --containerName nodeMongoApp --generateGithubActions=false &

# Wait for the application to start.
app_started=false
Expand Down Expand Up @@ -55,7 +55,7 @@ docker rm -f nodeMongoApp
done

# Start keploy in test mode.
sudo -E env PATH=$PATH ./../../keployv2 test -c "docker run -p 8000:8000 --name nodeMongoApp --network keploy-network node-app:1.0" --containerName nodeMongoApp --apiTimeout 30 --delay 30
sudo -E env PATH=$PATH ./../../keployv2 test -c "docker run -p 8000:8000 --name nodeMongoApp --network keploy-network node-app:1.0" --containerName nodeMongoApp --apiTimeout 30 --delay 30 --generateGithubActions=false

# Get the test results from the testReport file.
report_file="./keploy/reports/test-run-0/test-set-0-report.yaml"
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test_workflow_scripts/node-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rm -rf keploy/

for i in {1..2}; do
# Start keploy in record mode.
sudo -E env PATH=$PATH ./../../keployv2 record -c 'npm start' &
sudo -E env PATH=$PATH ./../../keployv2 record -c 'npm start' --generateGithubActions=false &

# Wait for the application to start.
app_started=false
Expand Down Expand Up @@ -63,11 +63,11 @@ sleep 5
done

# Start keploy in test mode.
sudo -E env PATH=$PATH ./../../keployv2 test -c 'npm start' --delay 10
sudo -E env PATH=$PATH ./../../keployv2 test -c 'npm start' --delay 10 --generateGithubActions=false

# sudo -E env PATH=$PATH ./../../keployv2 test -c "npm test" --delay 5 --coverage

sudo -E env PATH=$PATH ./../../keployv2 test -c 'npm start' --delay 10 --testsets test-set-0
sudo -E env PATH=$PATH ./../../keployv2 test -c 'npm start' --delay 10 --testsets test-set-0 --generateGithubActions=false

# Generate the keploy-config file.
sudo ./../../keployv2 config --generate
Expand All @@ -76,7 +76,7 @@ sudo ./../../keployv2 config --generate
config_file="./keploy.yml"
sed -i 's/selectedTests: {}/selectedTests: {"test-set-0": ["test-1", "test-2"]}/' "$config_file"

sudo -E env PATH=$PATH ./../../keployv2 test -c 'npm start' --apiTimeout 30 --delay 10
sudo -E env PATH=$PATH ./../../keployv2 test -c 'npm start' --apiTimeout 30 --delay 10 --generateGithubActions=false

# Get the test results from the testReport file.
report_file="./keploy/reports/test-run-0/test-set-0-report.yaml"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_workflow_scripts/python-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ sleep 5
docker build -t flask-app:1.0 .

for i in {1..2}; do
sudo -E env PATH=$PATH ./../../keployv2 record -c "docker compose up" --containerName flask-app --buildDelay 40s &
sudo -E env PATH=$PATH ./../../keployv2 record -c "docker compose up" --containerName flask-app --buildDelay 40s --generateGithubActions=false &

# Wait for the application to start.
app_started=false
Expand Down Expand Up @@ -50,7 +50,7 @@ docker rm -f flask-app
done

# Start the app in test mode.
sudo -E env PATH=$PATH ./../../keployv2 test -c "docker compose up" --containerName flask-app --buildDelay 40s --apiTimeout 60 --delay 20
sudo -E env PATH=$PATH ./../../keployv2 test -c "docker compose up" --containerName flask-app --buildDelay 40s --apiTimeout 60 --delay 20 --generateGithubActions=false

# Get the test results from the testReport file.
report_file="./keploy/reports/test-run-0/test-set-0-report.yaml"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_workflow_scripts/python-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ sleep 5

for i in {1..2}; do
# Start the django-postgres app in record mode and record testcases and mocks.
sudo -E env PATH="$PATH" ./../../../keployv2 record -c "python3 manage.py runserver" &
sudo -E env PATH="$PATH" ./../../../keployv2 record -c "python3 manage.py runserver" --generateGithubActions=false &

# Wait for the application to start.
app_started=false
Expand Down Expand Up @@ -89,7 +89,7 @@ sleep 5
done

# Start the app in test mode.
sudo -E env PATH="$PATH" ./../../../keployv2 test -c "python3 manage.py runserver" --delay 10
sudo -E env PATH="$PATH" ./../../../keployv2 test -c "python3 manage.py runserver" --delay 10 --generateGithubActions=false

# Get the test results from the testReport file.
report_file="./keploy/reports/test-run-0/test-set-0-report.yaml"
Expand Down
7 changes: 4 additions & 3 deletions cli/provider/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ func (c *CmdConfigurator) AddFlags(cmd *cobra.Command) error {
cmd.Flags().String("containerName", c.cfg.ContainerName, "Name of the application's docker container")
cmd.Flags().StringP("networkName", "n", c.cfg.NetworkName, "Name of the application's docker network")
cmd.Flags().UintSlice("passThroughPorts", config.GetByPassPorts(c.cfg), "Ports to bypass the proxy server and ignore the traffic")
cmd.Flags().Bool("generateGithubActions", c.cfg.GenerateGithubActions, "Generate Github Actions workflow file")
err = cmd.Flags().MarkHidden("port")
if err != nil {
errMsg := "failed to mark port as hidden flag"
Expand Down Expand Up @@ -302,9 +303,9 @@ func (c CmdConfigurator) ValidateFlags(ctx context.Context, cmd *cobra.Command)
}
return errors.New("missing required -c flag or appCmd in config file")
}

defer utils.GenerateGithubActions(c.logger, c.cfg.Command)

if c.cfg.GenerateGithubActions {
defer utils.GenerateGithubActions(c.logger, c.cfg.Command)
}
if c.cfg.InDocker {
c.logger.Info("detected that Keploy is running in a docker container")
if len(c.cfg.Path) > 0 {
Expand Down
35 changes: 18 additions & 17 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@ package config
import "time"

type Config struct {
Path string `json:"path" yaml:"path" mapstructure:"path" `
Command string `json:"command" yaml:"command" mapstructure:"command"`
Port uint32 `json:"port" yaml:"port" mapstructure:"port"`
DNSPort uint32 `json:"dnsPort" yaml:"dnsPort" mapstructure:"dnsPort"`
ProxyPort uint32 `json:"proxyPort" yaml:"proxyPort" mapstructure:"proxyPort"`
Debug bool `json:"debug" yaml:"debug" mapstructure:"debug"`
DisableTele bool `json:"disableTele" yaml:"disableTele" mapstructure:"disableTele"`
InDocker bool `json:"inDocker" yaml:"inDocker" mapstructure:"inDocker"`
ContainerName string `json:"containerName" yaml:"containerName" mapstructure:"containerName"`
NetworkName string `json:"networkName" yaml:"networkName" mapstructure:"networkName"`
BuildDelay time.Duration `json:"buildDelay" yaml:"buildDelay" mapstructure:"buildDelay"`
Test Test `json:"test" yaml:"test" mapstructure:"test"`
Record Record `json:"record" yaml:"record" mapstructure:"record"`
ConfigPath string `json:"configPath" yaml:"configPath" mapstructure:"configPath"`
BypassRules []BypassRule `json:"bypassRules" yaml:"bypassRules" mapstructure:"bypassRules"`
KeployContainer string `json:"keployContainer" yaml:"keployContainer" mapstructure:"keployContainer"`
KeployNetwork string `json:"keployNetwork" yaml:"keployNetwork" mapstructure:"keployNetwork"`
Path string `json:"path" yaml:"path" mapstructure:"path" `
Command string `json:"command" yaml:"command" mapstructure:"command"`
Port uint32 `json:"port" yaml:"port" mapstructure:"port"`
DNSPort uint32 `json:"dnsPort" yaml:"dnsPort" mapstructure:"dnsPort"`
ProxyPort uint32 `json:"proxyPort" yaml:"proxyPort" mapstructure:"proxyPort"`
Debug bool `json:"debug" yaml:"debug" mapstructure:"debug"`
DisableTele bool `json:"disableTele" yaml:"disableTele" mapstructure:"disableTele"`
InDocker bool `json:"inDocker" yaml:"inDocker" mapstructure:"inDocker"`
ContainerName string `json:"containerName" yaml:"containerName" mapstructure:"containerName"`
NetworkName string `json:"networkName" yaml:"networkName" mapstructure:"networkName"`
BuildDelay time.Duration `json:"buildDelay" yaml:"buildDelay" mapstructure:"buildDelay"`
Test Test `json:"test" yaml:"test" mapstructure:"test"`
Record Record `json:"record" yaml:"record" mapstructure:"record"`
ConfigPath string `json:"configPath" yaml:"configPath" mapstructure:"configPath"`
BypassRules []BypassRule `json:"bypassRules" yaml:"bypassRules" mapstructure:"bypassRules"`
KeployContainer string `json:"keployContainer" yaml:"keployContainer" mapstructure:"keployContainer"`
KeployNetwork string `json:"keployNetwork" yaml:"keployNetwork" mapstructure:"keployNetwork"`
GenerateGithubActions bool `json:"generateGithubActions" yaml:"generateGithubActions" mapstructure:"generateGithubActions"`
}

type Record struct {
Expand Down
1 change: 1 addition & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dnsPort: 26789
debug: false
disableTele: false
inDocker: false
generateGithubActions: true
containerName: ""
networkName: ""
buildDelay: 30s
Expand Down
Loading