diff --git a/.github/workflows/rewrite-ci.yml b/.github/workflows/rewrite-ci.yml new file mode 100644 index 00000000..321058fb --- /dev/null +++ b/.github/workflows/rewrite-ci.yml @@ -0,0 +1,55 @@ +name: CI (golang) + +on: + workflow_call: + pull_request: + paths: + - "rewrite/**" + - ".github/workflows/rewrite-ci.yml" + +permissions: + contents: read + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + - uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0 + with: + go-version-file: "rewrite/go.mod" + - run: make + working-directory: rewrite + + golangci: + name: Golangci-lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + - uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0 + with: + go-version-file: "rewrite/go.mod" + - name: golangci-lint + uses: golangci/golangci-lint-action@e7fa5ac41e1cf5b7d48e45e42232ce7ada589601 # v9.1.0 + with: + version: v2.5.0 + working-directory: rewrite + + fmtcheck: + name: Go fmt check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + - uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0 + with: + go-version-file: "rewrite/go.mod" + - name: format check + working-directory: rewrite + run: | + make fmt + if [ -n "$(git status --porcelain)" ]; then + echo "Code is not formatted. Please run 'make fmt' and commit the changes." + git --no-pager diff + exit 1 + fi diff --git a/rewrite/internal/cli/list.go b/rewrite/internal/cli/list.go index aacbc9db..77fe8974 100644 --- a/rewrite/internal/cli/list.go +++ b/rewrite/internal/cli/list.go @@ -2,12 +2,14 @@ package cli import ( "context" + "errors" "fmt" "os" + "github.com/urfave/cli/v3" + "github.com/89luca89/distrobox/pkg/commands" "github.com/89luca89/distrobox/pkg/containermanager" - "github.com/urfave/cli/v3" ) const ( @@ -33,7 +35,7 @@ func newListCommand() *cli.Command { func listAction(ctx context.Context, cmd *cli.Command) error { containerManager, ok := ctx.Value(containerManagerKey).(containermanager.ContainerManager) if !ok { - return fmt.Errorf("container manager not found in context") + return errors.New("container manager not found in context") } listCmd := commands.NewListCommand(containerManager) @@ -49,11 +51,13 @@ func listAction(ctx context.Context, cmd *cli.Command) error { } func printResult(result *commands.ListResult, noColor bool) { + //nolint:forbidigo // Using fmt.Printf is acceptable here for CLI output fmt.Printf("%-12s | %-20s | %-18s | %-30s\n", "ID", "NAME", "STATUS", "IMAGE") for _, c := range result.Containers { if noColor { + //nolint:forbidigo // Using fmt.Printf is acceptable here for CLI output fmt.Printf("%-12s | %-20s | %-18s | %-30s\n", c.ID, c.Name, c.Status, c.Image) } else { @@ -61,6 +65,7 @@ func printResult(result *commands.ListResult, noColor bool) { if c.IsRunning() { color = colorGreen } + //nolint:forbidigo // Using fmt.Printf is acceptable here for CLI output fmt.Printf("%s%-12s | %-20s | %-18s | %-30s%s\n", color, c.ID, c.Name, c.Status, c.Image, colorReset) } diff --git a/rewrite/pkg/containermanager/providers/docker.go b/rewrite/pkg/containermanager/providers/docker.go index 9ee9a553..a1b4c09a 100644 --- a/rewrite/pkg/containermanager/providers/docker.go +++ b/rewrite/pkg/containermanager/providers/docker.go @@ -75,9 +75,11 @@ func parseContainerList(output string) ([]containermanager.Container, error) { return nil, fmt.Errorf("failed to parse container JSON: %w", err) } + const containerIDMaxLength = 12 + id := dc.ID - if len(id) > 12 { - id = id[:12] + if len(id) > containerIDMaxLength { + id = id[:containerIDMaxLength] } containers = append(containers, containermanager.Container{