diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index 04240c5..f9aa7ea 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -1,8 +1,10 @@ -name: Deployment +name: deployment "on": push: branches: - master + pull_request: + branches: [] jobs: deploy: runs-on: ubuntu-latest diff --git a/go.mod b/go.mod index 3d3fdaf..860954e 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,5 @@ module github.com/root27/yml-parser -go 1.22.1 +go 1.22 -require ( - gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) +require gopkg.in/yaml.v2 v2.4.0 diff --git a/go.sum b/go.sum index 3483296..dd0bc19 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,4 @@ +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.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go index fecc2b5..56dc7ea 100644 --- a/main.go +++ b/main.go @@ -2,9 +2,7 @@ package main import ( "fmt" - "os" - - "gopkg.in/yaml.v2" + "reflect" ) type Workflow struct { @@ -15,6 +13,11 @@ type Workflow struct { type On struct { Push Push `yaml:"push"` + Pull Pull `yaml:"pull_request"` +} + +type Pull struct { + Branches []string `yaml:"branches"` } type Push struct { @@ -45,9 +48,9 @@ func main() { workflow := Workflow{} // Gather user inputs - fmt.Print("Enter your repository name: ") - var repoName string - fmt.Scanln(&repoName) + fmt.Print("Enter the workflow name: ") + var workFlowName string + fmt.Scanln(&workFlowName) fmt.Print("Enter the trigger event (e.g., push, pull_request): ") var triggerEvent string @@ -58,40 +61,46 @@ func main() { fmt.Scanln(&onBranch) // Populate the Workflow struct - workflow.Name = "Deployment" - workflow.On.Push.Branches = []string{onBranch} - workflow.Jobs.Deploy.RunsOn = "ubuntu-latest" - workflow.Jobs.Deploy.Steps = []Step{ - { - Uses: "actions/checkout@v2", - }, - { - Name: "Deploy to server", - Env: Env{ - ServerKey: "${{ secrets.SERVER_KEY }}", - }, - Run: `echo "$SERVER_KEY" > secret && chmod 600 secret && ssh -o StrictHostKeyChecking=no -i secret root@185.247.139.226 -p 8357 'ls -la'`, - }, - } - - // Set environment variables - // workflow.Jobs.Deploy.Steps[0].Env = Env{ - // ServerKey: "${{ secrets.SERVER_KEY }}", + + flowType := reflect.TypeOf(workflow) + + newStruct := reflect.New(flowType) + + newStruct.Elem().FieldByName("Name").SetString(workFlowName) + + newStruct.Elem().FieldByName("On").FieldByName(triggerEvent).FieldByName("Branches").Set(reflect.ValueOf([]string{onBranch})) + + fmt.Print(newStruct.Interface()) + + // workflow.On.Push.Branches = []string{onBranch} + + // workflow.Jobs.Deploy.RunsOn = "ubuntu-latest" + // workflow.Jobs.Deploy.Steps = []Step{ + // { + // Uses: "actions/checkout@v2", + // }, + // { + // Name: "Deploy to server", + // Env: Env{ + // ServerKey: "${{ secrets.SERVER_KEY }}", + // }, + // Run: `echo "$SERVER_KEY" > secret && chmod 600 secret && ssh -o StrictHostKeyChecking=no -i secret root@185.247.139.226 -p 8357 'ls -la'`, + // }, + // } + + // // Convert struct to YAML + // yamlData, err := yaml.Marshal(&workflow) + // if err != nil { + // fmt.Printf("Error marshalling YAML: %v\n", err) + // return + // } + + // // Write YAML to file + // err = os.WriteFile(".github/workflows/deployment.yml", yamlData, 0644) + // if err != nil { + // fmt.Printf("Error writing YAML file: %v\n", err) + // return // } - // Convert struct to YAML - yamlData, err := yaml.Marshal(&workflow) - if err != nil { - fmt.Printf("Error marshalling YAML: %v\n", err) - return - } - - // Write YAML to file - err = os.WriteFile(".github/workflows/deployment.yml", yamlData, 0644) - if err != nil { - fmt.Printf("Error writing YAML file: %v\n", err) - return - } - - fmt.Println("Deployment YAML file generated successfully.") + // fmt.Println("Deployment YAML file generated successfully.") }