Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeschuurmans committed Sep 23, 2024
1 parent ffefe67 commit 2e38df5
Show file tree
Hide file tree
Showing 39 changed files with 1,838 additions and 1,346 deletions.
2 changes: 2 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#### What does this PR do

77 changes: 77 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ main ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
schedule:
- cron: '34 3 * * 0'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'go' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
61 changes: 61 additions & 0 deletions .github/workflows/push-pr-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: lint, test and build image
on: [pull_request, push]

jobs:
lint-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
args: --config .golangci.yml --timeout 2m
version: v1.61.0

- name: Test
run: go test ./...

build:
runs-on: ubuntu-latest
needs: [lint-test]
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: build binary
run: make build-linux

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build bioscfg Docker image - no push
id: dockerbuild-bioscfg
uses: docker/build-push-action@v5
with:
context: .
push: false
file: Dockerfile

- name: Scan image - bioscfg
id: scan-bioscfg-image
uses: anchore/scan-action@v3
with:
image: ghcr.io/metal-toolbox/bioscfg:latest
acs-report-enable: true
fail-build: false

- name: Inspect action SARIF report
run: cat ${{ steps.scan.outputs.sarif }}
if: always()
47 changes: 47 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: release

on:
push:
tags:
- 'v*.*.*'

jobs:
goreleaser:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
packages: write
steps:
-
name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
-
name: install cosign
uses: sigstore/cosign-installer@main
-
uses: anchore/sbom-action/[email protected]
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COSIGN_EXPERIMENTAL: 1
GOVERSION: "1.20"
17 changes: 6 additions & 11 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: 1.57.2
golangci-lint-version: 1.61.0

linters-settings:
govet:
enable:
- fieldalignment
auto-fix: true
check-shadowing: true
settings:
printf:
funcs:
Expand Down Expand Up @@ -47,6 +46,7 @@ linters-settings:
- wrapperFunc
gofumpt:
extra-rules: true
shadow: true

linters:
enable:
Expand All @@ -65,7 +65,7 @@ linters:
# additional linters
- bodyclose
- gocritic
- goerr113
- err113
- goimports
- revive
- misspell
Expand All @@ -76,14 +76,11 @@ linters:
enable-all: false
disable-all: true

run:
# build-tags:
skip-dirs:
issues:
exclude-dirs:
- internal/fixtures
skip-files:
exclude-files:
- "(.*/)*.*_test.go"

issues:
exclude-rules:
- linters:
- gosec
Expand Down Expand Up @@ -119,5 +116,3 @@ issues:
# EXC0010 gosec: False positive is triggered by 'src, err := ioutil.ReadFile(filename)'
- Potential file inclusion via variable
exclude-use-default: false


46 changes: 24 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ GIT_SUMMARY := $(shell git describe --tags --dirty --always)
VERSION := $(shell git describe --tags 2> /dev/null)
BUILD_DATE := $(shell date +%s)
GIT_COMMIT_FULL := $(shell git rev-parse HEAD)
GO_VERSION := $(shell expr `go version |cut -d ' ' -f3 |cut -d. -f2` \>= 16)
GO_VERSION := $(shell expr `go version |cut -d ' ' -f3 |cut -d. -f2` \>= 23)
DOCKER_IMAGE := "ghcr.io/metal-toolbox/bioscfg"
REPO := "https://github.com/metal-toolbox/bioscfg.git"

.DEFAULT_GOAL := help

## lint
lint: gen-mock
golangci-lint run --config .golangci.yml
golangci-lint run --config .golangci.yml --fix

## Go test
test: lint
Expand All @@ -30,38 +30,36 @@ gen-mock:
## build-osx
build-osx:
ifeq ($(GO_VERSION), 0)
$(error build requies go version 1.22.1 or higher)
$(error build requies go version 1.23 or higher)
endif
go build -o bioscfg \
-ldflags \
go build -o bioscfg \
-ldflags \
"-X $(LDFLAG_LOCATION).GitCommit=$(GIT_COMMIT) \
-X $(LDFLAG_LOCATION).GitBranch=$(GIT_BRANCH) \
-X $(LDFLAG_LOCATION).GitSummary=$(GIT_SUMMARY) \
-X $(LDFLAG_LOCATION).AppVersion=$(VERSION) \
-X $(LDFLAG_LOCATION).BuildDate=$(BUILD_DATE)"

-X $(LDFLAG_LOCATION).GitBranch=$(GIT_BRANCH) \
-X $(LDFLAG_LOCATION).GitSummary=$(GIT_SUMMARY) \
-X $(LDFLAG_LOCATION).AppVersion=$(VERSION) \
-X $(LDFLAG_LOCATION).BuildDate=$(BUILD_DATE)"

## Build linux bin
build-linux:
ifeq ($(GO_VERSION), 0)
$(error build requies go version 1.22.1 or higher)
$(error build requies go version 1.23 or higher)
endif
GOOS=linux GOARCH=amd64 go build -o bioscfg \
-ldflags \
-ldflags \
"-X $(LDFLAG_LOCATION).GitCommit=$(GIT_COMMIT) \
-X $(LDFLAG_LOCATION).GitBranch=$(GIT_BRANCH) \
-X $(LDFLAG_LOCATION).GitSummary=$(GIT_SUMMARY) \
-X $(LDFLAG_LOCATION).AppVersion=$(VERSION) \
-X $(LDFLAG_LOCATION).BuildDate=$(BUILD_DATE)"

-X $(LDFLAG_LOCATION).GitBranch=$(GIT_BRANCH) \
-X $(LDFLAG_LOCATION).GitSummary=$(GIT_SUMMARY) \
-X $(LDFLAG_LOCATION).AppVersion=$(VERSION) \
-X $(LDFLAG_LOCATION).BuildDate=$(BUILD_DATE)"

## build docker image and tag as ghcr.io/metal-toolbox/bioscfg:latest
build-image: build-linux
@echo ">>>> NOTE: You may want to execute 'make build-image-nocache' depending on the Docker stages changed"
docker build --rm=true -f Dockerfile -t ${DOCKER_IMAGE}:latest . \
--label org.label-schema.schema-version=1.0 \
--label org.label-schema.vcs-ref=$(GIT_COMMIT_FULL) \
--label org.label-schema.vcs-url=$(REPO)
docker build --rm=true -f Dockerfile -t ${DOCKER_IMAGE}:latest . \
--label org.label-schema.schema-version=1.0 \
--label org.label-schema.vcs-ref=$(GIT_COMMIT_FULL) \
--label org.label-schema.vcs-url=$(REPO)

## tag and push devel docker image to local registry
push-image-devel: build-image
Expand All @@ -73,14 +71,18 @@ push-image-devel: build-image
push-image:
docker push ${DOCKER_IMAGE}:latest

## Clean all caches
clean-all:
golangci-lint cache clean
go clean -modcache -testcache -cache -fuzzcache

# https://gist.github.com/prwhite/8168133
# COLORS
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)


TARGET_MAX_CHAR_NUM=20
## Show help
help:
Expand Down
27 changes: 27 additions & 0 deletions cmd/bioscfg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cmd

import (
"fmt"
"os"

"github.com/metal-toolbox/bioscfg/internal/controllers"
"github.com/metal-toolbox/bioscfg/internal/controllers/kind"
"github.com/spf13/cobra"
)

// bioscfgCmd represents the bioscfg command
var bioscfgCmd = &cobra.Command{
Use: "bioscfg",
Short: "Run the BiosCfg Controller",
Run: func(cmd *cobra.Command, _ []string) {
err := controllers.Run(cmd.Context(), kind.BiosCfg)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}

func init() {
rootCmd.AddCommand(bioscfgCmd)
}
Loading

0 comments on commit 2e38df5

Please sign in to comment.