chore: add ci for rewrite project (#9)

* chore: disable mdlint (#6)

* resolve lint issues

Some issues where detected by the CI once run:
* use of `fmt.Printf` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
* File is not properly formatted (goimports)
* Magic number: 12, in <condition> detected (mnd)
* error-format: fmt.Errorf can be replaced with errors.New (perfsprint)

---------

Co-authored-by: Alessio Biancalana <alessio@dottorblaster.it>
This commit is contained in:
Emanuele De Cupis
2026-06-11 18:24:39 +02:00
committed by Alessio Biancalana
co-authored by Alessio Biancalana
parent 5bff18e3d1
commit 1f883d2fbe
3 changed files with 66 additions and 4 deletions
+55
View File
@@ -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
+7 -2
View File
@@ -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)
}
@@ -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{