From fae96c7c8afde7758b722d0cb449280725d90d62 Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Thu, 18 Sep 2025 18:02:06 -0300 Subject: [PATCH 01/18] chore: handle additional inputs in templates --- pkg/cmd/init/contracts.go | 29 ++++++++++++++++++++++------- pkg/cmd/init/init.go | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/pkg/cmd/init/contracts.go b/pkg/cmd/init/contracts.go index 5b8418baf..decad4ecc 100644 --- a/pkg/cmd/init/contracts.go +++ b/pkg/cmd/init/contracts.go @@ -1,14 +1,29 @@ package init type Template struct { - Name string `json:"name"` - Items []Item `json:"items"` + Name string `json:"name"` + Items []Item `json:"items"` } type Item struct { - Name string `json:"name"` - Message string `json:"message"` - Preset string `json:"preset"` - Path string `json:"path"` - Link string `json:"link"` + Name string `json:"name"` + Message string `json:"message"` + Preset string `json:"preset"` + Path string `json:"path"` + Link string `json:"link"` + Extras *Extras `json:"extras,omitempty"` +} + +// Extras represents optional additional information sent by the templates API +// Currently supports type "env" with a list of inputs to be collected from the user +type Extras struct { + Type string `json:"type"` + Inputs []ExtraInput `json:"inputs"` +} + +// ExtraInput represents a single input for the extras block +// For type "env", each input contains a key and a user-facing prompt text +type ExtraInput struct { + Key string `json:"key"` + Text string `json:"text"` } diff --git a/pkg/cmd/init/init.go b/pkg/cmd/init/init.go index 8b4612fa7..da4486a09 100644 --- a/pkg/cmd/init/init.go +++ b/pkg/cmd/init/init.go @@ -37,7 +37,8 @@ import ( const ( SAMPLESURL = "https://github.com/aziontech/azion-samples.git" - APIURL = "https://api.azion.com/v4/utils/project_samples" + // APIURL = "https://api.azion.com/v4/utils/project_samples" + APIURL = "https://b0rfluh05b.map.azionedge.net/api/templates" ) type initCmd struct { @@ -267,6 +268,38 @@ func (cmd *initCmd) Run(c *cobra.Command, _ []string) error { cmd.preset = strings.ToLower(templateOptionsMap[answerTemplate].Preset) + // Handle optional extras from the Templates API + selectedItem := templateOptionsMap[answerTemplate] + if selectedItem.Extras != nil && strings.ToLower(selectedItem.Extras.Type) == "env" && len(selectedItem.Extras.Inputs) > 0 { + // Collect user inputs and write/append them to a .env file in the working directory + envLines := make([]string, 0, len(selectedItem.Extras.Inputs)) + for _, input := range selectedItem.Extras.Inputs { + var userVal string + promptEnv := &survey.Input{Message: input.Text} + if err := cmd.askOne(promptEnv, &userVal); err != nil { + return err + } + line := fmt.Sprintf("%s=%s", input.Key, userVal) + envLines = append(envLines, line) + } + + envPath := path.Join(newPath, ".env") + var existing string + if _, err := cmd.stat(envPath); err == nil { + if b, rerr := cmd.fileReader(envPath); rerr == nil { + existing = string(b) + if len(existing) > 0 && !strings.HasSuffix(existing, "\n") { + existing += "\n" + } + } + } + + content := existing + strings.Join(envLines, "\n") + "\n" + if err := cmd.writeFile(envPath, []byte(content), 0644); err != nil { + return err + } + } + if err = cmd.createTemplateAzion(); err != nil { return err } From 3ba638dc2af7f5ec3139a666be7bbec63cb56eb0 Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Thu, 18 Sep 2025 18:07:04 -0300 Subject: [PATCH 02/18] chore: add code to a helper function --- pkg/cmd/init/init.go | 31 +++++------------------------ utils/helpers.go | 46 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 26 deletions(-) diff --git a/pkg/cmd/init/init.go b/pkg/cmd/init/init.go index da4486a09..c92b550ba 100644 --- a/pkg/cmd/init/init.go +++ b/pkg/cmd/init/init.go @@ -37,8 +37,7 @@ import ( const ( SAMPLESURL = "https://github.com/aziontech/azion-samples.git" - // APIURL = "https://api.azion.com/v4/utils/project_samples" - APIURL = "https://b0rfluh05b.map.azionedge.net/api/templates" + APIURL = "https://api.azion.com/v4/utils/project_samples" ) type initCmd struct { @@ -271,31 +270,11 @@ func (cmd *initCmd) Run(c *cobra.Command, _ []string) error { // Handle optional extras from the Templates API selectedItem := templateOptionsMap[answerTemplate] if selectedItem.Extras != nil && strings.ToLower(selectedItem.Extras.Type) == "env" && len(selectedItem.Extras.Inputs) > 0 { - // Collect user inputs and write/append them to a .env file in the working directory - envLines := make([]string, 0, len(selectedItem.Extras.Inputs)) - for _, input := range selectedItem.Extras.Inputs { - var userVal string - promptEnv := &survey.Input{Message: input.Text} - if err := cmd.askOne(promptEnv, &userVal); err != nil { - return err - } - line := fmt.Sprintf("%s=%s", input.Key, userVal) - envLines = append(envLines, line) - } - - envPath := path.Join(newPath, ".env") - var existing string - if _, err := cmd.stat(envPath); err == nil { - if b, rerr := cmd.fileReader(envPath); rerr == nil { - existing = string(b) - if len(existing) > 0 && !strings.HasSuffix(existing, "\n") { - existing += "\n" - } - } + inputs := make([]utils.EnvInput, 0, len(selectedItem.Extras.Inputs)) + for _, in := range selectedItem.Extras.Inputs { + inputs = append(inputs, utils.EnvInput{Key: in.Key, Text: in.Text}) } - - content := existing + strings.Join(envLines, "\n") + "\n" - if err := cmd.writeFile(envPath, []byte(content), 0644); err != nil { + if err := utils.CollectEnvInputsAndWriteFile(inputs, newPath); err != nil { return err } } diff --git a/utils/helpers.go b/utils/helpers.go index d2b949cf6..30bf3b09b 100644 --- a/utils/helpers.go +++ b/utils/helpers.go @@ -702,3 +702,49 @@ func ReplaceInvalidCharsBucket(str string) string { re := regexp.MustCompile(`(?i)(?:azion-|b2-)|[^a-z0-9\-]`) return re.ReplaceAllString(str, "") } + +// EnvInput represents a key and a user-facing prompt text for collecting +// environment variable values and writing them to a .env file. +type EnvInput struct { + Key string + Text string +} + +// CollectEnvInputsAndWriteFile prompts the user for each provided EnvInput and +// writes/appends the resulting KEY=VALUE pairs to a .env file under destDir. +// If the .env file already exists, the new pairs are concatenated, preserving +// existing content. Ensures the file ends with a trailing newline. +func CollectEnvInputsAndWriteFile(inputs []EnvInput, destDir string) error { + if len(inputs) == 0 { + return nil + } + + // Collect inputs from user + envLines := make([]string, 0, len(inputs)) + for _, in := range inputs { + val, err := AskInputEmpty(in.Text) + if err != nil { + return err + } + line := fmt.Sprintf("%s=%s", in.Key, val) + envLines = append(envLines, line) + } + + // Prepare .env path and existing content + envPath := path.Join(destDir, ".env") + var existing string + if FileExists(envPath) { + if b, err := os.ReadFile(envPath); err == nil { + existing = string(b) + if len(existing) > 0 && !strings.HasSuffix(existing, "\n") { + existing += "\n" + } + } + } + + content := existing + strings.Join(envLines, "\n") + "\n" + if err := os.WriteFile(envPath, []byte(content), 0644); err != nil { + return err + } + return nil +} From 7d1538416d9c3549c45496028ec9af061ec5dc5b Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Thu, 2 Oct 2025 11:04:40 -0300 Subject: [PATCH 03/18] chore: add port to dev command (v3) --- pkg/v3commands/dev/dev.go | 4 +++- pkg/v3commands/dev/vulcan.go | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/v3commands/dev/dev.go b/pkg/v3commands/dev/dev.go index 3ec1cab06..71411614b 100644 --- a/pkg/v3commands/dev/dev.go +++ b/pkg/v3commands/dev/dev.go @@ -17,6 +17,7 @@ import ( var ( isFirewall bool + port int ) type DevCmd struct { @@ -56,6 +57,7 @@ func NewCobraCmd(dev *DevCmd) *cobra.Command { }, } devCmd.Flags().BoolP("help", "h", false, msg.DevFlagHelp) + devCmd.Flags().IntVar(&port, "port", 0, msg.PortFlag) devCmd.Flags().BoolVar(&isFirewall, "firewall", false, msg.IsFirewall) return devCmd } @@ -76,7 +78,7 @@ func (cmd *DevCmd) Run(f *cmdutil.Factory) error { return output.Print(&outGen) } - err := vulcan(cmd, isFirewall) + err := vulcan(cmd, isFirewall, port) if err != nil { return err } diff --git a/pkg/v3commands/dev/vulcan.go b/pkg/v3commands/dev/vulcan.go index fb4aebdf4..73a177d0f 100644 --- a/pkg/v3commands/dev/vulcan.go +++ b/pkg/v3commands/dev/vulcan.go @@ -8,12 +8,17 @@ import ( "go.uber.org/zap" ) -func vulcan(cmd *DevCmd, isFirewall bool) error { +func vulcan(cmd *DevCmd, isFirewall bool, port int) error { vul := cmd.Vulcan() command := vul.Command("", "dev", cmd.F) + + if port > 0 { + command = fmt.Sprintf("%s --port %d", command, port) + } + if isFirewall { - command = vul.Command("", "dev --firewall", cmd.F) + command = fmt.Sprintf("%s --firewall", command) } err := runCommand(cmd, command) From c3df8cae0626ef216be4ea7a8633f427f40ea290 Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Fri, 3 Oct 2025 15:42:04 -0300 Subject: [PATCH 04/18] chore: update init command --- pkg/cmd/init/contracts.go | 25 +++++----- pkg/cmd/init/init.go | 34 +++++++++----- utils/helpers.go | 96 +++++++++++++++++++++++++-------------- 3 files changed, 98 insertions(+), 57 deletions(-) diff --git a/pkg/cmd/init/contracts.go b/pkg/cmd/init/contracts.go index decad4ecc..3bbcc4b03 100644 --- a/pkg/cmd/init/contracts.go +++ b/pkg/cmd/init/contracts.go @@ -1,29 +1,30 @@ package init type Template struct { - Name string `json:"name"` - Items []Item `json:"items"` + Name string `json:"name"` + Items []Item `json:"items"` } type Item struct { - Name string `json:"name"` - Message string `json:"message"` - Preset string `json:"preset"` - Path string `json:"path"` - Link string `json:"link"` - Extras *Extras `json:"extras,omitempty"` + Name string `json:"name"` + Message string `json:"message"` + Preset string `json:"preset"` + Path string `json:"path"` + Link string `json:"link"` + RequiresAdditionalBuild *bool `json:"requires_additional_build"` + Extras *Extras `json:"extras,omitempty"` } // Extras represents optional additional information sent by the templates API // Currently supports type "env" with a list of inputs to be collected from the user type Extras struct { - Type string `json:"type"` - Inputs []ExtraInput `json:"inputs"` + Type string `json:"type"` + Inputs []ExtraInput `json:"inputs"` } // ExtraInput represents a single input for the extras block // For type "env", each input contains a key and a user-facing prompt text type ExtraInput struct { - Key string `json:"key"` - Text string `json:"text"` + Key string `json:"key"` + Text string `json:"text"` } diff --git a/pkg/cmd/init/init.go b/pkg/cmd/init/init.go index c92b550ba..e1a4d2c3d 100644 --- a/pkg/cmd/init/init.go +++ b/pkg/cmd/init/init.go @@ -37,7 +37,8 @@ import ( const ( SAMPLESURL = "https://github.com/aziontech/azion-samples.git" - APIURL = "https://api.azion.com/v4/utils/project_samples" + // APIURL = "https://api.azion.com/v4/utils/project_samples" + APIURL = "https://qxresbth58.map.azionedge.net/api/templates" ) type initCmd struct { @@ -200,10 +201,13 @@ func (cmd *initCmd) Run(c *cobra.Command, _ []string) error { return err } - templateOptions := make([]string, len(templateMap[answer])) + templateOptions := []string{} templateOptionsMap := make(map[string]Item) - for number, value := range templateMap[answer] { - templateOptions[number] = value.Name + for _, value := range templateMap[answer] { + if value.RequiresAdditionalBuild != nil && *value.RequiresAdditionalBuild { + continue + } + templateOptions = append(templateOptions, value.Name) templateOptionsMap[value.Name] = value } @@ -266,23 +270,31 @@ func (cmd *initCmd) Run(c *cobra.Command, _ []string) error { } cmd.preset = strings.ToLower(templateOptionsMap[answerTemplate].Preset) + if err = cmd.createTemplateAzion(); err != nil { + return err + } // Handle optional extras from the Templates API selectedItem := templateOptionsMap[answerTemplate] - if selectedItem.Extras != nil && strings.ToLower(selectedItem.Extras.Type) == "env" && len(selectedItem.Extras.Inputs) > 0 { + if selectedItem.Extras != nil && len(selectedItem.Extras.Inputs) > 0 { inputs := make([]utils.EnvInput, 0, len(selectedItem.Extras.Inputs)) for _, in := range selectedItem.Extras.Inputs { inputs = append(inputs, utils.EnvInput{Key: in.Key, Text: in.Text}) } - if err := utils.CollectEnvInputsAndWriteFile(inputs, newPath); err != nil { - return err + switch strings.ToLower(selectedItem.Extras.Type) { + case "env": + if err := utils.CollectEnvInputsAndWriteFile(inputs, newPath); err != nil { + return err + } + case "args": + if err := utils.CollectArgsInputsAndWriteFile(inputs, path.Join(newPath, "azion")); err != nil { + return err + } + default: + return fmt.Errorf("invalid extra type: %s", selectedItem.Extras.Type) } } - if err = cmd.createTemplateAzion(); err != nil { - return err - } - logger.FInfoFlags(cmd.f.IOStreams.Out, msg.WebAppInitCmdSuccess, cmd.f.Format, cmd.f.Out) msgs = append(msgs, msg.WebAppInitCmdSuccess) diff --git a/utils/helpers.go b/utils/helpers.go index 30bf3b09b..08df7c798 100644 --- a/utils/helpers.go +++ b/utils/helpers.go @@ -706,8 +706,8 @@ func ReplaceInvalidCharsBucket(str string) string { // EnvInput represents a key and a user-facing prompt text for collecting // environment variable values and writing them to a .env file. type EnvInput struct { - Key string - Text string + Key string + Text string } // CollectEnvInputsAndWriteFile prompts the user for each provided EnvInput and @@ -715,36 +715,64 @@ type EnvInput struct { // If the .env file already exists, the new pairs are concatenated, preserving // existing content. Ensures the file ends with a trailing newline. func CollectEnvInputsAndWriteFile(inputs []EnvInput, destDir string) error { - if len(inputs) == 0 { - return nil - } - - // Collect inputs from user - envLines := make([]string, 0, len(inputs)) - for _, in := range inputs { - val, err := AskInputEmpty(in.Text) - if err != nil { - return err - } - line := fmt.Sprintf("%s=%s", in.Key, val) - envLines = append(envLines, line) - } - - // Prepare .env path and existing content - envPath := path.Join(destDir, ".env") - var existing string - if FileExists(envPath) { - if b, err := os.ReadFile(envPath); err == nil { - existing = string(b) - if len(existing) > 0 && !strings.HasSuffix(existing, "\n") { - existing += "\n" - } - } - } - - content := existing + strings.Join(envLines, "\n") + "\n" - if err := os.WriteFile(envPath, []byte(content), 0644); err != nil { - return err - } - return nil + if len(inputs) == 0 { + return nil + } + + // Collect inputs from user + envLines := make([]string, 0, len(inputs)) + for _, in := range inputs { + val, err := AskInputEmpty(in.Text) + if err != nil { + return err + } + line := fmt.Sprintf("%s=%s", in.Key, val) + envLines = append(envLines, line) + } + + // Prepare .env path and existing content + envPath := path.Join(destDir, ".env") + var existing string + if FileExists(envPath) { + if b, err := os.ReadFile(envPath); err == nil { + existing = string(b) + if len(existing) > 0 && !strings.HasSuffix(existing, "\n") { + existing += "\n" + } + } + } + + content := existing + strings.Join(envLines, "\n") + "\n" + if err := os.WriteFile(envPath, []byte(content), 0644); err != nil { + return err + } + return nil +} + +func CollectArgsInputsAndWriteFile(inputs []EnvInput, destDir string) error { + if len(inputs) == 0 { + return nil + } + + // Prepare args.json path and collect fresh inputs into a new JSON object + argsPath := path.Join(destDir, "args.json") + data := make(map[string]string) + + for _, in := range inputs { + val, err := AskInputEmpty(in.Text) + if err != nil { + return err + } + data[in.Key] = val + } + + // Marshal as pretty JSON and write file + content, err := json.MarshalIndent(data, "", " ") + if err != nil { + return err + } + if err := os.WriteFile(argsPath, content, 0644); err != nil { + return err + } + return nil } From f862ec197599650dc8b7afe800ba5a14da818706 Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Fri, 3 Oct 2025 15:43:31 -0300 Subject: [PATCH 05/18] tests: update init tests --- pkg/cmd/init/init_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/cmd/init/init_test.go b/pkg/cmd/init/init_test.go index 136f199df..dba372571 100644 --- a/pkg/cmd/init/init_test.go +++ b/pkg/cmd/init/init_test.go @@ -735,6 +735,10 @@ func Test_initCmd_Run(t *testing.T) { unmarshal: tt.fields.unmarshal, git: tt.fields.git, } + // Ensure we always pass a non-nil cobra.Command to avoid nil deref in deps() + if tt.args.c == nil { + tt.args.c = NewCmd(tt.fields.f) + } if err := cmd.Run(tt.args.c, tt.args.in1); (err != nil) != tt.wantErr { t.Errorf("initCmd.Run() error = %v, wantErr %v", err, tt.wantErr) } From d4ee741fb6f84446ff4b969f3ee91681fb525acd Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Mon, 6 Oct 2025 10:37:32 -0300 Subject: [PATCH 06/18] chore: update workflow --- .github/workflows/test_and_build.yml | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test_and_build.yml b/.github/workflows/test_and_build.yml index 372619ac0..b8413436f 100644 --- a/.github/workflows/test_and_build.yml +++ b/.github/workflows/test_and_build.yml @@ -2,14 +2,13 @@ name: Test and Build on: pull_request: - types: [opened, synchronize] + types: [opened, synchronize, labeled, unlabeled] branches-ignore: - main - - dev - - pre-release-v4 jobs: build: + if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip-unit-tests') }} runs-on: ubuntu-latest container: image: golang:1.25.0 @@ -26,10 +25,25 @@ jobs: - name: Setting up a secure repository run: git config --global --add safe.directory /__w/azion/azion - - name: Build & Test + - uses: goreleaser/goreleaser-action@v6 + name: run goreleaser check + with: + distribution: goreleaser + version: 2.3.2 + args: check + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }} + + - name: Build & Test (skip v3 tests) run: | - echo "Building and testing" - make test build + echo "Building and testing (skipping v3 tests)" + mkdir -p cover + PKGS=$(go list ./... | grep -v "/pkg/v3commands/") + echo "Testing packages:" $PKGS + go test -v -failfast -coverprofile ./cover/azioncoverage.out -coverpkg=$(echo "$PKGS" | tr '\n' ',') $PKGS + go tool cover -html=./cover/azioncoverage.out -o ./cover/azioncoverage.html + go tool cover -func ./cover/azioncoverage.out + make build - name: Gosec run: | From 4d0a7cca2e693669a8ae6f8cdaafc596e614a923 Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Mon, 6 Oct 2025 11:11:37 -0300 Subject: [PATCH 07/18] chore: update APIURL var --- go.sum | 2 -- pkg/cmd/init/init.go | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/go.sum b/go.sum index f07799452..8792c4ec9 100644 --- a/go.sum +++ b/go.sum @@ -88,8 +88,6 @@ github.com/aws/smithy-go v1.23.0 h1:8n6I3gXzWJB2DxBDnfxgBaSX6oe0d/t10qGz7OKqMCE= github.com/aws/smithy-go v1.23.0/go.mod h1:t1ufH5HMublsJYulve2RKmHDC15xu1f26kHCp/HgceI= github.com/aziontech/azionapi-go-sdk v0.143.0 h1:4eEBlYT10prgeCVTNR9FIc7f59Crbl2zrH1a4D1BUqU= github.com/aziontech/azionapi-go-sdk v0.143.0/go.mod h1:cA5DY/VP4X5Eu11LpQNzNn83ziKjja7QVMIl4J45feA= -github.com/aziontech/azionapi-v4-go-sdk-dev v0.71.0 h1:GwS8mCmhh/8tgNSGGma0ic/WOr3rmmpOiBFaSQmvn5o= -github.com/aziontech/azionapi-v4-go-sdk-dev v0.71.0/go.mod h1:kJOyMICpeA+2xeo7/trGKGzMLdBMRKXM9A270vknSbI= github.com/aziontech/azionapi-v4-go-sdk-dev v0.74.0 h1:eVnoGTYq/D7xNJUajdUqVyxRNthIMgoc8vJg5DgCDPI= github.com/aziontech/azionapi-v4-go-sdk-dev v0.74.0/go.mod h1:kJOyMICpeA+2xeo7/trGKGzMLdBMRKXM9A270vknSbI= github.com/aziontech/go-thoth v0.0.0-20240228144710-d061a88cc39f h1:b0IX6tpiiG+QzCVOBqwYEHP5gPeeESq57A5ZXiYyDS4= diff --git a/pkg/cmd/init/init.go b/pkg/cmd/init/init.go index e1a4d2c3d..3933a496d 100644 --- a/pkg/cmd/init/init.go +++ b/pkg/cmd/init/init.go @@ -37,8 +37,7 @@ import ( const ( SAMPLESURL = "https://github.com/aziontech/azion-samples.git" - // APIURL = "https://api.azion.com/v4/utils/project_samples" - APIURL = "https://qxresbth58.map.azionedge.net/api/templates" + APIURL = "https://api.azion.com/v4/utils/project_samples" ) type initCmd struct { From e4e4f71268f7b9024fb4a978b401f0cfd9f269e6 Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Fri, 10 Oct 2025 15:21:05 -0300 Subject: [PATCH 08/18] feat: option to add deployment workflow --- messages/link/errors.go | 2 + messages/link/messages.go | 2 + pkg/cmd/link/link.go | 14 +++++++ pkg/github/constants.go | 77 +++++++++++++++++++++++++++++++++++++ pkg/github/github.go | 59 +++++++++++++++++++++++----- pkg/v3commands/link/link.go | 14 +++++++ 6 files changed, 158 insertions(+), 10 deletions(-) create mode 100644 pkg/github/constants.go diff --git a/messages/link/errors.go b/messages/link/errors.go index b4d917362..04b810d1d 100644 --- a/messages/link/errors.go +++ b/messages/link/errors.go @@ -20,4 +20,6 @@ var ( ErrorDeps = errors.New("Failed to install project dependencies") ErrorReadingGitignore = errors.New("Failed to read your .gitignore file") ErrorWritingGitignore = errors.New("Failed to write to your .gitignore file") + ErrorReadingWorkflow = errors.New("Failed to check for GitHub Actions workflow file") + ErrorWritingWorkflow = errors.New("Failed to write GitHub Actions workflow file") ) diff --git a/messages/link/messages.go b/messages/link/messages.go index 4d0241952..dd69a2f08 100644 --- a/messages/link/messages.go +++ b/messages/link/messages.go @@ -32,6 +32,8 @@ var ( AskLocalDev = "Do you want to start a local development server? (y/N)" AskGitignore = "Azion CLI creates some files during the build process for internal use. Would you like to add these to your .gitignore file? (Y/n)" WrittenGitignore = "Sucessfully written to your .gitignore file\n" + AskWorkflow = "Would you like to add a GitHub Actions workflow for automated deployment? (Y/n)" + WrittenWorkflow = "Successfully created GitHub Actions workflow file at .github/workflows/azion-deploy.yml\n" SkipFrameworkBuild = "Indicates whether to bypass the framework build phase before executing 'azion build'" ) diff --git a/pkg/cmd/link/link.go b/pkg/cmd/link/link.go index b4037d8d6..4b8213cf5 100644 --- a/pkg/cmd/link/link.go +++ b/pkg/cmd/link/link.go @@ -225,6 +225,20 @@ func (cmd *LinkCmd) run(c *cobra.Command, info *LinkInfo) error { msgs = append(msgs, msg.WrittenGitignore) } + //asks if user wants to add GitHub Actions workflow + workflowExists, err := git.CheckWorkflowFile(info.PathWorkingDir) + if err != nil { + return msg.ErrorReadingWorkflow + } + + if !workflowExists && (info.Auto || info.GlobalFlagAll || utils.Confirm(info.GlobalFlagAll, msg.AskWorkflow, true)) { + if err := git.WriteWorkflowFile(info.PathWorkingDir); err != nil { + return msg.ErrorWritingWorkflow + } + logger.FInfoFlags(cmd.Io.Out, msg.WrittenWorkflow, cmd.F.Format, cmd.F.Out) + msgs = append(msgs, msg.WrittenWorkflow) + } + cmdVulcanBuild := "build" if len(info.Preset) > 0 { cmdVulcanBuild = fmt.Sprintf("%s --preset '%s' --only-generate-config", cmdVulcanBuild, info.Preset) diff --git a/pkg/github/constants.go b/pkg/github/constants.go new file mode 100644 index 000000000..17b06d426 --- /dev/null +++ b/pkg/github/constants.go @@ -0,0 +1,77 @@ +package github + +const workflowContent = `name: Deploy Application using Azion CLI + +on: + workflow_dispatch: + inputs: + branch: + required: true + type: choice + default: main + options: + - main + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + + permissions: + contents: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Use Node.js 20.x + uses: actions/setup-node@v4 + with: + node-version: 20 + + # If you want to change package manager, change the command below and add the necessary configurations + - name: Install dependencies + run: npm install + + - name: Install Azion CLI + run: | + curl -o azionlinux https://downloads.azion.com/linux/x86_64/azion + sudo mv azionlinux /usr/bin/azion + sudo chmod u+x /usr/bin/azion + + - name: CLI version + run: azion --version + + # Configure a personal token in your github secrets + # You may create a personal token by running 'azion create personal-token' + - name: Configure token + run: | + azion -t ${{ secrets.AZION_PERSONAL_TOKEN }} + azion whoami + + - name: Azion Build + run: | + azion build + + # You may add the --sync flag to sync local and remote resources + - name: Azion Deploy + run: | + azion deploy --local --skip-build + + - name: Commit Azion files + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git add azion/azion.json azion.config.* || true + # Commit only if there are staged changes + if git diff --cached --quiet; then + echo "No Azion changes to commit. Skipping push." + else + git commit -m "chore: update azion files" + # Rebase in case remote has new commits, then push + git pull --rebase origin ${{ inputs.branch }} + git push + fi +` diff --git a/pkg/github/github.go b/pkg/github/github.go index 5a90ba5f8..8f353ce2e 100644 --- a/pkg/github/github.go +++ b/pkg/github/github.go @@ -20,11 +20,13 @@ import ( ) type Github struct { - GetVersionGitHub func(name string) (string, string, error) - Clone func(cloneOptions *git.CloneOptions, url, path string) error - GetNameRepo func(url string) string - CheckGitignore func(path string) (bool, error) - WriteGitignore func(path string) error + GetVersionGitHub func(name string) (string, string, error) + Clone func(cloneOptions *git.CloneOptions, url, path string) error + GetNameRepo func(url string) string + CheckGitignore func(path string) (bool, error) + WriteGitignore func(path string) error + CheckWorkflowFile func(path string) (bool, error) + WriteWorkflowFile func(path string) error } type Release struct { @@ -38,11 +40,13 @@ var ( func NewGithub() *Github { return &Github{ - GetVersionGitHub: getVersionGitHub, - Clone: clone, - GetNameRepo: getNameRepo, - CheckGitignore: checkGitignore, - WriteGitignore: writeGitignore, + GetVersionGitHub: getVersionGitHub, + Clone: clone, + GetNameRepo: getNameRepo, + CheckGitignore: checkGitignore, + WriteGitignore: writeGitignore, + CheckWorkflowFile: checkWorkflowFile, + WriteWorkflowFile: writeWorkflowFile, } } @@ -146,3 +150,38 @@ func writeGitignore(path string) error { return nil } + +func checkWorkflowFile(path string) (bool, error) { + logger.Debug("Checking for GitHub Actions workflow file") + workflowPath := filepath.Join(path, ".github", "workflows", "azion-deploy.yml") + + _, err := os.Stat(workflowPath) + if err != nil { + if errors.Is(err, os.ErrNotExist) { + return false, nil + } + return false, err + } + + return true, nil +} + +func writeWorkflowFile(path string) error { + logger.Debug("Writing GitHub Actions workflow file") + workflowDir := filepath.Join(path, ".github", "workflows") + workflowPath := filepath.Join(workflowDir, "azion-deploy.yml") + + // Create .github/workflows directory if it doesn't exist + if err := os.MkdirAll(workflowDir, 0755); err != nil { + logger.Error("Error creating workflow directory", zap.Error(err)) + return err + } + + // Write the workflow file + if err := os.WriteFile(workflowPath, []byte(workflowContent), 0644); err != nil { + logger.Error("Error writing workflow file", zap.Error(err)) + return err + } + + return nil +} diff --git a/pkg/v3commands/link/link.go b/pkg/v3commands/link/link.go index 50e519318..020792876 100644 --- a/pkg/v3commands/link/link.go +++ b/pkg/v3commands/link/link.go @@ -217,6 +217,20 @@ func (cmd *LinkCmd) run(c *cobra.Command, info *LinkInfo) error { msgs = append(msgs, msg.WrittenGitignore) } + //asks if user wants to add GitHub Actions workflow + workflowExists, err := git.CheckWorkflowFile(info.PathWorkingDir) + if err != nil { + return msg.ErrorReadingWorkflow + } + + if !workflowExists && (info.Auto || info.GlobalFlagAll || utils.Confirm(info.GlobalFlagAll, msg.AskWorkflow, true)) { + if err := git.WriteWorkflowFile(info.PathWorkingDir); err != nil { + return msg.ErrorWritingWorkflow + } + logger.FInfoFlags(cmd.Io.Out, msg.WrittenWorkflow, cmd.F.Format, cmd.F.Out) + msgs = append(msgs, msg.WrittenWorkflow) + } + if !info.Auto { if cmd.ShouldDevDeploy(info, msg.AskLocalDev, false) { if err := deps(c, cmd, info, msg.AskInstallDepsDev, &msgs); err != nil { From c5174ee0f79a3d5abc6bb2c1a3cb246e35c85111 Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Thu, 23 Oct 2025 10:21:52 -0300 Subject: [PATCH 09/18] refactor: update project dependencies --- go.mod | 36 ++++++++++++++++++------------------ go.sum | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index 4bb01abe4..e91d859f5 100644 --- a/go.mod +++ b/go.mod @@ -5,10 +5,10 @@ go 1.25.0 require ( github.com/AlecAivazis/survey/v2 v2.3.7 github.com/MakeNowJust/heredoc v1.0.0 - github.com/aws/aws-sdk-go-v2 v1.39.2 - github.com/aws/aws-sdk-go-v2/config v1.31.12 - github.com/aws/aws-sdk-go-v2/credentials v1.18.16 - github.com/aws/aws-sdk-go-v2/service/s3 v1.88.4 + github.com/aws/aws-sdk-go-v2 v1.39.3 + github.com/aws/aws-sdk-go-v2/config v1.31.14 + github.com/aws/aws-sdk-go-v2/credentials v1.18.18 + github.com/aws/aws-sdk-go-v2/service/s3 v1.88.6 github.com/aziontech/azionapi-go-sdk v0.143.0 github.com/aziontech/go-thoth v0.0.0-20240228144710-d061a88cc39f github.com/aziontech/tablecli v0.0.0-20241007135202-07712c07aa9e @@ -48,20 +48,20 @@ require ( dario.cat/mergo v1.0.0 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect github.com/ProtonMail/go-crypto v1.1.6 // indirect - github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.1 // indirect - github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.9 // indirect - github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.9 // indirect - github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.9 // indirect - github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3 // indirect - github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.9 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.1 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.0 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.9 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.9 // indirect - github.com/aws/aws-sdk-go-v2/service/sso v1.29.6 // indirect - github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.1 // indirect - github.com/aws/aws-sdk-go-v2/service/sts v1.38.6 // indirect - github.com/aws/smithy-go v1.23.0 // indirect + github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.2 // indirect + github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.10 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.10 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.10 // indirect + github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 // indirect + github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.10 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.2 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.1 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.10 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.10 // indirect + github.com/aws/aws-sdk-go-v2/service/sso v1.29.7 // indirect + github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.2 // indirect + github.com/aws/aws-sdk-go-v2/service/sts v1.38.8 // indirect + github.com/aws/smithy-go v1.23.1 // indirect github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect github.com/cloudflare/circl v1.6.1 // indirect diff --git a/go.sum b/go.sum index 428763819..22e2d3839 100644 --- a/go.sum +++ b/go.sum @@ -54,66 +54,102 @@ github.com/aws/aws-sdk-go-v2 v1.39.0 h1:xm5WV/2L4emMRmMjHFykqiA4M/ra0DJVSWUkDyBj github.com/aws/aws-sdk-go-v2 v1.39.0/go.mod h1:sDioUELIUO9Znk23YVmIk86/9DOpkbyyVb1i/gUNFXY= github.com/aws/aws-sdk-go-v2 v1.39.2 h1:EJLg8IdbzgeD7xgvZ+I8M1e0fL0ptn/M47lianzth0I= github.com/aws/aws-sdk-go-v2 v1.39.2/go.mod h1:sDioUELIUO9Znk23YVmIk86/9DOpkbyyVb1i/gUNFXY= +github.com/aws/aws-sdk-go-v2 v1.39.3 h1:h7xSsanJ4EQJXG5iuW4UqgP7qBopLpj84mpkNx3wPjM= +github.com/aws/aws-sdk-go-v2 v1.39.3/go.mod h1:yWSxrnioGUZ4WVv9TgMrNUeLV3PFESn/v+6T/Su8gnM= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.1 h1:i8p8P4diljCr60PpJp6qZXNlgX4m2yQFpYk+9ZT+J4E= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.1/go.mod h1:ddqbooRZYNoJ2dsTwOty16rM+/Aqmk/GOXrK8cg7V00= +github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.2 h1:t9yYsydLYNBk9cJ73rgPhPWqOh/52fcWDQB5b1JsKSY= +github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.2/go.mod h1:IusfVNTmiSN3t4rhxWFaBAqn+mcNdwKtPcV16eYdgko= github.com/aws/aws-sdk-go-v2/config v1.31.8 h1:kQjtOLlTU4m4A64TsRcqwNChhGCwaPBt+zCQt/oWsHU= github.com/aws/aws-sdk-go-v2/config v1.31.8/go.mod h1:QPpc7IgljrKwH0+E6/KolCgr4WPLerURiU592AYzfSY= github.com/aws/aws-sdk-go-v2/config v1.31.12 h1:pYM1Qgy0dKZLHX2cXslNacbcEFMkDMl+Bcj5ROuS6p8= github.com/aws/aws-sdk-go-v2/config v1.31.12/go.mod h1:/MM0dyD7KSDPR+39p9ZNVKaHDLb9qnfDurvVS2KAhN8= +github.com/aws/aws-sdk-go-v2/config v1.31.14 h1:kj/KpDqvt0UqcEL3WOvCykE9QUpBb6b23hQdnXe+elo= +github.com/aws/aws-sdk-go-v2/config v1.31.14/go.mod h1:X5PaY6QCzViihn/ru7VxnIamcJQrG9NSeTxuSKm2YtU= github.com/aws/aws-sdk-go-v2/credentials v1.18.13 h1:gkpEm65/ZfrGJ3wbFH++Ki7DyaWtsWbK9idX6OXCo2E= github.com/aws/aws-sdk-go-v2/credentials v1.18.13/go.mod h1:eVTHz1yI2/WIlXTE8f70mcrSxNafXD5sJpTIM9f+kmo= github.com/aws/aws-sdk-go-v2/credentials v1.18.16 h1:4JHirI4zp958zC026Sm+V4pSDwW4pwLefKrc0bF2lwI= github.com/aws/aws-sdk-go-v2/credentials v1.18.16/go.mod h1:qQMtGx9OSw7ty1yLclzLxXCRbrkjWAM7JnObZjmCB7I= +github.com/aws/aws-sdk-go-v2/credentials v1.18.18 h1:5AfxTvDN0AJoA7rg/yEc0sHhl6/B9fZ+NtiQuOjWGQM= +github.com/aws/aws-sdk-go-v2/credentials v1.18.18/go.mod h1:m9mE1mJ1s7zI6rrt7V3RQU2SCgUbNaphlfqEksLp+Fs= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.7 h1:Is2tPmieqGS2edBnmOJIbdvOA6Op+rRpaYR60iBAwXM= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.7/go.mod h1:F1i5V5421EGci570yABvpIXgRIBPb5JM+lSkHF6Dq5w= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.9 h1:Mv4Bc0mWmv6oDuSWTKnk+wgeqPL5DRFu5bQL9BGPQ8Y= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.9/go.mod h1:IKlKfRppK2a1y0gy1yH6zD+yX5uplJ6UuPlgd48dJiQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.10 h1:UuGVOX48oP4vgQ36oiKmW9RuSeT8jlgQgBFQD+HUiHY= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.10/go.mod h1:vM/Ini41PzvudT4YkQyE/+WiQJiQ6jzeDyU8pQKwCac= github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.7 h1:UCxq0X9O3xrlENdKf1r9eRJoKz/b0AfGkpp3a7FPlhg= github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.7/go.mod h1:rHRoJUNUASj5Z/0eqI4w32vKvC7atoWR0jC+IkmVH8k= github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.9 h1:se2vOWGD3dWQUtfn4wEjRQJb1HK1XsNIt825gskZ970= github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.9/go.mod h1:hijCGH2VfbZQxqCDN7bwz/4dzxV+hkyhjawAtdPWKZA= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.10 h1:mj/bdWleWEh81DtpdHKkw41IrS+r3uw1J/VQtbwYYp8= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.10/go.mod h1:7+oEMxAZWP8gZCyjcm9VicI0M61Sx4DJtcGfKYv2yKQ= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.7 h1:Y6DTZUn7ZUC4th9FMBbo8LVE+1fyq3ofw+tRwkUd3PY= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.7/go.mod h1:x3XE6vMnU9QvHN/Wrx2s44kwzV2o2g5x/siw4ZUJ9g8= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.9 h1:6RBnKZLkJM4hQ+kN6E7yWFveOTg8NLPHAkqrs4ZPlTU= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.9/go.mod h1:V9rQKRmK7AWuEsOMnHzKj8WyrIir1yUJbZxDuZLFvXI= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.10 h1:wh+/mn57yhUrFtLIxyFPh2RgxgQz/u+Yrf7hiHGHqKY= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.10/go.mod h1:7zirD+ryp5gitJJ2m1BBux56ai8RIRDykXZrJSp540w= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3 h1:bIqFDwgGXXN1Kpp99pDOdKMTTb5d2KyU5X/BZxjOkRo= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3/go.mod h1:H5O/EsxDWyU+LP/V8i5sm8cxoZgc2fdNR9bxlOFrQTo= +github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 h1:WKuaxf++XKWlHWu9ECbMlha8WOEGm0OUEZqm4K/Gcfk= +github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4/go.mod h1:ZWy7j6v1vWGmPReu0iSGvRiise4YI5SkR3OHKTZ6Wuc= github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.7 h1:BszAktdUo2xlzmYHjWMq70DqJ7cROM8iBd3f6hrpuMQ= github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.7/go.mod h1:XJ1yHki/P7ZPuG4fd3f0Pg/dSGA2cTQBCLw82MH2H48= github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.9 h1:w9LnHqTq8MEdlnyhV4Bwfizd65lfNCNgdlNC6mM5paE= github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.9/go.mod h1:LGEP6EK4nj+bwWNdrvX/FnDTFowdBNwcSPuZu/ouFys= +github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.10 h1:FHw90xCTsofzk6vjU808TSuDtDfOOKPNdz5Weyc3tUI= +github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.10/go.mod h1:n8jdIE/8F3UYkg8O4IGkQpn2qUmapg/1K1yl29/uf/c= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.1 h1:oegbebPEMA/1Jny7kvwejowCaHz1FWZAQ94WXFNCyTM= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.1/go.mod h1:kemo5Myr9ac0U9JfSjMo9yHLtw+pECEHsFtJ9tqCEI8= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.2 h1:xtuxji5CS0JknaXoACOunXOYOQzgfTvGAc9s2QdCJA4= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.2/go.mod h1:zxwi0DIR0rcRcgdbl7E2MSOvxDyyXGBlScvBkARFaLQ= github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.8.7 h1:zmZ8qvtE9chfhBPuKB2aQFxW5F/rpwXUgmcVCgQzqRw= github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.8.7/go.mod h1:vVYfbpd2l+pKqlSIDIOgouxNsGu5il9uDp0ooWb0jys= github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.0 h1:X0FveUndcZ3lKbSpIC6rMYGRiQTcUVRNH6X4yYtIrlU= github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.0/go.mod h1:IWjQYlqw4EX9jw2g3qnEPPWvCE6bS8fKzhMed1OK7c8= +github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.1 h1:ne+eepnDB2Wh5lHKzELgEncIqeVlQ1rSF9fEa4r5I+A= +github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.1/go.mod h1:u0Jkg0L+dcG1ozUq21uFElmpbmjBnhHR5DELHIme4wg= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.7 h1:mLgc5QIgOy26qyh5bvW+nDoAppxgn3J2WV3m9ewq7+8= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.7/go.mod h1:wXb/eQnqt8mDQIQTTmcw58B5mYGxzLGZGK8PWNFZ0BA= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.9 h1:5r34CgVOD4WZudeEKZ9/iKpiT6cM1JyEROpXjOcdWv8= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.9/go.mod h1:dB12CEbNWPbzO2uC6QSWHteqOg4JfBVJOojbAoAUb5I= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.10 h1:DRND0dkCKtJzCj4Xl4OpVbXZgfttY5q712H9Zj7qc/0= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.10/go.mod h1:tGGNmJKOTernmR2+VJ0fCzQRurcPZj9ut60Zu5Fi6us= github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.7 h1:u3VbDKUCWarWiU+aIUK4gjTr/wQFXV17y3hgNno9fcA= github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.7/go.mod h1:/OuMQwhSyRapYxq6ZNpPer8juGNrB4P5Oz8bZ2cgjQE= github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.9 h1:wuZ5uW2uhJR63zwNlqWH2W4aL4ZjeJP3o92/W+odDY4= github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.9/go.mod h1:/G58M2fGszCrOzvJUkDdY8O9kycodunH4VdT5oBAqls= +github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.10 h1:DA+Hl5adieRyFvE7pCvBWm3VOZTRexGVkXw33SUqNoY= +github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.10/go.mod h1:L+A89dH3/gr8L4ecrdzuXUYd1znoko6myzndVGZx/DA= github.com/aws/aws-sdk-go-v2/service/s3 v1.88.1 h1:+RpGuaQ72qnU83qBKVwxkznewEdAGhIWo/PQCmkhhog= github.com/aws/aws-sdk-go-v2/service/s3 v1.88.1/go.mod h1:xajPTguLoeQMAOE44AAP2RQoUhF8ey1g5IFHARv71po= github.com/aws/aws-sdk-go-v2/service/s3 v1.88.4 h1:mUI3b885qJgfqKDUSj6RgbRqLdX0wGmg8ruM03zNfQA= github.com/aws/aws-sdk-go-v2/service/s3 v1.88.4/go.mod h1:6v8ukAxc7z4x4oBjGUsLnH7KGLY9Uhcgij19UJNkiMg= +github.com/aws/aws-sdk-go-v2/service/s3 v1.88.6 h1:Hcb4yllr4GTOHC/BKjEklxWhciWMHIqzeCI9oYf1OIk= +github.com/aws/aws-sdk-go-v2/service/s3 v1.88.6/go.mod h1:N/iojY+8bW3MYol9NUMuKimpSbPEur75cuI1SmtonFM= github.com/aws/aws-sdk-go-v2/service/sso v1.29.3 h1:7PKX3VYsZ8LUWceVRuv0+PU+E7OtQb1lgmi5vmUE9CM= github.com/aws/aws-sdk-go-v2/service/sso v1.29.3/go.mod h1:Ql6jE9kyyWI5JHn+61UT/Y5Z0oyVJGmgmJbZD5g4unY= github.com/aws/aws-sdk-go-v2/service/sso v1.29.6 h1:A1oRkiSQOWstGh61y4Wc/yQ04sqrQZr1Si/oAXj20/s= github.com/aws/aws-sdk-go-v2/service/sso v1.29.6/go.mod h1:5PfYspyCU5Vw1wNPsxi15LZovOnULudOQuVxphSflQA= +github.com/aws/aws-sdk-go-v2/service/sso v1.29.7 h1:fspVFg6qMx0svs40YgRmE7LZXh9VRZvTT35PfdQR6FM= +github.com/aws/aws-sdk-go-v2/service/sso v1.29.7/go.mod h1:BQTKL3uMECaLaUV3Zc2L4Qybv8C6BIXjuu1dOPyxTQs= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.34.5 h1:gBBZmSuIySGqDLtXdZiYpwyzbJKXQD2jjT0oDY6ywbo= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.34.5/go.mod h1:XclEty74bsGBCr1s0VSaA11hQ4ZidK4viWK7rRfO88I= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.1 h1:5fm5RTONng73/QA73LhCNR7UT9RpFH3hR6HWL6bIgVY= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.1/go.mod h1:xBEjWD13h+6nq+z4AkqSfSvqRKFgDIQeaMguAJndOWo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.2 h1:scVnW+NLXasGOhy7HhkdT9AGb6kjgW7fJ5xYkUaqHs0= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.2/go.mod h1:FRNCY3zTEWZXBKm2h5UBUPvCVDOecTad9KhynDyGBc0= github.com/aws/aws-sdk-go-v2/service/sts v1.38.4 h1:PR00NXRYgY4FWHqOGx3fC3lhVKjsp1GdloDv2ynMSd8= github.com/aws/aws-sdk-go-v2/service/sts v1.38.4/go.mod h1:Z+Gd23v97pX9zK97+tX4ppAgqCt3Z2dIXB02CtBncK8= github.com/aws/aws-sdk-go-v2/service/sts v1.38.6 h1:p3jIvqYwUZgu/XYeI48bJxOhvm47hZb5HUQ0tn6Q9kA= github.com/aws/aws-sdk-go-v2/service/sts v1.38.6/go.mod h1:WtKK+ppze5yKPkZ0XwqIVWD4beCwv056ZbPQNoeHqM8= +github.com/aws/aws-sdk-go-v2/service/sts v1.38.8 h1:xSL4IV19pKDASL2fjWXRfTGmZddPiPPZNPpbv6uZQZY= +github.com/aws/aws-sdk-go-v2/service/sts v1.38.8/go.mod h1:L1xxV3zAdB+qVrVW/pBIrIAnHFWHo6FBbFe4xOGsG/o= github.com/aws/smithy-go v1.23.0 h1:8n6I3gXzWJB2DxBDnfxgBaSX6oe0d/t10qGz7OKqMCE= github.com/aws/smithy-go v1.23.0/go.mod h1:t1ufH5HMublsJYulve2RKmHDC15xu1f26kHCp/HgceI= +github.com/aws/smithy-go v1.23.1 h1:sLvcH6dfAFwGkHLZ7dGiYF7aK6mg4CgKA/iDKjLDt9M= +github.com/aws/smithy-go v1.23.1/go.mod h1:LEj2LM3rBRQJxPZTB4KuzZkaZYnZPnvgIhb4pu07mx0= github.com/aziontech/azionapi-go-sdk v0.143.0 h1:4eEBlYT10prgeCVTNR9FIc7f59Crbl2zrH1a4D1BUqU= github.com/aziontech/azionapi-go-sdk v0.143.0/go.mod h1:cA5DY/VP4X5Eu11LpQNzNn83ziKjja7QVMIl4J45feA= github.com/aziontech/azionapi-v4-go-sdk-dev v0.71.0 h1:GwS8mCmhh/8tgNSGGma0ic/WOr3rmmpOiBFaSQmvn5o= From 457fdc5d3c2f14a4b2bb7c0b043f2276cbea32cf Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Thu, 23 Oct 2025 11:44:40 -0300 Subject: [PATCH 10/18] refactor: use object to unmarshal json --- pkg/cmd/init/contracts.go | 4 ++-- pkg/cmd/init/utils.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/cmd/init/contracts.go b/pkg/cmd/init/contracts.go index 3bbcc4b03..cda077f51 100644 --- a/pkg/cmd/init/contracts.go +++ b/pkg/cmd/init/contracts.go @@ -10,8 +10,8 @@ type Item struct { Message string `json:"message"` Preset string `json:"preset"` Path string `json:"path"` - Link string `json:"link"` - RequiresAdditionalBuild *bool `json:"requires_additional_build"` + Link string `json:"link,omitempty"` + RequiresAdditionalBuild *bool `json:"requires_additional_build,omitempty"` Extras *Extras `json:"extras,omitempty"` } diff --git a/pkg/cmd/init/utils.go b/pkg/cmd/init/utils.go index e19fc0a4e..bf86e0052 100644 --- a/pkg/cmd/init/utils.go +++ b/pkg/cmd/init/utils.go @@ -98,13 +98,13 @@ func (cmd *initCmd) getVulcanInfo() (string, error) { return "", err } - var infoJson map[string]string + var infoJson Item err = cmd.unmarshal(fileContent, &infoJson) if err != nil { logger.Debug("Error unmarshalling template info", zap.Error(err)) return "", err } - logger.Debug("Information about the template:", zap.Any("preset", infoJson["preset"])) - return infoJson["preset"], nil + logger.Debug("Information about the template:", zap.Any("preset", infoJson.Preset)) + return infoJson.Preset, nil } From 7da3043eeebb4da49d9d7a75e87ff3e9a3100f2c Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Thu, 23 Oct 2025 11:58:09 -0300 Subject: [PATCH 11/18] tests: update unit tests for unmarshal --- pkg/cmd/init/utils_test.go | 46 +++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/init/utils_test.go b/pkg/cmd/init/utils_test.go index a1b1053ed..e3c5742a8 100644 --- a/pkg/cmd/init/utils_test.go +++ b/pkg/cmd/init/utils_test.go @@ -391,8 +391,8 @@ func Test_initCmd_getVulcanInfo(t *testing.T) { pathWorkingDir: "/path/to/working/dir", unmarshal: func(data []byte, v interface{}) error { // Mocking unmarshalling process - *(v.(*map[string]string)) = map[string]string{ - "preset": "astro", + *(v.(*Item)) = Item{ + Preset: "astro", } return nil }, @@ -400,7 +400,47 @@ func Test_initCmd_getVulcanInfo(t *testing.T) { wantPreset: "astro", wantErr: false, readFile: func(filename string) ([]byte, error) { - return []byte(`{"preset": "astro"}`), nil + return []byte(`{"name": "Test Template", "message": "A test template", "preset": "astro", "path": "/test"}`), nil + }, + }, + { + name: "flow completed with complex extras structure", + fields: fields{ + pathWorkingDir: "/path/to/working/dir", + unmarshal: func(data []byte, v interface{}) error { + // Mocking unmarshalling process with complex structure + *(v.(*Item)) = Item{ + Name: "Cosmic - Simple Astro Blog", + Message: "An Astro blog template powered by Cosmic", + Preset: "astro", + Path: "/cosmic-simple-astro-blog", + Extras: &Extras{ + Type: "env", + Inputs: []ExtraInput{ + {Key: "PUBLIC_COSMIC_BUCKET_SLUG", Text: "Type the Bucket Slug of your Cosmic project"}, + {Key: "PUBLIC_COSMIC_READ_KEY", Text: "Type the Read Key of your Cosmic project"}, + }, + }, + } + return nil + }, + }, + wantPreset: "astro", + wantErr: false, + readFile: func(filename string) ([]byte, error) { + return []byte(`{ + "name": "Cosmic - Simple Astro Blog", + "message": "An Astro blog template powered by Cosmic", + "preset": "astro", + "path": "/cosmic-simple-astro-blog", + "extras": { + "type": "env", + "inputs": [ + {"key": "PUBLIC_COSMIC_BUCKET_SLUG", "text": "Type the Bucket Slug of your Cosmic project"}, + {"key": "PUBLIC_COSMIC_READ_KEY", "text": "Type the Read Key of your Cosmic project"} + ] + } + }`), nil }, }, { From 9e98c60f98fbec71ddc797280c2947a30656c07d Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Fri, 24 Oct 2025 11:10:20 -0300 Subject: [PATCH 12/18] chore: write azion.config returned from remote deploy --- pkg/cmd/deploy/deploy.go | 8 ++++++++ pkg/contracts/contracts.go | 18 ++++++++++++------ utils/helpers.go | 31 +++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/pkg/cmd/deploy/deploy.go b/pkg/cmd/deploy/deploy.go index 83428dc5e..c8c072ef6 100644 --- a/pkg/cmd/deploy/deploy.go +++ b/pkg/cmd/deploy/deploy.go @@ -39,6 +39,7 @@ type DeployCmd struct { WriteFile func(filename string, data []byte, perm fs.FileMode) error GetAzionJsonContent func(pathConfig string) (*contracts.AzionApplicationOptions, error) WriteAzionJsonContent func(conf *contracts.AzionApplicationOptions, confConf string) error + WriteAzionConfig func(conf *contracts.AzionConfig) error BuildCmd func(f *cmdutil.Factory) *build.BuildCmd Open func(name string) (*os.File, error) FilepathWalk func(root string, fn filepath.WalkFunc) error @@ -82,6 +83,7 @@ func NewDeployCmd(f *cmdutil.Factory) *DeployCmd { BuildCmd: build.NewBuildCmd, GetAzionJsonContent: utils.GetAzionJsonContent, WriteAzionJsonContent: utils.WriteAzionJsonContent, + WriteAzionConfig: utils.WriteAzionConfig, Open: os.Open, FilepathWalk: filepath.Walk, Unmarshal: json.Unmarshal, @@ -370,6 +372,12 @@ func captureLogs(execId, token string, cmd *DeployCmd) error { if err != nil { return err } + + err = cmd.WriteAzionConfig(Result.Result.AzionConfig) + if err != nil { + return err + } + default: s.Stop() return msg.ErrorDeployRemote diff --git a/pkg/contracts/contracts.go b/pkg/contracts/contracts.go index d071c0530..aa089c7f1 100644 --- a/pkg/contracts/contracts.go +++ b/pkg/contracts/contracts.go @@ -105,15 +105,21 @@ type ResultsV4 struct { } type Result struct { - Azion *AzionApplicationOptionsV3 `json:"azion,omitempty"` // Pointer and omitempty tag - Extras []interface{} `json:"extras"` // Assuming Extras can contain any data - Errors *ErrorDetails `json:"errors,omitempty"` // Pointer and omitempty for optional errors + Azion *AzionApplicationOptionsV3 `json:"azion,omitempty"` + Extras []interface{} `json:"extras"` + Errors *ErrorDetails `json:"errors,omitempty"` } type ResultV4 struct { - Azion *AzionApplicationOptions `json:"azion,omitempty"` // Pointer and omitempty tag - Extras []interface{} `json:"extras"` // Assuming Extras can contain any data - Errors *ErrorDetails `json:"errors,omitempty"` // Pointer and omitempty for optional errors + Azion *AzionApplicationOptions `json:"azion,omitempty"` + Extras []interface{} `json:"extras"` + Errors *ErrorDetails `json:"errors,omitempty"` + AzionConfig *AzionConfig `json:"azion_config,omitempty"` +} + +type AzionConfig struct { + FileName string `json:"file_name"` + FileContent string `json:"file_content"` } type ErrorDetails struct { diff --git a/utils/helpers.go b/utils/helpers.go index 08df7c798..fe25834b2 100644 --- a/utils/helpers.go +++ b/utils/helpers.go @@ -230,6 +230,37 @@ func WriteAzionJsonContentV3(conf *contracts.AzionApplicationOptionsV3, confPath return nil } +func WriteAzionConfig(conf *contracts.AzionConfig) error { + logger.Debug("Writing your azion.config file", zap.Any("File name", conf.FileName)) + // Get the current working directory + wd, err := GetWorkingDir() + if err != nil { + return err + } + + // Process the FileContent to handle escape sequences + processedContent := strings.ReplaceAll(conf.FileContent, "\\n", "\n") + processedContent = strings.ReplaceAll(processedContent, "\\t", "\t") + processedContent = strings.ReplaceAll(processedContent, "\\r", "\r") + processedContent = strings.ReplaceAll(processedContent, "\\\"", "\"") + processedContent = strings.ReplaceAll(processedContent, "\\'", "'") + processedContent = strings.ReplaceAll(processedContent, "\\\\", "\\") + + // Create the full file path + filePath := path.Join(wd, conf.FileName) + + // Write the processed content to the file (overwrite if exists) + err = os.WriteFile(filePath, []byte(processedContent), 0644) + if err != nil { + logger.Debug("Error writing config file", zap.Error(err)) + return fmt.Errorf("failed to write config file %s: %w", filePath, err) + } + + logger.Debug("Config file written successfully", zap.Any("File name", conf.FileName)) + + return nil +} + func ErrorPerStatusCode(httpResp *http.Response, err error) error { // when the CLI times out, probably due to SSO communication, httpResp is null and/or http status is 500; From ded5a99321f715242aab6f0645bf3ed2e198e5be Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Fri, 24 Oct 2025 11:15:26 -0300 Subject: [PATCH 13/18] tests: update deploy unit tests --- pkg/cmd/deploy/deploy_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/cmd/deploy/deploy_test.go b/pkg/cmd/deploy/deploy_test.go index 705b9fed9..42484b0b1 100644 --- a/pkg/cmd/deploy/deploy_test.go +++ b/pkg/cmd/deploy/deploy_test.go @@ -101,6 +101,11 @@ func MockCaptureLogs(execId string, token string, cmd *DeployCmd) error { return nil } +// MockWriteAzionConfig mocks WriteAzionConfig behavior +func MockWriteAzionConfig(conf *contracts.AzionConfig) error { + return nil +} + func TestDeploy_Run(t *testing.T) { logger.New(zapcore.DebugLevel) tests := []struct { @@ -120,6 +125,7 @@ func TestDeploy_Run(t *testing.T) { cmd.OpenBrowser = MockOpenBrowser cmd.CaptureLogs = MockCaptureLogs cmd.CheckToken = MockCheckToken + cmd.WriteAzionConfig = MockWriteAzionConfig // Return populated settings so that the deploy flow skips bucket/credentials creation cmd.ReadSettings = MockReadSettings cmd.UploadFiles = func(f *cmdutil.Factory, conf *contracts.AzionApplicationOptions, msgs *[]string, pathStatic, bucket string, cmd *DeployCmd, settings token.Settings) error { @@ -141,6 +147,7 @@ func TestDeploy_Run(t *testing.T) { cmd.CaptureLogs = MockCaptureLogs cmd.CheckToken = MockCheckToken cmd.ReadSettings = MockReadSettings + cmd.WriteAzionConfig = MockWriteAzionConfig cmd.UploadFiles = func(f *cmdutil.Factory, conf *contracts.AzionApplicationOptions, msgs *[]string, pathStatic, bucket string, cmd *DeployCmd, settings token.Settings) error { return nil } @@ -157,6 +164,7 @@ func TestDeploy_Run(t *testing.T) { cmd.WriteAzionJsonContent = MockWriteAzionJsonContent cmd.CheckToken = MockCheckToken cmd.ReadSettings = MockReadSettings + cmd.WriteAzionConfig = MockWriteAzionConfig cmd.UploadFiles = func(f *cmdutil.Factory, conf *contracts.AzionApplicationOptions, msgs *[]string, pathStatic, bucket string, cmd *DeployCmd, settings token.Settings) error { return nil } @@ -268,6 +276,9 @@ func TestCaptureLogs(t *testing.T) { cmd.WriteAzionJsonContent = func(conf *contracts.AzionApplicationOptions, confConf string) error { return nil } + cmd.WriteAzionConfig = func(conf *contracts.AzionConfig) error { + return nil + } err := cmd.CaptureLogs(execID, token, cmd) // Check for expected error From a9b2b28f58d0aa774759aba332c09fe0c08109cf Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Mon, 27 Oct 2025 11:12:09 -0300 Subject: [PATCH 14/18] chore: clean batch files after deploy is run --- pkg/cmd/deploy/upload.go | 7 +++++++ pkg/cmd/deploy/zip.go | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/pkg/cmd/deploy/upload.go b/pkg/cmd/deploy/upload.go index fb9540dd7..148481c9f 100644 --- a/pkg/cmd/deploy/upload.go +++ b/pkg/cmd/deploy/upload.go @@ -100,6 +100,13 @@ func uploadFiles(f *cmdutil.Factory, conf *contracts.AzionApplicationOptions, ms return err } + // Ensure cleanup of temporary zip files after upload completion or on error + defer func() { + if cleanupErr := CleanupZipFiles(); cleanupErr != nil { + logger.Debug("Failed to cleanup temporary zip files", zap.Error(cleanupErr)) + } + }() + listZip, err := ReadZip() if err != nil { return err diff --git a/pkg/cmd/deploy/zip.go b/pkg/cmd/deploy/zip.go index 8db766f85..f21bdd0d1 100644 --- a/pkg/cmd/deploy/zip.go +++ b/pkg/cmd/deploy/zip.go @@ -14,8 +14,6 @@ import ( "go.uber.org/zap" ) -// CreateZipsInBatches Function to split files into batches of up to 1MB and -// create ZIPs keeping the directory structure func CreateZipsInBatches(files []contracts.FileOps) error { const maxBatchSize = 1 * 1024 * 1024 // 1MB em bytes var currentBatch []contracts.FileOps @@ -60,7 +58,6 @@ func CreateZipsInBatches(files []contracts.FileOps) error { return nil } -// createZip Helper function to create a ZIP file from a batch of FileOps while maintaining the directory structure func createZip(batch []contracts.FileOps, destDir string, batchNumber int) error { zipFileName := fmt.Sprintf("batch_%d.zip", batchNumber) zipFilePath := filepath.Join(destDir, zipFileName) @@ -104,8 +101,6 @@ func createZip(batch []contracts.FileOps, destDir string, batchNumber int) error return nil } -// ReadZip reads the ZIP files in the pathStatic directory that start with -// prefix and end with .zip. Returns a list of contracts.FileOps or an error. func ReadZip() ([]contracts.FileOps, error) { var listZIP []contracts.FileOps @@ -141,3 +136,35 @@ func ReadZip() ([]contracts.FileOps, error) { return listZIP, nil } + +func CleanupZipFiles() error { + logger.Debug("Running cleanup for batch zip files") + tempDir := os.TempDir() + + files, err := os.ReadDir(tempDir) + if err != nil { + logger.Debug("Error reading temp directory for cleanup", zap.Error(err)) + return err + } + + var cleanupErrors []error + for _, f := range files { + if strings.ToLower(filepath.Ext(f.Name())) == ".zip" && + strings.HasPrefix(f.Name(), "batch") { + zipPath := filepath.Join(tempDir, f.Name()) + logger.Debug("Removing temporary ZIP file", zap.String("path", zipPath)) + + if err := os.Remove(zipPath); err != nil { + logger.Debug("Error removing ZIP file", zap.String("path", zipPath), zap.Error(err)) + cleanupErrors = append(cleanupErrors, err) + } + } + } + + if len(cleanupErrors) > 0 { + logger.Debug("Some ZIP files could not be removed during cleanup", zap.Int("count", len(cleanupErrors))) + return cleanupErrors[0] + } + + return nil +} From 24506d2d1eb41f2176f48c7d324bf2886046d49d Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Mon, 27 Oct 2025 11:12:35 -0300 Subject: [PATCH 15/18] refactor: update cleanup files --- pkg/cmd/deploy/upload.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/cmd/deploy/upload.go b/pkg/cmd/deploy/upload.go index 148481c9f..f845b32dd 100644 --- a/pkg/cmd/deploy/upload.go +++ b/pkg/cmd/deploy/upload.go @@ -100,7 +100,6 @@ func uploadFiles(f *cmdutil.Factory, conf *contracts.AzionApplicationOptions, ms return err } - // Ensure cleanup of temporary zip files after upload completion or on error defer func() { if cleanupErr := CleanupZipFiles(); cleanupErr != nil { logger.Debug("Failed to cleanup temporary zip files", zap.Error(cleanupErr)) From 5528974f2a92a9138091f2568e0a77c5dadc7e25 Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Mon, 27 Oct 2025 14:52:54 -0300 Subject: [PATCH 16/18] refactor: security checks --- .github/workflows/cla.yml | 3 +++ .github/workflows/deploy_prod.yml | 12 ++++++++++++ .github/workflows/deploy_stage.yml | 3 +++ .github/workflows/e2e_test.yml | 3 +++ .github/workflows/generate_docs.yml | 3 +++ .github/workflows/package-audit.yaml | 3 +++ .github/workflows/scc-checker.yml | 3 +++ .github/workflows/test_and_build.yml | 3 +++ pkg/cmd/create/domain/domain.go | 8 ++++---- 9 files changed, 37 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cla.yml b/.github/workflows/cla.yml index dd9a3c44b..ab120990b 100644 --- a/.github/workflows/cla.yml +++ b/.github/workflows/cla.yml @@ -7,6 +7,9 @@ on: jobs: CLAssistant: + permissions: + contents: read + pull-requests: write runs-on: ubuntu-latest container: image: ubuntu:24.04 diff --git a/.github/workflows/deploy_prod.yml b/.github/workflows/deploy_prod.yml index a1c31be73..9babf450b 100644 --- a/.github/workflows/deploy_prod.yml +++ b/.github/workflows/deploy_prod.yml @@ -8,6 +8,9 @@ on: jobs: build: + permissions: + contents: read + pull-requests: write runs-on: ubuntu-latest container: image: golang:1.25.0 @@ -96,6 +99,9 @@ jobs: bump_formula: + permissions: + contents: read + pull-requests: write runs-on: ubuntu-latest needs: build steps: @@ -106,6 +112,9 @@ jobs: tag: ${{needs.build.outputs.binver}} publish-choco-package: + permissions: + contents: read + pull-requests: write runs-on: windows-latest needs: build steps: @@ -170,6 +179,9 @@ jobs: shell: pwsh Publish-to-WinGet: + permissions: + contents: read + pull-requests: write runs-on: windows-latest needs: [build, bump_formula] steps: diff --git a/.github/workflows/deploy_stage.yml b/.github/workflows/deploy_stage.yml index 4caea48d5..f5cb6fe3b 100644 --- a/.github/workflows/deploy_stage.yml +++ b/.github/workflows/deploy_stage.yml @@ -8,6 +8,9 @@ on: jobs: build: + permissions: + contents: read + pull-requests: write runs-on: ubuntu-latest container: image: golang:1.25.0 diff --git a/.github/workflows/e2e_test.yml b/.github/workflows/e2e_test.yml index cf2d8bf5d..0a43077d9 100644 --- a/.github/workflows/e2e_test.yml +++ b/.github/workflows/e2e_test.yml @@ -8,6 +8,9 @@ on: jobs: build: + permissions: + contents: read + pull-requests: write runs-on: ubuntu-latest if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip-e2e') }} container: diff --git a/.github/workflows/generate_docs.yml b/.github/workflows/generate_docs.yml index aef1a477c..b2ef0b4f0 100644 --- a/.github/workflows/generate_docs.yml +++ b/.github/workflows/generate_docs.yml @@ -8,6 +8,9 @@ on: jobs: build: + permissions: + contents: read + pull-requests: write runs-on: ubuntu-latest container: image: golang:1.25.0 diff --git a/.github/workflows/package-audit.yaml b/.github/workflows/package-audit.yaml index 158811420..5521732f7 100644 --- a/.github/workflows/package-audit.yaml +++ b/.github/workflows/package-audit.yaml @@ -6,6 +6,9 @@ on: jobs: PackageAuditing: + permissions: + contents: read + pull-requests: write name: Package Auditor (GoVulnCheck) runs-on: ubuntu-latest container: diff --git a/.github/workflows/scc-checker.yml b/.github/workflows/scc-checker.yml index 358ec57b9..229c6598a 100644 --- a/.github/workflows/scc-checker.yml +++ b/.github/workflows/scc-checker.yml @@ -6,6 +6,9 @@ on: jobs: scc-check: + permissions: + contents: read + pull-requests: write runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/test_and_build.yml b/.github/workflows/test_and_build.yml index b8413436f..2229d6948 100644 --- a/.github/workflows/test_and_build.yml +++ b/.github/workflows/test_and_build.yml @@ -8,6 +8,9 @@ on: jobs: build: + permissions: + contents: read + pull-requests: write if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip-unit-tests') }} runs-on: ubuntu-latest container: diff --git a/pkg/cmd/create/domain/domain.go b/pkg/cmd/create/domain/domain.go index cadb40a3d..106fe9e57 100644 --- a/pkg/cmd/create/domain/domain.go +++ b/pkg/cmd/create/domain/domain.go @@ -22,7 +22,7 @@ type Fields struct { Name string `json:"name"` Cnames []string `json:"cnames"` CnameAccessOnly string `json:"cname_access_only"` - EdgeApplicationID int `json:"edge_application_id"` + EdgeApplicationID int64 `json:"edge_application_id"` DigitalCertificateID string `json:"digital_certificate_id"` IsActive string `json:"is_active"` Path string @@ -63,7 +63,7 @@ func NewCmd(f *cmdutil.Factory) *cobra.Command { return msg.ErrorConvertApplicationID } - fields.EdgeApplicationID = int(num) + fields.EdgeApplicationID = num } if !cmd.Flags().Changed("name") { @@ -89,7 +89,7 @@ func NewCmd(f *cmdutil.Factory) *cobra.Command { request.SetName(fields.Name) request.SetCnames(fields.Cnames) - request.SetEdgeApplicationId(int64(fields.EdgeApplicationID)) + request.SetEdgeApplicationId(fields.EdgeApplicationID) if cmd.Flags().Changed("digital-certificate-id") { request.SetDigitalCertificateId(fields.DigitalCertificateID) @@ -122,7 +122,7 @@ func NewCmd(f *cmdutil.Factory) *cobra.Command { flags.StringSliceVar(&fields.Cnames, "cnames", []string{}, msg.FlagCnames) flags.StringVar(&fields.CnameAccessOnly, "cname-access-only", "false", msg.FlagCnameAccessOnly) flags.StringVar(&fields.DigitalCertificateID, "digital-certificate-id", "", msg.FlagDigitalCertificateID) - flags.IntVar(&fields.EdgeApplicationID, "application-id", 0, msg.FlagEdgeApplicationId) + flags.Int64Var(&fields.EdgeApplicationID, "application-id", 0, msg.FlagEdgeApplicationId) flags.StringVar(&fields.IsActive, "active", "true", msg.FlagIsActive) flags.StringVar(&fields.Path, "file", "", msg.FlagFile) flags.BoolP("help", "h", false, msg.HelpFlag) From 44c3fdc349b02b4c3fa25790c8203de97cdbc499 Mon Sep 17 00:00:00 2001 From: Magnun A V F Date: Tue, 28 Oct 2025 09:30:08 -0300 Subject: [PATCH 17/18] chore: update vulcan version --- pkg/vulcan/vulcan.go | 4 ++-- pkg/vulcan/vulcan_test.go | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/vulcan/vulcan.go b/pkg/vulcan/vulcan.go index 3caa3ee82..f67533099 100644 --- a/pkg/vulcan/vulcan.go +++ b/pkg/vulcan/vulcan.go @@ -15,8 +15,8 @@ import ( var ( currentMajor = 6 installEdgeFunctions = "npx --yes %s edge-functions%s %s" - firstTimeExecuting = "@6.1.2" - versionVulcan = "@6.1.2" + firstTimeExecuting = "@6.2.0" + versionVulcan = "@6.2.0" ) type VulcanPkg struct { diff --git a/pkg/vulcan/vulcan_test.go b/pkg/vulcan/vulcan_test.go index fa8e37c45..b22656e24 100644 --- a/pkg/vulcan/vulcan_test.go +++ b/pkg/vulcan/vulcan_test.go @@ -105,7 +105,7 @@ func TestCheckVulcanMajor(t *testing.T) { { name: "new major version without last version", args: args{ - currentVersion: "6.1.2", + currentVersion: "6.2.0", }, lastVulcanVer: "", expectedVersion: firstTimeExecuting, @@ -116,8 +116,8 @@ func TestCheckVulcanMajor(t *testing.T) { args: args{ currentVersion: "7.0.2", }, - lastVulcanVer: "6.1.2", - expectedVersion: "@6.1.2", + lastVulcanVer: "6.2.0", + expectedVersion: "@6.2.0", wantErr: false, }, { @@ -125,8 +125,8 @@ func TestCheckVulcanMajor(t *testing.T) { args: args{ currentVersion: "7.0.2", }, - lastVulcanVer: "6.1.2", - expectedVersion: "@6.1.2", + lastVulcanVer: "6.2.0", + expectedVersion: "@6.2.0", wantErr: false, }, { From 080f407decdc5f637686c8288e1e42709d91aecd Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Wed, 29 Oct 2025 11:19:30 -0300 Subject: [PATCH 18/18] refactor: update workflows --- .github/workflows/cla.yml | 2 +- .github/workflows/deploy_prod.yml | 8 ++++---- .github/workflows/deploy_stage.yml | 2 +- .github/workflows/e2e_test.yml | 2 +- .github/workflows/generate_docs.yml | 2 +- .github/workflows/package-audit.yaml | 2 +- .github/workflows/scc-checker.yml | 2 +- .github/workflows/test_and_build.yml | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/cla.yml b/.github/workflows/cla.yml index ab120990b..2a87bef91 100644 --- a/.github/workflows/cla.yml +++ b/.github/workflows/cla.yml @@ -8,7 +8,7 @@ on: jobs: CLAssistant: permissions: - contents: read + contents: write pull-requests: write runs-on: ubuntu-latest container: diff --git a/.github/workflows/deploy_prod.yml b/.github/workflows/deploy_prod.yml index 9babf450b..a96038cab 100644 --- a/.github/workflows/deploy_prod.yml +++ b/.github/workflows/deploy_prod.yml @@ -9,7 +9,7 @@ on: jobs: build: permissions: - contents: read + contents: write pull-requests: write runs-on: ubuntu-latest container: @@ -100,7 +100,7 @@ jobs: bump_formula: permissions: - contents: read + contents: write pull-requests: write runs-on: ubuntu-latest needs: build @@ -113,7 +113,7 @@ jobs: publish-choco-package: permissions: - contents: read + contents: write pull-requests: write runs-on: windows-latest needs: build @@ -180,7 +180,7 @@ jobs: Publish-to-WinGet: permissions: - contents: read + contents: write pull-requests: write runs-on: windows-latest needs: [build, bump_formula] diff --git a/.github/workflows/deploy_stage.yml b/.github/workflows/deploy_stage.yml index f5cb6fe3b..0d4a84c39 100644 --- a/.github/workflows/deploy_stage.yml +++ b/.github/workflows/deploy_stage.yml @@ -9,7 +9,7 @@ on: jobs: build: permissions: - contents: read + contents: write pull-requests: write runs-on: ubuntu-latest container: diff --git a/.github/workflows/e2e_test.yml b/.github/workflows/e2e_test.yml index 0a43077d9..624f8120a 100644 --- a/.github/workflows/e2e_test.yml +++ b/.github/workflows/e2e_test.yml @@ -9,7 +9,7 @@ on: jobs: build: permissions: - contents: read + contents: write pull-requests: write runs-on: ubuntu-latest if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip-e2e') }} diff --git a/.github/workflows/generate_docs.yml b/.github/workflows/generate_docs.yml index b2ef0b4f0..72ce9ff4c 100644 --- a/.github/workflows/generate_docs.yml +++ b/.github/workflows/generate_docs.yml @@ -9,7 +9,7 @@ on: jobs: build: permissions: - contents: read + contents: write pull-requests: write runs-on: ubuntu-latest container: diff --git a/.github/workflows/package-audit.yaml b/.github/workflows/package-audit.yaml index 5521732f7..507d88f93 100644 --- a/.github/workflows/package-audit.yaml +++ b/.github/workflows/package-audit.yaml @@ -7,7 +7,7 @@ on: jobs: PackageAuditing: permissions: - contents: read + contents: write pull-requests: write name: Package Auditor (GoVulnCheck) runs-on: ubuntu-latest diff --git a/.github/workflows/scc-checker.yml b/.github/workflows/scc-checker.yml index 229c6598a..7e39773ad 100644 --- a/.github/workflows/scc-checker.yml +++ b/.github/workflows/scc-checker.yml @@ -7,7 +7,7 @@ on: jobs: scc-check: permissions: - contents: read + contents: write pull-requests: write runs-on: ubuntu-latest steps: diff --git a/.github/workflows/test_and_build.yml b/.github/workflows/test_and_build.yml index 2229d6948..9c303b602 100644 --- a/.github/workflows/test_and_build.yml +++ b/.github/workflows/test_and_build.yml @@ -9,7 +9,7 @@ on: jobs: build: permissions: - contents: read + contents: write pull-requests: write if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip-unit-tests') }} runs-on: ubuntu-latest