Skip to content

Commit

Permalink
chore: rekres
Browse files Browse the repository at this point in the history
Rekresify and use `t.TempDir()` in tests.

Signed-off-by: Noel Georgi <[email protected]>
  • Loading branch information
frezbo committed Sep 19, 2022
1 parent a121f38 commit 1130050
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 82 deletions.
4 changes: 2 additions & 2 deletions .conform.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2022-03-23T17:40:43Z by kres latest.
# Generated on 2022-09-19T13:49:50Z by kres 9ea8a33.

---
policies:
Expand Down Expand Up @@ -29,10 +29,10 @@ policies:
skipPaths:
- .git/
- testdata/
- internal/policy/license/
includeSuffixes:
- .go
excludeSuffixes:
- .pb.go
- .pb.gw.go
allowPrecedingComments: true
header: "// This Source Code Form is subject to the terms of the Mozilla Public\u000A// License, v. 2.0. If a copy of the MPL was not distributed with this\u000A// file, You can obtain one at http://mozilla.org/MPL/2.0/.\u000A"
17 changes: 12 additions & 5 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2021-09-01T21:21:54Z by kres 5ca7963.
# Generated on 2022-09-19T13:49:50Z by kres 9ea8a33.

kind: pipeline
type: kubernetes
Expand Down Expand Up @@ -209,7 +209,7 @@ steps:
path: /root/.ssh
when:
branch:
- master
- main
event:
exclude:
- pull_request
Expand Down Expand Up @@ -303,6 +303,12 @@ volumes:
temp:
medium: memory

trigger:
branch:
exclude:
- renovate/*
- dependabot/*

---
kind: pipeline
type: kubernetes
Expand Down Expand Up @@ -330,9 +336,10 @@ steps:
- failure

trigger:
status:
- success
- failure
branch:
exclude:
- renovate/*
- dependabot/*

depends_on:
- default
Expand Down
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2022-06-03T19:43:01Z by kres 65530e7.
# Generated on 2022-09-19T13:49:50Z by kres 9ea8a33.

# options for analysis running
run:
Expand Down Expand Up @@ -137,6 +137,8 @@ linters:
- gomoddirectives
- ireturn
- nestif
- nonamedreturns
- nosnakecase
- paralleltest
- tagliatelle
- thelper
Expand Down
15 changes: 8 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2022-06-03T19:43:01Z by kres 65530e7.
# Generated on 2022-09-19T13:49:50Z by kres 9ea8a33.

ARG TOOLCHAIN

# cleaned up specs and compiled versions
FROM scratch AS generate

FROM ghcr.io/siderolabs/ca-certificates:v1.0.0 AS image-ca-certificates
FROM ghcr.io/siderolabs/ca-certificates:v1.2.0 AS image-ca-certificates

FROM ghcr.io/siderolabs/fhs:v1.0.0 AS image-fhs
FROM ghcr.io/siderolabs/fhs:v1.2.0 AS image-fhs

# runs markdownlint
FROM node:18.2.0-alpine AS lint-markdown
FROM docker.io/node:18.9.0-alpine3.16 AS lint-markdown
WORKDIR /src
RUN npm i -g markdownlint-cli@0.31.1
RUN npm i -g markdownlint-cli@0.32.2
RUN npm i [email protected]
COPY .markdownlint.json .
COPY ./CHANGELOG.md ./CHANGELOG.md
Expand All @@ -28,12 +28,13 @@ FROM ${TOOLCHAIN} AS toolchain
RUN apk --update --no-cache add bash curl build-base protoc protobuf-dev git

# build tools
FROM toolchain AS tools
FROM --platform=${BUILDPLATFORM} toolchain AS tools
ENV GO111MODULE on
ENV CGO_ENABLED 0
ENV GOPATH /go
ARG GOLANGCILINT_VERSION
RUN curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/${GOLANGCILINT_VERSION}/install.sh | bash -s -- -b /bin ${GOLANGCILINT_VERSION}
RUN go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCILINT_VERSION} \
&& mv /go/bin/golangci-lint /bin/golangci-lint
ARG GOFUMPT_VERSION
RUN go install mvdan.cc/gofumpt@${GOFUMPT_VERSION} \
&& mv /go/bin/gofumpt /bin/gofumpt
Expand Down
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2022-06-03T19:43:01Z by kres 65530e7.
# Generated on 2022-09-19T13:49:50Z by kres 9ea8a33.

# common variables

Expand All @@ -11,13 +11,13 @@ ARTIFACTS := _out
REGISTRY ?= ghcr.io
USERNAME ?= siderolabs
REGISTRY_AND_USERNAME ?= $(REGISTRY)/$(USERNAME)
GOLANGCILINT_VERSION ?= v1.46.2
GOLANGCILINT_VERSION ?= v1.49.0
GOFUMPT_VERSION ?= v0.3.1
GO_VERSION ?= 1.18
GOIMPORTS_VERSION ?= v0.1.10
PROTOBUF_GO_VERSION ?= 1.28.0
GO_VERSION ?= 1.19
GOIMPORTS_VERSION ?= v0.1.12
PROTOBUF_GO_VERSION ?= 1.28.1
GRPC_GO_VERSION ?= 1.2.0
GRPC_GATEWAY_VERSION ?= 2.10.0
GRPC_GATEWAY_VERSION ?= 2.11.3
VTPROTOBUF_VERSION ?= 0.3.0
DEEPCOPY_VERSION ?= v0.5.5
TESTPKGS ?= ./...
Expand All @@ -39,6 +39,7 @@ COMMON_ARGS += --build-arg=ARTIFACTS=$(ARTIFACTS)
COMMON_ARGS += --build-arg=SHA=$(SHA)
COMMON_ARGS += --build-arg=TAG=$(TAG)
COMMON_ARGS += --build-arg=USERNAME=$(USERNAME)
COMMON_ARGS += --build-arg=REGISTRY=$(REGISTRY)
COMMON_ARGS += --build-arg=TOOLCHAIN=$(TOOLCHAIN)
COMMON_ARGS += --build-arg=GOLANGCILINT_VERSION=$(GOLANGCILINT_VERSION)
COMMON_ARGS += --build-arg=GOFUMPT_VERSION=$(GOFUMPT_VERSION)
Expand All @@ -49,7 +50,7 @@ COMMON_ARGS += --build-arg=GRPC_GATEWAY_VERSION=$(GRPC_GATEWAY_VERSION)
COMMON_ARGS += --build-arg=VTPROTOBUF_VERSION=$(VTPROTOBUF_VERSION)
COMMON_ARGS += --build-arg=DEEPCOPY_VERSION=$(DEEPCOPY_VERSION)
COMMON_ARGS += --build-arg=TESTPKGS=$(TESTPKGS)
TOOLCHAIN ?= docker.io/golang:1.18-alpine
TOOLCHAIN ?= docker.io/golang:1.19-alpine

# help menu

Expand Down
18 changes: 9 additions & 9 deletions cmd/conform/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -36,43 +36,43 @@ var serveCmd = &cobra.Command{
}

http.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
payload, err := ioutil.ReadAll(r.Body)
payload, err := io.ReadAll(r.Body)
if err != nil {
log.Printf("failed to read payload: %+v\n", err)

return
}

go func() {
dir, err := ioutil.TempDir("/tmp", "conform")
dir, err := os.CreateTemp("/tmp", "conform")
if err != nil {
log.Printf("failed to create temporary directory: %+v\n", err)

return
}

defer os.RemoveAll(dir) //nolint:errcheck
defer os.RemoveAll(dir.Name()) //nolint:errcheck

if err = os.MkdirAll(filepath.Join(dir, "github"), 0o700); err != nil {
if err = os.MkdirAll(filepath.Join(dir.Name(), "github"), 0o700); err != nil {
log.Printf("failed to create github directory: %+v\n", err)

return
}
if err = os.MkdirAll(filepath.Join(dir, "repo"), 0o700); err != nil {
if err = os.MkdirAll(filepath.Join(dir.Name(), "repo"), 0o700); err != nil {
log.Printf("failed to create repo directory: %+v\n", err)

return
}

event := filepath.Join(dir, "github", "event.json")
event := filepath.Join(dir.Name(), "github", "event.json")
pullRequestEvent := &github.PullRequestEvent{}
if err = json.Unmarshal(payload, pullRequestEvent); err != nil {
log.Printf("failed to parse pull_request event: %+v\n", err)

return
}

cloneRepo := filepath.Join(dir, "repo")
cloneRepo := filepath.Join(dir.Name(), "repo")
cloneURL := pullRequestEvent.GetPullRequest().GetBase().GetRepo().GetCloneURL()

log.Printf("Cloning %s", cloneURL)
Expand Down Expand Up @@ -127,7 +127,7 @@ var serveCmd = &cobra.Command{

log.Printf("writing %s to disk", event)

if err = ioutil.WriteFile(event, payload, 0o600); err != nil {
if err = os.WriteFile(event, payload, 0o600); err != nil {
log.Printf("failed to write event to disk: %+v\n", err)

return
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/siderolabs/conform

go 1.17
go 1.19

require (
github.com/denormal/go-gitignore v0.0.0-20180930084346-ae8ad1d07817
Expand Down
3 changes: 1 addition & 2 deletions internal/enforcer/enforcer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package enforcer

import (
"fmt"
"io/ioutil"
"log"
"os"
"text/tabwriter"
Expand Down Expand Up @@ -62,7 +61,7 @@ func New(r string) (*Conform, error) {
c.reporter = &reporter.Noop{}
}

configBytes, err := ioutil.ReadFile(".conform.yaml")
configBytes, err := os.ReadFile(".conform.yaml")
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/policy/commit/check_gpg_identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package commit
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"sync"

Expand Down Expand Up @@ -133,7 +133,7 @@ func getKey(ctx context.Context, login string) (string, error) {

defer resp.Body.Close() //nolint:errcheck

buf, err := ioutil.ReadAll(resp.Body)
buf, err := io.ReadAll(resp.Body)

return string(buf), err
}
4 changes: 2 additions & 2 deletions internal/policy/commit/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package commit

import (
"io/ioutil"
"os"
"regexp"
"strings"

Expand Down Expand Up @@ -107,7 +107,7 @@ func (c *Commit) Compliance(options *policy.Options) (*policy.Report, error) {
if options.CommitMsgFile != nil {
var contents []byte

if contents, err = ioutil.ReadFile(*options.CommitMsgFile); err != nil {
if contents, err = os.ReadFile(*options.CommitMsgFile); err != nil {
return report, errors.Errorf("failed to read commit message file: %v", err)
}

Expand Down
Loading

0 comments on commit 1130050

Please sign in to comment.