Skip to content

Commit 056b274

Browse files
committed
workflow and minor fixes
1 parent 8509d16 commit 056b274

File tree

14 files changed

+889
-476
lines changed

14 files changed

+889
-476
lines changed

.github/dependabot.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55

66
version: 2
77
updates:
8-
- package-ecosystem: "github-actions" # See documentation for possible values
9-
directory: "/" # Location of package manifests
10-
schedule:
11-
interval: "weekly"
8+
- package-ecosystem: gomod
9+
directory: "/"
10+
schedule:
11+
interval: daily
12+
open-pull-requests-limit: 10
13+
- package-ecosystem: "github-actions"
14+
directory: "/"
15+
schedule:
16+
interval: daily

.github/workflows/codeql.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ "main" ]
17+
paths-ignore:
18+
- 'docs/**'
19+
- '**.md'
20+
- '.github/**'
21+
pull_request:
22+
# The branches below must be a subset of the branches above
23+
branches: [ "main" ]
24+
paths-ignore:
25+
- 'docs/**'
26+
- '**.md'
27+
- '.github/**'
28+
schedule:
29+
- cron: '16 12 * * 1'
30+
31+
jobs:
32+
analyze:
33+
name: Analyze
34+
runs-on: ubuntu-latest
35+
permissions:
36+
actions: read
37+
contents: read
38+
security-events: write
39+
40+
strategy:
41+
fail-fast: false
42+
matrix:
43+
language: [ 'go' ]
44+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
45+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
46+
47+
steps:
48+
- name: Checkout repository
49+
uses: actions/checkout@v4
50+
51+
- name: Set up Go
52+
uses: actions/setup-go@v5
53+
if: ${{ matrix.language == 'go' }}
54+
with:
55+
cache: false
56+
go-version-file: 'go.mod'
57+
58+
59+
# Initializes the CodeQL tools for scanning.
60+
- name: Initialize CodeQL
61+
uses: github/codeql-action/init@v3
62+
with:
63+
languages: ${{ matrix.language }}
64+
# If you wish to specify custom queries, you can do so here or in a config file.
65+
# By default, queries listed here will override any specified in a config file.
66+
# Prefix the list here with "+" to use these queries and those in the config file.
67+
68+
# 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
69+
# queries: security-extended,security-and-quality
70+
71+
72+
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
73+
# If this step fails, then you should remove it and run the build manually (see below)
74+
- name: Autobuild
75+
uses: github/codeql-action/autobuild@v3
76+
77+
# ℹ️ Command-line programs to run using the OS shell.
78+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
79+
80+
# If the Autobuild fails above, remove it and uncomment the following three lines.
81+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
82+
83+
# - run: |
84+
# echo "Run, Build Application using script"
85+
# ./location_of_script_within_repo/buildscript.sh
86+
87+
- name: Perform CodeQL Analysis
88+
uses: github/codeql-action/analyze@v3
89+
with:
90+
category: "/language:${{matrix.language}}"

.github/workflows/main.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Main
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.ref }}
5+
cancel-in-progress: true
6+
7+
on:
8+
push:
9+
paths-ignore:
10+
- 'docs/**'
11+
- '**.md'
12+
- '.github/**'
13+
pull_request:
14+
paths-ignore:
15+
- 'docs/**'
16+
- '**.md'
17+
- '.github/**'
18+
19+
permissions:
20+
contents: read
21+
22+
jobs:
23+
lint:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Setup Go
27+
uses: actions/setup-go@v5
28+
with:
29+
check-latest: true
30+
go-version: '1.23'
31+
id: go
32+
33+
- name: Checkout repository
34+
uses: actions/checkout@v4
35+
36+
- name: golangci-lint
37+
uses: golangci/golangci-lint-action@v6
38+
with:
39+
version: latest
40+
args: --verbose
41+
42+
build:
43+
runs-on: ubuntu-latest
44+
steps:
45+
- name: Set up Go
46+
uses: actions/setup-go@v5
47+
with:
48+
check-latest: true
49+
go-version: 1.23
50+
id: go
51+
52+
- name: Check out code into the Go module directory
53+
uses: actions/checkout@v4
54+
55+
- name: Cache go module
56+
uses: actions/cache@v4
57+
with:
58+
path: |
59+
~/go/pkg/mod
60+
~/.cache/go-build
61+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
62+
restore-keys: |
63+
${{ runner.os }}-go-
64+
65+
- name: Check and build
66+
run: |
67+
make check
68+
git diff --exit-code
69+
make build
70+
71+
- name: Test
72+
run: |
73+
make test-full
74+
make test-race
75+
make test-pure
76+
make benchmark-pure
77+
78+
- name: Upload coverage to Codecov
79+
uses: codecov/codecov-action@v4
80+
with:
81+
token: ${{ secrets.CODECOV_TOKEN }}
82+
file: ./coverage.txt

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 iglov
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
PKG_PREFIX := github.com/iglov/netbox-agent
2+
NAME := netbox-agent
3+
BINDIR := bin
4+
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
5+
COMMIT_TAG := $(shell git rev-parse --short=12 HEAD)
6+
DATEINFO_TAG := $(shell date -u +'%Y%m%d%H%M%S')
7+
8+
PKG_TAG ?= $(shell git tag -l --points-at HEAD)
9+
ifeq ($(PKG_TAG),)
10+
PKG_TAG := $(BRANCH)
11+
endif
12+
13+
LDFLAGS = -X 'main.Version=$(PKG_TAG)-$(DATEINFO_TAG)-$(COMMIT_TAG)'
14+
GOBUILD = go build -trimpath -tags "$(BUILDTAGS)" -ldflags "$(LDFLAGS)"
15+
16+
PLATFORM_LIST = \
17+
linux-amd64 \
18+
19+
all: check test build
20+
21+
clean:
22+
rm -rf bin/*
23+
24+
build: linux-amd64
25+
26+
fmt:
27+
gofmt -l -w -s ./
28+
29+
vet:
30+
go vet ./...
31+
32+
lint: install-golint
33+
golint ./...
34+
35+
install-golint:
36+
which golint || go install golang.org/x/lint/golint@latest
37+
38+
govulncheck: install-govulncheck
39+
govulncheck ./...
40+
41+
install-govulncheck:
42+
which govulncheck || go install golang.org/x/vuln/cmd/govulncheck@latest
43+
44+
errcheck: install-errcheck
45+
errcheck -exclude=errcheck_excludes.txt ./...
46+
47+
install-errcheck:
48+
which errcheck || go install github.com/kisielk/errcheck@latest
49+
50+
golangci-lint: install-golangci-lint
51+
golangci-lint run --exclude '(SA4003|SA1019|SA5011):' -E contextcheck -E decorder --timeout 2m
52+
53+
install-golangci-lint:
54+
which golangci-lint || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.60.1
55+
56+
check: fmt vet lint errcheck golangci-lint govulncheck
57+
58+
test-main:
59+
go test ./...
60+
61+
test-race:
62+
go test -race ./...
63+
64+
test-pure:
65+
CGO_ENABLED=0 go test ./...
66+
67+
test-full:
68+
go test -coverprofile=coverage.txt -covermode=atomic ./...
69+
70+
benchmark:
71+
go test -bench=. ./...
72+
73+
benchmark-pure:
74+
CGO_ENABLED=0 go test -bench=. ./...
75+
76+
test: test-main test-race test-pure test-full benchmark benchmark-pure
77+
78+
linux-amd64:
79+
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@
80+
81+
gz_releases=$(addsuffix .gz, $(PLATFORM_LIST))
82+
83+
$(gz_releases): %.gz : %
84+
chmod +x $(BINDIR)/$(NAME)-$(basename $@)
85+
gzip -f -S -$(PKG_TAG).gz $(BINDIR)/$(NAME)-$(basename $@)
86+
87+
all-arch: $(PLATFORM_LIST)
88+
89+
release: $(gz_releases)
90+

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[![Latest Release](https://img.shields.io/github/release/iglov/netbox-agent.svg?style=flat-square)](https://github.com/iglov/netbox-agent/releases/latest)
2+
[![GitHub license](https://img.shields.io/github/license/iglov/netbox-agent.svg)](https://github.com/iglov/netbox-agent/blob/master/LICENSE)
3+
[![Go Report Card](https://goreportcard.com/badge/github.com/iglov/netbox-agent)](https://goreportcard.com/report/github.com/iglov/netbox-agent)
4+
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/iglov/netbox-agent)
5+
[![Build Status](https://github.com/iglov/netbox-agent/actions/workflows/build.yml/badge.svg)](https://github.com/iglov/netbox-agent/actions)
6+
[![codecov](https://codecov.io/gh/iglov/netbox-agent/branch/main/graph/badge.svg)](https://codecov.io/gh/iglov/netbox-agent)
7+
8+
# netbox-agent
9+
The first go-netbox/v4 agent! Unf, the first but not the best xd
10+
11+
# How to start
12+
1. Download the lastest release
13+
2. Create .env file in the same dir (`cat .env.example > .env`)
14+
3. Run it!
15+
16+
# How to develop
17+
1. `git clone https://github.com/iglov/netbox-agent`
18+
2. Change something you want and commit changes
19+
3. Build with `make all`

0 commit comments

Comments
 (0)