-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
55 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 [email protected] -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 [email protected] -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.") | ||
} |