-
-
Notifications
You must be signed in to change notification settings - Fork 111
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
14 changed files
with
302 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
# The workflow name **must** be "autofix.ci" for Autofix CI to function correctly. | ||
# Any deviation from this name will cause Autofix CI to fail, as it relies on this | ||
# specific identifier for execution. This is a strict requirement of Autofix CI. | ||
name: autofix.ci | ||
on: pull_request | ||
permissions: {} | ||
jobs: | ||
autofix: | ||
runs-on: ubuntu-24.04 | ||
permissions: {} | ||
timeout-minutes: 15 | ||
steps: | ||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
with: | ||
persist-credentials: false | ||
- uses: aquaproj/aqua-installer@e2d0136abcf70b7a2f6f505720640750557c4b33 # v3.1.1 | ||
with: | ||
aqua_version: v2.43.0 | ||
|
||
- name: Update aqua-checksums.json | ||
run: aqua upc -prune | ||
|
||
# go mod tidy | ||
- uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0 | ||
with: | ||
go-version-file: go.mod | ||
- run: go mod tidy | ||
|
||
# gofumpt | ||
- name: Get changed Go files | ||
id: changed-files | ||
uses: tj-actions/changed-files@d6e91a2266cdb9d62096cebf1e8546899c6aa18f # v45.0.6 | ||
with: | ||
use_rest_api: "true" | ||
files: | | ||
**/*.go | ||
- if: steps.changed-files.outputs.all_changed_files_count != '0' | ||
env: | ||
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} | ||
run: | | ||
# shellcheck disable=SC2086 | ||
gofumpt -l -w $ALL_CHANGED_FILES | ||
- uses: autofix-ci/action@2891949f3779a1cafafae1523058501de3d4e944 # v1.3.1 |
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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"checksums": [ | ||
{ | ||
"id": "github_release/github.com/mvdan/gofumpt/v0.7.0/gofumpt_v0.7.0_darwin_amd64", | ||
"checksum": "B7D05E092DA45C5EC96344AB635B1D6547C3E27C840BA39BC76989934EFD7CE3", | ||
"algorithm": "sha256" | ||
}, | ||
{ | ||
"id": "github_release/github.com/mvdan/gofumpt/v0.7.0/gofumpt_v0.7.0_darwin_arm64", | ||
"checksum": "08F23114760A090B090706D92B8C52B9875B9EB352D76C77AA354D6AA20B045A", | ||
"algorithm": "sha256" | ||
}, | ||
{ | ||
"id": "github_release/github.com/mvdan/gofumpt/v0.7.0/gofumpt_v0.7.0_linux_amd64", | ||
"checksum": "6FF459C1DCAE3B0B00844C1A5A4A5B0F547237D8A4F3624AAEA8D424AEEF24C6", | ||
"algorithm": "sha256" | ||
}, | ||
{ | ||
"id": "github_release/github.com/mvdan/gofumpt/v0.7.0/gofumpt_v0.7.0_linux_arm64", | ||
"checksum": "00C18C88EF50437629626BA20D677F4648684CB280952814CDD887677D42CBD3", | ||
"algorithm": "sha256" | ||
}, | ||
{ | ||
"id": "github_release/github.com/mvdan/gofumpt/v0.7.0/gofumpt_v0.7.0_windows_amd64.exe", | ||
"checksum": "65F5B9EA7723AA936FA6880E184624747E9E6481802B62D4CB5B774EF2350CEC", | ||
"algorithm": "sha256" | ||
}, | ||
{ | ||
"id": "registries/github_content/github.com/aquaproj/aqua-registry/v4.302.1/registry.yaml", | ||
"checksum": "908B44E94A3583AA2D6F0B17F53E49D01ACD57E4ECDFEDB29EB082D335D9445478426E591AB57D37BAA02A2EF9581A71A3AA66C825CC787323D65A1D89B53072", | ||
"algorithm": "sha512" | ||
} | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
# yaml-language-server: $schema=https://raw.githubusercontent.com/aquaproj/aqua/main/json-schema/aqua-yaml.json | ||
# aqua - Declarative CLI Version Manager | ||
# https://aquaproj.github.io/ | ||
checksum: | ||
enabled: true | ||
require_checksum: true | ||
registries: | ||
- type: standard | ||
ref: v4.302.1 # renovate: depName=aquaproj/aqua-registry | ||
packages: | ||
- import: imports/*.yaml |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
packages: | ||
- name: mvdan/[email protected] |
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
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 |
---|---|---|
@@ -0,0 +1,175 @@ | ||
package tests | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func TestCLITerraformClean(t *testing.T) { | ||
// Capture the starting working directory | ||
startingDir, err := os.Getwd() | ||
if err != nil { | ||
t.Fatalf("Failed to get the current working directory: %v", err) | ||
} | ||
|
||
// Initialize PathManager and update PATH | ||
pathManager := NewPathManager() | ||
pathManager.Prepend("../build", "..") | ||
err = pathManager.Apply() | ||
if err != nil { | ||
t.Fatalf("Failed to apply updated PATH: %v", err) | ||
} | ||
fmt.Printf("Updated PATH: %s\n", pathManager.GetPath()) | ||
defer func() { | ||
// Change back to the original working directory after the test | ||
if err := os.Chdir(startingDir); err != nil { | ||
t.Fatalf("Failed to change back to the starting directory: %v", err) | ||
} | ||
}() | ||
|
||
// Define the work directory and change to it | ||
workDir := "../examples/quick-start-simple" | ||
if err := os.Chdir(workDir); err != nil { | ||
t.Fatalf("Failed to change directory to %q: %v", workDir, err) | ||
} | ||
|
||
// Find the binary path for "atmos" | ||
binaryPath, err := exec.LookPath("atmos") | ||
if err != nil { | ||
t.Fatalf("Binary not found: %s. Current PATH: %s", "atmos", pathManager.GetPath()) | ||
} | ||
|
||
// Force clean everything | ||
runTerraformCleanCommand(t, binaryPath, "--force") | ||
// Clean everything | ||
runTerraformCleanCommand(t, binaryPath) | ||
// Clean specific component | ||
runTerraformCleanCommand(t, binaryPath, "station") | ||
// Clean component with stack | ||
runTerraformCleanCommand(t, binaryPath, "station", "-s", "dev") | ||
|
||
// Run terraform apply for prod environment | ||
runTerraformApply(t, binaryPath, "prod") | ||
verifyStateFilesExist(t, []string{"./components/terraform/weather/terraform.tfstate.d/prod-station"}) | ||
runCLITerraformCleanComponent(t, binaryPath, "prod") | ||
verifyStateFilesDeleted(t, []string{"./components/terraform/weather/terraform.tfstate.d/prod-station"}) | ||
|
||
// Run terraform apply for dev environment | ||
runTerraformApply(t, binaryPath, "dev") | ||
|
||
// Verify if state files exist before cleaning | ||
stateFiles := []string{ | ||
"./components/terraform/weather/.terraform", | ||
"./components/terraform/weather/terraform.tfstate.d", | ||
"./components/terraform/weather/.terraform.lock.hcl", | ||
} | ||
verifyStateFilesExist(t, stateFiles) | ||
|
||
// Run terraform clean | ||
runTerraformClean(t, binaryPath) | ||
|
||
// Verify if state files have been deleted after clean | ||
verifyStateFilesDeleted(t, stateFiles) | ||
|
||
} | ||
|
||
// runTerraformApply runs the terraform apply command for a given environment. | ||
func runTerraformApply(t *testing.T, binaryPath, environment string) { | ||
cmd := exec.Command(binaryPath, "terraform", "apply", "station", "-s", environment) | ||
envVars := os.Environ() | ||
envVars = append(envVars, "ATMOS_COMPONENTS_TERRAFORM_APPLY_AUTO_APPROVE=true") | ||
cmd.Env = envVars | ||
|
||
var stdout, stderr bytes.Buffer | ||
cmd.Stdout = &stdout | ||
cmd.Stderr = &stderr | ||
err := cmd.Run() | ||
t.Log(stdout.String()) | ||
if err != nil { | ||
t.Fatalf("Failed to run terraform apply station -s %s: %v", environment, stderr.String()) | ||
} | ||
} | ||
|
||
// verifyStateFilesExist checks if the state files exist before cleaning. | ||
func verifyStateFilesExist(t *testing.T, stateFiles []string) { | ||
for _, file := range stateFiles { | ||
fileAbs, err := filepath.Abs(file) | ||
if err != nil { | ||
t.Fatalf("Failed to resolve absolute path for %q: %v", file, err) | ||
} | ||
if _, err := os.Stat(fileAbs); errors.Is(err, os.ErrNotExist) { | ||
t.Errorf("Expected file to exist before cleaning: %q", fileAbs) | ||
} | ||
} | ||
} | ||
|
||
// runTerraformClean runs the terraform clean command. | ||
func runTerraformClean(t *testing.T, binaryPath string) { | ||
cmd := exec.Command(binaryPath, "terraform", "clean", "--force") | ||
var stdout, stderr bytes.Buffer | ||
cmd.Stdout = &stdout | ||
cmd.Stderr = &stderr | ||
err := cmd.Run() | ||
t.Logf("Clean command output:\n%s", stdout.String()) | ||
if err != nil { | ||
t.Fatalf("Failed to run terraform clean: %v", stderr.String()) | ||
} | ||
} | ||
|
||
// verifyStateFilesDeleted checks if the state files have been deleted after cleaning. | ||
func verifyStateFilesDeleted(t *testing.T, stateFiles []string) { | ||
for _, file := range stateFiles { | ||
fileAbs, err := filepath.Abs(file) | ||
if err != nil { | ||
t.Fatalf("Failed to resolve absolute path for %q: %v", file, err) | ||
} | ||
_, err = os.Stat(fileAbs) | ||
if err == nil { | ||
t.Errorf("Expected Terraform state file to be deleted: %q", fileAbs) | ||
} else if !errors.Is(err, os.ErrNotExist) { | ||
t.Errorf("Unexpected error checking file %q: %v", fileAbs, err) | ||
} | ||
} | ||
} | ||
|
||
func runCLITerraformCleanComponent(t *testing.T, binaryPath, environment string) { | ||
cmd := exec.Command(binaryPath, "terraform", "clean", "station", "-s", environment, "--force") | ||
var stdout, stderr bytes.Buffer | ||
cmd.Stdout = &stdout | ||
cmd.Stderr = &stderr | ||
err := cmd.Run() | ||
t.Logf("Clean command output:\n%s", stdout.String()) | ||
if err != nil { | ||
t.Fatalf("Failed to run terraform clean: %v", stderr.String()) | ||
} | ||
} | ||
func runCLITerraformClean(t *testing.T, binaryPath string) { | ||
cmd := exec.Command(binaryPath, "terraform", "clean") | ||
var stdout, stderr bytes.Buffer | ||
cmd.Stdout = &stdout | ||
cmd.Stderr = &stderr | ||
err := cmd.Run() | ||
t.Logf("Clean command output:\n%s", stdout.String()) | ||
if err != nil { | ||
t.Fatalf("Failed to run terraform clean: %v", stderr.String()) | ||
} | ||
|
||
} | ||
|
||
func runTerraformCleanCommand(t *testing.T, binaryPath string, args ...string) { | ||
cmdArgs := append([]string{"terraform", "clean"}, args...) | ||
cmd := exec.Command(binaryPath, cmdArgs...) | ||
var stdout, stderr bytes.Buffer | ||
cmd.Stdout = &stdout | ||
cmd.Stderr = &stderr | ||
err := cmd.Run() | ||
t.Logf("Clean command output:\n%s", stdout.String()) | ||
if err != nil { | ||
t.Fatalf("Failed to run terraform clean: %v", stderr.String()) | ||
} | ||
} |
Oops, something went wrong.