diff --git a/.github/workflows/ci-docker.yaml b/.github/workflows/ci-docker.yaml index 521d0d8..b213a81 100644 --- a/.github/workflows/ci-docker.yaml +++ b/.github/workflows/ci-docker.yaml @@ -6,7 +6,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v7 - name: Set Swap Space uses: pierotofy/set-swap-space@master @@ -14,27 +14,27 @@ jobs: swap-size-gb: 12 - name: Run Golangci lint - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@v9 with: version: latest - args: --print-resources-usage + args: --verbose - name: Docker meta id: docker_meta - uses: docker/metadata-action@v3 + uses: docker/metadata-action@v6 with: images: ${{ github.repository }},quay.io/${{ github.repository }} labels: | io.artifacthub.package.readme-url=https://raw.githubusercontent.com/${{ github.repository }}/${{ github.event.repository.default_branch }}/README.md - name: Set up QEMU - uses: docker/setup-qemu-action@v1 + uses: docker/setup-qemu-action@v4 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v4 - name: Build - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v7 with: context: . file: ./Dockerfile diff --git a/.github/workflows/release-assets.yaml b/.github/workflows/release-assets.yaml index 9d38757..7b694f1 100644 --- a/.github/workflows/release-assets.yaml +++ b/.github/workflows/release-assets.yaml @@ -8,16 +8,16 @@ jobs: release: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v7 - name: Set Swap Space uses: pierotofy/set-swap-space@master with: swap-size-gb: 12 - - uses: actions/setup-go@v2 + - uses: actions/setup-go@v6 with: - go-version: '1.19' + go-version: '1.26.5' check-latest: true - name: Build @@ -25,7 +25,7 @@ jobs: make release-assets - name: Upload assets to release - uses: svenstaro/upload-release-action@v2 + uses: svenstaro/upload-release-action@2.11.5 with: repo_token: ${{ secrets.GITHUB_TOKEN }} file: ./release-assets/* diff --git a/.github/workflows/release-docker.yaml b/.github/workflows/release-docker.yaml index ef6fa31..49b48d3 100644 --- a/.github/workflows/release-docker.yaml +++ b/.github/workflows/release-docker.yaml @@ -11,7 +11,7 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v7 - name: Set Swap Space uses: pierotofy/set-swap-space@master @@ -19,10 +19,10 @@ jobs: swap-size-gb: 12 - name: Run Golangci lint - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@v9 with: version: latest - args: --print-resources-usage + args: --verbose build: needs: lint @@ -35,7 +35,7 @@ jobs: include: [] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v7 - name: Set Swap Space uses: pierotofy/set-swap-space@master @@ -44,7 +44,7 @@ jobs: - name: Docker meta id: docker_meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@v6 with: images: ${{ github.repository }},quay.io/${{ github.repository }} labels: | @@ -54,26 +54,26 @@ jobs: suffix=${{ matrix.suffix }} - name: Set up QEMU - uses: docker/setup-qemu-action@v1 + uses: docker/setup-qemu-action@v4 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v4 - name: Login to DockerHub - uses: docker/login-action@v1 + uses: docker/login-action@v4 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Login to Quay - uses: docker/login-action@v1 + uses: docker/login-action@v4 with: registry: quay.io username: ${{ secrets.QUAY_USERNAME }} password: ${{ secrets.QUAY_TOKEN }} - name: Build and push - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v7 with: context: . file: ./${{ matrix.Dockerfile }} diff --git a/.github/workflows/scheduled-docker.yaml b/.github/workflows/scheduled-docker.yaml index 9737bde..fbece48 100644 --- a/.github/workflows/scheduled-docker.yaml +++ b/.github/workflows/scheduled-docker.yaml @@ -8,7 +8,7 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v7 - name: Set Swap Space uses: pierotofy/set-swap-space@master @@ -16,10 +16,10 @@ jobs: swap-size-gb: 12 - name: Run Golangci lint - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@v9 with: version: latest - args: --print-resources-usage + args: --verbose build: needs: lint @@ -32,7 +32,7 @@ jobs: include: [] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v7 - name: Set Swap Space uses: pierotofy/set-swap-space@master @@ -41,7 +41,7 @@ jobs: - name: Docker meta id: docker_meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@v6 with: images: ${{ github.repository }},quay.io/${{ github.repository }} labels: | @@ -51,26 +51,26 @@ jobs: suffix=${{ matrix.suffix }} - name: Set up QEMU - uses: docker/setup-qemu-action@v1 + uses: docker/setup-qemu-action@v4 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v4 - name: Login to DockerHub - uses: docker/login-action@v1 + uses: docker/login-action@v4 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Login to Quay - uses: docker/login-action@v1 + uses: docker/login-action@v4 with: registry: quay.io username: ${{ secrets.QUAY_USERNAME }} password: ${{ secrets.QUAY_TOKEN }} - name: Build and push - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v7 with: context: . file: ./${{ matrix.Dockerfile }} diff --git a/.golangci.yaml b/.golangci.yaml index 4496150..dd572d7 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,26 +1,36 @@ -run: - timeout: 120m - +version: "2" linters: enable: - asciicheck - bidichk - bodyclose + - copyloopvar - errorlint - - exportloopref + - gosec + settings: + gosec: + confidence: low + config: + global: + audit: true + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: - gofmt - goimports - - gosec - -linters-settings: - gosec: - excludes: [] - confidence: low - config: - global: - audit: true - -issues: {} - -output: - sort-results: true + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/Dockerfile b/Dockerfile index 20988e2..5fce992 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ ############################################# # Build ############################################# -FROM --platform=$BUILDPLATFORM golang:1.19-alpine as build +FROM --platform=$BUILDPLATFORM golang:1.26.5-alpine AS build RUN apk upgrade --no-cache --force RUN apk add --update build-base make git @@ -21,7 +21,7 @@ RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} make build ############################################# # Test ############################################# -FROM gcr.io/distroless/static as test +FROM gcr.io/distroless/static AS test USER 0:0 WORKDIR /app COPY --from=build /go/src/github.com/webdevops/go-replace/go-replace . diff --git a/Makefile b/Makefile index 1c394ea..35b3d95 100644 --- a/Makefile +++ b/Makefile @@ -59,7 +59,7 @@ cram-test: build .PHONY: lint lint: $(GOLANGCI_LINT_BIN) - time $(GOLANGCI_LINT_BIN) run --verbose --print-resources-usage + time $(GOLANGCI_LINT_BIN) run --verbose --verbose $(GOLANGCI_LINT_BIN): curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(FIRST_GOPATH)/bin diff --git a/filehandling.go b/filehandling.go index 7cac123..515de00 100644 --- a/filehandling.go +++ b/filehandling.go @@ -15,7 +15,7 @@ import ( // buffered reader. func Readln(r *bufio.Reader) (string, error) { var ( - isPrefix bool = true + isPrefix = true err error = nil line, ln []byte ) diff --git a/go.mod b/go.mod index afdc6b4..50ea7fc 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/webdevops/go-replace -go 1.19 +go 1.26.5 require ( github.com/Masterminds/sprig v2.22.0+incompatible @@ -17,6 +17,6 @@ require ( github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/stretchr/testify v1.7.1 // indirect - golang.org/x/crypto v0.0.0-20221005025214-4161e89ecf1b // indirect - golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec // indirect + golang.org/x/crypto v0.54.0 // indirect + golang.org/x/sys v0.47.0 // indirect ) diff --git a/go.sum b/go.sum index 566810e..64c0fdb 100644 --- a/go.sum +++ b/go.sum @@ -25,11 +25,11 @@ github.com/remeh/sizedwaitgroup v1.0.0/go.mod h1:3j2R4OIe/SeS6YDhICBy22RWjJC5eNC github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -golang.org/x/crypto v0.0.0-20221005025214-4161e89ecf1b h1:huxqepDufQpLLIRXiVkTvnxrzJlpwmIWAObmcCcUFr0= -golang.org/x/crypto v0.0.0-20221005025214-4161e89ecf1b/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.54.0 h1:YLIA59K4fiNzHzjnZt2tUJQjQtUWfWbeHBqKtk3eScw= +golang.org/x/crypto v0.54.0/go.mod h1:KWL8ny2AZdGR2cWmzeHrp2azQPGogOv+HeQaVEXC2dk= golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec h1:BkDtF2Ih9xZ7le9ndzTA7KJow28VbQW3odyk/8drmuI= -golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs= +golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA= diff --git a/log.go b/log.go index 46c13f8..c2b6cff 100644 --- a/log.go +++ b/log.go @@ -20,7 +20,7 @@ func logError(err error) { // Log error object as message func logFatalErrorAndExit(err error, exitCode int) { - cmdline := fmt.Sprintf("%s %s", argparser.Command.Name, strings.Join(os.Args[1:], " ")) + cmdline := fmt.Sprintf("%s %s", argparser.Name, strings.Join(os.Args[1:], " ")) fmt.Fprintf(os.Stderr, "Error: %s\n", err) fmt.Fprintf(os.Stderr, "Command: %s\n", cmdline) diff --git a/main.go b/main.go index f72d61f..32f6956 100644 --- a/main.go +++ b/main.go @@ -77,8 +77,8 @@ var pathFilterDirectories = []string{"autom4te.cache", "blib", "_build", ".bzr", // Apply changesets to file func applyChangesetsToFile(fileitem fileitem, changesets []changeset) (string, bool, error) { var ( - output string = "" - status bool = true + output = "" + status = true ) // try open file @@ -278,7 +278,7 @@ func handleSpecialCliOptions(args []string) { // --output if opts.Output != "" && len(args) > 1 { - logFatalErrorAndExit(errors.New("Only one file is allowed when using --output"), 1) + logFatalErrorAndExit(errors.New("only one file is allowed when using --output"), 1) } if opts.LineinfileBefore != "" || opts.LineinfileAfter != "" { @@ -287,7 +287,7 @@ func handleSpecialCliOptions(args []string) { } if opts.LineinfileBefore != "" && opts.LineinfileAfter != "" { - logFatalErrorAndExit(errors.New("Only --lineinfile-after or --lineinfile-before is allowed in --mode=lineinfile"), 1) + logFatalErrorAndExit(errors.New("only --lineinfile-after or --lineinfile-before is allowed in --mode=lineinfile"), 1) } } } @@ -330,7 +330,7 @@ func actionProcessFiles(changesets []changeset, fileitems []fileitem) int { os.Exit(0) } else { // no files found, print error and exit with error code - logFatalErrorAndExit(errors.New("No files specified"), 1) + logFatalErrorAndExit(errors.New("no files specified"), 1) } } @@ -381,7 +381,7 @@ func actionProcessFiles(changesets []changeset, fileitems []fileitem) int { } if errorCount >= 1 { - fmt.Fprintf(os.Stderr, "[ERROR] %s failed with %d error(s)\n", argparser.Command.Name, errorCount) + fmt.Fprintf(os.Stderr, "[ERROR] %s failed with %d error(s)\n", argparser.Name, errorCount) return 1 } @@ -394,14 +394,14 @@ func buildChangesets() []changeset { if !opts.ModeIsTemplate { if len(opts.Search) == 0 || len(opts.Replace) == 0 { // error: unequal numbers of search and replace options - logFatalErrorAndExit(errors.New("Missing either --search or --replace for this mode"), 1) + logFatalErrorAndExit(errors.New("missing either --search or --replace for this mode"), 1) } } // check if search and replace options have equal lenght (equal number of options) if len(opts.Search) != len(opts.Replace) { // error: unequal numbers of search and replace options - logFatalErrorAndExit(errors.New("Unequal numbers of search or replace options"), 1) + logFatalErrorAndExit(errors.New("unequal numbers of search or replace options"), 1) } // build changesets