Skip to content

Commit

Permalink
Merge pull request #1 from edcdavid/ci
Browse files Browse the repository at this point in the history
New organization and CI
  • Loading branch information
edcdavid authored Aug 19, 2024
2 parents ce51737 + 22864e7 commit 3c99bf0
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .checkmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[maxbodylength]
disabled = true
82 changes: 82 additions & 0 deletions .github/workflows/pre-main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Test Incoming Changes

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

permissions:
contents: read

env:
TERM: xterm-color
CM_BIN: /usr/local/bin/checkmake
CM_URL_LINUX: https://github.com/mrtazz/checkmake/releases/download/0.2.2/checkmake-0.2.2.linux.amd64 # yamllint disable-line

concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
cancel-in-progress: true

jobs:
lint-and-test:
name: Run Linters, Vet and unit tests
runs-on: ubuntu-22.04
env:
SHELL: /bin/bash

steps:
- name: Set up Go 1.22
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: 1.22.5

- name: Disable default go problem matcher
run: echo "::remove-matcher owner=go::"

- name: Check out code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
ref: ${{ github.sha }}

- name: Extract dependent Pull Requests
uses: depends-on/depends-on-action@9e8a61fce18b15281e831f1bba0e14c71d1e1f46 # main
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Install checkmake
run: |
curl --location --output $CM_BIN --silent $CM_URL_LINUX
chmod +x $CM_BIN
- name: Install Shfmt
uses: mfinelli/setup-shfmt@031e887e39d899d773a7e9b6dd6472c2c23ff50d # v3.0.1

- name: Golangci-lint
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0
with:
version: v1.59
args: --timeout 10m0s

- name: Checkmake
run: checkmake --config=.checkmake Makefile

- name: Shfmt
run: shfmt -d scripts

- name: ShellCheck
uses: ludeeus/action-shellcheck@00b27aa7cb85167568cb48a3838b75f4265f2bca # master

- name: Go vet
run: make vet

- name: Run Build
run: make build
env:
SHELL: /bin/bash

- name: Run Tests
run: make test
env:
SHELL: /bin/bash
52 changes: 31 additions & 21 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ linters-settings:
dupl:
threshold: 100
funlen:
lines: 50
statements: 30
gci:
local-prefixes: github.com/golangci/golangci-lint
lines: 60
statements: 45
goconst:
min-len: 4
min-occurrences: 2
Expand All @@ -19,16 +17,13 @@ linters-settings:
disabled-checks:
- whyNoLint
gocyclo:
min-complexity: 15
goimports:
local-prefixes: github.com/golangci/golangci-lint
gomnd:
min-complexity: 20
mnd:
settings:
mnd:
# don't include the "operation" and "assign"
# do not include the "operation" and "assign"
checks: argument,case,condition,return
govet:
check-shadowing: true
settings:
printf:
funcs:
Expand All @@ -43,16 +38,17 @@ linters-settings:
nolintlint:
allow-leading-space: false # disallow leading spaces. A space means the //nolint comment shows in `godoc` output.
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-explanation: false # do not require an explanation for nolint directives
require-specific: true # require nolint directives to be specific about which linter is being skipped
exhaustive:
default-signifies-exhaustive: true
linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- bodyclose
- dogsled
- dupl
- errcheck
- exhaustive
- exportloopref
Expand All @@ -62,18 +58,15 @@ linters:
- gocyclo
- gofmt
- goimports
- gomnd
- mnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- noctx
- nolintlint
- revive
- rowserrcheck
- staticcheck
- stylecheck
Expand All @@ -82,31 +75,48 @@ linters:
- unparam
- unused
- whitespace
# don't enable:
# do not enable:
# - asciicheck
# - depguard
# - dupl
# - gochecknoglobals
# - gochecknoinits
# - gocognit
# - godot
# - godox
# - goerr113
# - maligned
# - nakedret
# - nestif
# - noctx
# - prealloc
# - revive
# - exportloopref
# - structcheck
# - testpackage
# - wsl
issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
# Ignore magic numbers and inline strings in tests.
# Ignore magic numbers, inline strings and function length in tests.
- path: _test\.go
linters:
- gomnd
- mnd
- goconst
# Ignore line length for string assignments (don't try and wrap regex definitions)
- funlen
- path: config/config.go
linters:
- mnd
- path: _scaling.go
linters:
- gocritic
- path: hugepages.go
linters:
- mnd
- path: scheduling.go
linters:
- mnd
# Ignore line length for string assignments (do not try and wrap regex definitions)
- linters:
- lll
source: "^(.*= (\".*\"|`.*`))$"
Expand All @@ -120,6 +130,6 @@ issues:
# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: 1.54.x # use the fixed version to not introduce new linters unexpectedly
golangci-lint-version: 1.59.x # use the fixed version to not introduce new linters unexpectedly
prepare:
- echo "here I can run custom commands, but no preparation needed for this repo"
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.PHONY: all clean test build
GOLANGCI_VERSION=v1.54.2

lint:
Expand All @@ -7,3 +8,5 @@ build:
# Install golangci-lint
install-lint:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ${GO_PATH}/bin ${GOLANGCI_VERSION}
test:
scripts/test.sh
Binary file added basic
Binary file not shown.
8 changes: 4 additions & 4 deletions basic.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
lib "github.com/redhat-best-practices-for-k8s/graphsolver-lib"
l2lib "github.com/redhat-best-practices-for-k8s/l2discovery-exports"
lib "github.com/redhat-cne/graphsolver-lib"
l2lib "github.com/redhat-cne/l2discovery-exports"
)

type testGraph struct {
Expand Down Expand Up @@ -40,8 +40,8 @@ func main() {
tagGrandmaster = 1
)

if1 := l2lib.PtpIf{IfClusterIndex: l2lib.IfClusterIndex{InterfaceName: "ens3f0", NodeName: "node1"}, Iface: l2lib.Iface{IfMac: l2lib.Mac{Data: "52:55:00:81:c2:62"}, IfPci: l2lib.PCIAddress{Device: "00:03", Function: "0"}}}
if2 := l2lib.PtpIf{IfClusterIndex: l2lib.IfClusterIndex{InterfaceName: "ens3f0", NodeName: "node2"}, Iface: l2lib.Iface{IfMac: l2lib.Mac{Data: "52:55:00:81:c2:63"}, IfPci: l2lib.PCIAddress{Device: "00:03", Function: "0"}}}
if1 := l2lib.PtpIf{IfClusterIndex: l2lib.IfClusterIndex{InterfaceName: "ens3f0", NodeName: "node1"}, Iface: l2lib.Iface{IfName: "ens3f0", IfMac: l2lib.Mac{Data: "52:55:00:81:c2:62"}, IfPci: l2lib.PCIAddress{Device: "00:03", Function: "0"}}}
if2 := l2lib.PtpIf{IfClusterIndex: l2lib.IfClusterIndex{InterfaceName: "ens3f0", NodeName: "node2"}, Iface: l2lib.Iface{IfName: "ens3f0", IfMac: l2lib.Mac{Data: "52:55:00:81:c2:63"}, IfPci: l2lib.PCIAddress{Device: "00:03", Function: "0"}}}
lans := [][]int{{0, 1}}
aGraph := testGraph{ifList: []*l2lib.PtpIf{&if1, &if2}, lans: &lans, ptpInterfaces: nil}

Expand Down
10 changes: 4 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
module github.com/redhat-best-practices-for-k8s/graphsolver-minimal

go 1.22.5

toolchain go1.22.6
go 1.22

require (
github.com/redhat-best-practices-for-k8s/graphsolver-lib v0.0.4
github.com/redhat-best-practices-for-k8s/l2discovery-exports v0.0.4
github.com/redhat-cne/graphsolver-lib v0.0.5
github.com/redhat-cne/l2discovery-exports v0.0.4
)

require (
github.com/redhat-best-practices-for-k8s/graphsolver-exports v0.0.2 // indirect
github.com/redhat-cne/graphsolver-exports v0.0.2 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/redhat-best-practices-for-k8s/graphsolver-exports v0.0.2 h1:SJnXD40jEFBCWT8ZjmJOFJdIzMwWPbrIUCAQu1oXfYQ=
github.com/redhat-best-practices-for-k8s/graphsolver-exports v0.0.2/go.mod h1:Vl268nAHQKEnIw7GIYehp3Lx4qYP8+rOlwGsWxD/aO4=
github.com/redhat-best-practices-for-k8s/graphsolver-lib v0.0.4 h1:541I5wcounFu3P/5YmWjrpNOH50KwalGKHBer41Tjj8=
github.com/redhat-best-practices-for-k8s/graphsolver-lib v0.0.4/go.mod h1:IK4i8ZBV16s/EVD+EpOrubdbSGqcryRV7eah0gcl5sg=
github.com/redhat-best-practices-for-k8s/l2discovery-exports v0.0.4 h1:66qE0Vj/8vWvt8yaVq1yJK5+OOELGZdlCwzHkXRxFr4=
github.com/redhat-best-practices-for-k8s/l2discovery-exports v0.0.4/go.mod h1:NO9mpaj5neVKarRGcsL5SHVFb+uYUoCC8uVbuT419xs=
github.com/redhat-cne/graphsolver-exports v0.0.2 h1:xpswAtA6J4BVIrZfytRUBzG9icQw71lIUa6NMHQ1FN4=
github.com/redhat-cne/graphsolver-exports v0.0.2/go.mod h1:ZXxUEsVGE+ND/ODQ28nIcSJfTTYAB5bjs2HrTjPiIQI=
github.com/redhat-cne/graphsolver-lib v0.0.5 h1:M/C07yZQFQCA9AStdwvlNrjWYcQuObVGiPT06ZriE1Y=
github.com/redhat-cne/graphsolver-lib v0.0.5/go.mod h1:hOlp1RlLrwb9ZqmX4lcknGobuKFQxIByx+ugTtAwfj4=
github.com/redhat-cne/l2discovery-exports v0.0.4 h1:oYZlk0lXEnLTO8nxnL1G54L+KdQ1WyA5zZFJln9/8uA=
github.com/redhat-cne/l2discovery-exports v0.0.4/go.mod h1:hYvCYXSfngU/j+auFobgvKcwiu5DurO2BnUBoSmg/NA=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
4 changes: 4 additions & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
make build
./basic 2>&1| sed 's/time="[^"]*" //' > test/actual.txt
diff test/actual.txt test/expected.txt
7 changes: 7 additions & 0 deletions test/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
level=info msg="Solutions for OC problem"
level=info msg="p0= node1 : ens3f0"
level=info msg="p1= node2 : ens3f0"
level=info msg=---
level=info msg="p0= node2 : ens3f0"
level=info msg="p1= node1 : ens3f0"
level=info msg=---

0 comments on commit 3c99bf0

Please sign in to comment.