Skip to content

Commit

Permalink
Run go-makefile-maker
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 committed Oct 10, 2024
1 parent 2ab7220 commit 38d2851
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 32 deletions.
6 changes: 6 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
if type -P lorri &>/dev/null; then
eval "$(lorri direnv)"
else
use nix
fi
23 changes: 11 additions & 12 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base",
"config:recommended",
"default:pinDigestsDisabled",
"mergeConfidence:all-badges",
"docker:disable"
Expand All @@ -11,7 +12,7 @@
],
"commitMessageAction": "Renovate: Update",
"constraints": {
"go": "1.22"
"go": "1.23"
},
"dependencyDashboardOSVVulnerabilitySummary": "all",
"osvVulnerabilityAlerts": true,
Expand All @@ -24,27 +25,25 @@
"matchPackageNames": [
"golang"
],
"allowedVersions": "1.22.x"
"allowedVersions": "1.23.x"
},
{
"matchPackagePatterns": [
"^github\\.com\\/sapcc\\/.*"
"matchPackageNames": [
"/^github\\.com\\/sapcc\\/.*/"
],
"automerge": true,
"groupName": "github.com/sapcc"
},
{
"excludePackagePatterns": [
"^github\\.com\\/sapcc\\/.*"
],
"matchPackagePatterns": [
".*"
"matchPackageNames": [
"!/^github\\.com\\/sapcc\\/.*/",
"/.*/"
],
"groupName": "External dependencies"
},
{
"matchPackagePrefixes": [
"k8s.io/"
"matchPackageNames": [
"/^k8s.io\\//"
],
"allowedVersions": "0.28.x"
}
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ name: Checks
pull_request:
branches:
- '*'
workflow_dispatch: {}
permissions:
checks: write
contents: read
Expand All @@ -25,7 +26,11 @@ jobs:
uses: actions/setup-go@v5
with:
check-latest: true
go-version: 1.22.5
go-version: 1.23.2
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
- name: Dependency Licenses Review
run: make check-dependency-licenses
- name: Run govulncheck
Expand Down
15 changes: 6 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ name: CI
- '*'
paths-ignore:
- '**.md'
workflow_dispatch: {}
permissions:
contents: read
jobs:
buildAndLint:
name: Build & Lint
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Check out code
Expand All @@ -28,17 +29,13 @@ jobs:
uses: actions/setup-go@v5
with:
check-latest: true
go-version: 1.22.5
go-version: 1.23.2
- name: Build all binaries
run: make build-all
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
test:
name: Test
needs:
- buildAndLint
- build
runs-on: ubuntu-latest
steps:
- name: Check out code
Expand All @@ -47,6 +44,6 @@ jobs:
uses: actions/setup-go@v5
with:
check-latest: true
go-version: 1.22.5
go-version: 1.23.2
- name: Run tests and generate coverage report
run: make build/cover.out
3 changes: 2 additions & 1 deletion .github/workflows/codeql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ name: CodeQL
- master
schedule:
- cron: '00 07 * * 1'
workflow_dispatch: {}
permissions:
actions: read
contents: read
Expand All @@ -28,7 +29,7 @@ jobs:
uses: actions/setup-go@v5
with:
check-latest: true
go-version: 1.22.5
go-version: 1.23.2
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ linters-settings:
- ^http\.Handle(?:Func)?$
# Forbid usage of old and archived square/go-jose
- pkg: ^gopkg\.in/square/go-jose\.v2$
msg: "gopk.in/square/go-jose is arcived and has CVEs. Replace it with gopkg.in/go-jose/go-jose.v2"
msg: "gopk.in/square/go-jose is archived and has CVEs. Replace it with gopkg.in/go-jose/go-jose.v2"
- pkg: ^github.com/coreos/go-oidc$
msg: "github.com/coreos/go-oidc depends on gopkg.in/square/go-jose which has CVEs. Replace it with github.com/coreos/go-oidc/v3"

Expand Down
16 changes: 9 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ install-ginkgo: FORCE
GO_BUILDFLAGS =
GO_LDFLAGS =
GO_TESTENV =
GO_BUILDENV =
TESTBIN=$(shell pwd)/testbin

build-all: build/runtime-extension-maintenance-controller

build/runtime-extension-maintenance-controller: FORCE generate
go build $(GO_BUILDFLAGS) -ldflags '-s -w $(GO_LDFLAGS)' -o build/runtime-extension-maintenance-controller .
@env $(GO_BUILDENV) go build $(GO_BUILDFLAGS) -ldflags '-s -w $(GO_LDFLAGS)' -o build/runtime-extension-maintenance-controller .

DESTDIR =
ifeq ($(shell uname -s),Darwin)
Expand Down Expand Up @@ -69,16 +70,16 @@ check: FORCE static-check build/cover.html build-all

generate: install-controller-gen
@printf "\e[1;36m>> controller-gen\e[0m\n"
@controller-gen crd rbac:roleName=runtime-extension-maintenance-controller paths="./..." output:crd:artifacts:config=crd
@controller-gen object paths=./...
@controller-gen crd rbac:roleName=runtime-extension-maintenance-controller webhook paths="./..." output:crd:artifacts:config=crd
@controller-gen object paths="./..."

run-golangci-lint: FORCE prepare-static-check
@printf "\e[1;36m>> golangci-lint\e[0m\n"
@golangci-lint run

build/cover.out: FORCE install-ginkgo generate install-setup-envtest | build
@printf "\e[1;36m>> Running tests\e[0m\n"
KUBEBUILDER_ASSETS="$(shell setup-envtest use 1.30 --bin-dir $(TESTBIN) -p path)" ginkgo run --randomize-all -output-dir=build $(GO_BUILDFLAGS) -ldflags '-s -w $(GO_LDFLAGS)' -covermode=count -coverpkg=$(subst $(space),$(comma),$(GO_COVERPKGS)) $(GO_TESTPKGS)
KUBEBUILDER_ASSETS=$$(setup-envtest use 1.31 --bin-dir $(TESTBIN) -p path) ginkgo run --randomize-all -output-dir=build $(GO_BUILDFLAGS) -ldflags '-s -w $(GO_LDFLAGS)' -covermode=count -coverpkg=$(subst $(space),$(comma),$(GO_COVERPKGS)) $(GO_TESTPKGS)
@mv build/coverprofile.out build/cover.out

build/cover.html: build/cover.out
Expand All @@ -96,11 +97,11 @@ tidy-deps: FORCE

license-headers: FORCE prepare-static-check
@printf "\e[1;36m>> addlicense\e[0m\n"
@addlicense -c "SAP SE" -- $(patsubst $(shell awk '$$1 == "module" {print $$2}' go.mod)%,.%/*.go,$(shell go list ./...))
@addlicense -c "SAP SE" -- $(patsubst $(shell awk '$$1 == "module" {print $$2}' go.mod)%,.%/*.go,$(shell go list ./...))

check-license-headers: FORCE prepare-static-check
@printf "\e[1;36m>> addlicense --check\e[0m\n"
@addlicense --check -- $(patsubst $(shell awk '$$1 == "module" {print $$2}' go.mod)%,.%/*.go,$(shell go list ./...))
@addlicense --check -- $(patsubst $(shell awk '$$1 == "module" {print $$2}' go.mod)%,.%/*.go,$(shell go list ./...))

check-dependency-licenses: FORCE prepare-static-check
@printf "\e[1;36m>> go-licence-detector\e[0m\n"
Expand All @@ -111,6 +112,7 @@ clean: FORCE

vars: FORCE
@printf "DESTDIR=$(DESTDIR)\n"
@printf "GO_BUILDENV=$(GO_BUILDENV)\n"
@printf "GO_BUILDFLAGS=$(GO_BUILDFLAGS)\n"
@printf "GO_COVERPKGS=$(GO_COVERPKGS)\n"
@printf "GO_LDFLAGS=$(GO_LDFLAGS)\n"
Expand Down Expand Up @@ -147,7 +149,7 @@ help: FORCE
@printf "\n"
@printf "\e[1mDevelopment\e[0m\n"
@printf " \e[36mtidy-deps\e[0m Run go mod tidy and go mod verify.\n"
@printf " \e[36mlicense-headers\e[0m Add license headers to all non-vendored .go files.\n"
@printf " \e[36mlicense-headers\e[0m Add license headers to all non-vendored source code files.\n"
@printf " \e[36mcheck-license-headers\e[0m Check license headers in all non-vendored .go files.\n"
@printf " \e[36mcheck-dependency-licenses\e[0m Check all dependency licenses using go-licence-detector.\n"
@printf " \e[36mclean\e[0m Run git clean.\n"
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/sapcc/runtime-extension-maintenance-controller

go 1.22.0
go 1.23

require (
github.com/evanphx/json-patch v5.9.0+incompatible
Expand Down
42 changes: 42 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{ pkgs ? import <nixpkgs> { } }:

with pkgs;

let
# TODO: drop after https://github.com/NixOS/nixpkgs/pull/347304 got merged
go-licence-detector = buildGoModule rec {
pname = "go-licence-detector";
version = "0.7.0";

src = fetchFromGitHub {
owner = "elastic";
repo = "go-licence-detector";
rev = "v${version}";
hash = "sha256-43MyzEF7BZ7pcgzDvXx9SjXGHaLozmWkGWUO/yf6K98=";
};

vendorHash = "sha256-7vIP5pGFH6CbW/cJp+DiRg2jFcLFEBl8dQzUw1ogTTA=";

meta = with lib; {
description = "Detect licences in Go projects and generate documentation";
homepage = "https://github.com/elastic/go-licence-detector";
license = licenses.asl20;
maintainers = with maintainers; [ SuperSandro2000 ];
};
};
in

mkShell {
nativeBuildInputs = [
ginkgo
go-licence-detector
go_1_23
golangci-lint
gotools # goimports
kubernetes-controller-tools # controller-gen
setup-envtest

# keep this line if you use bash
bashInteractive
];
}

0 comments on commit 38d2851

Please sign in to comment.