Skip to content

Commit

Permalink
Merge pull request #8 from kolyshkin/ci
Browse files Browse the repository at this point in the history
ci: add some basic GHA checks
  • Loading branch information
kolyshkin authored Jul 31, 2024
2 parents 634ecd5 + cf3b5c1 commit 9289123
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 37 deletions.
3 changes: 3 additions & 0 deletions .codespellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[codespell]
skip = ./.git
ignore-words-list = nd
74 changes: 74 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: test
on:
push:
tags:
- v*
branches:
- main
- release-*
pull_request:
env:
GO_VERSION: 1.22.x
permissions:
contents: read

jobs:
lint:
permissions:
contents: read
pull-requests: read
checks: write # to allow the action to annotate code in the PR.
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "${{ env.GO_VERSION }}"
- name: install deps
run: |
sudo apt -q update
sudo apt -qy install libseccomp-dev
- uses: golangci/golangci-lint-action@v6
with:
version: v1.59

go-fix:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: actions/setup-go@v5
with:
go-version: "${{ env.GO_VERSION }}"
- name: run go fix
run: |
go fix ./...
git diff --exit-code
codespell:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: install deps
# Version of codespell bundled with Ubuntu is way old, so use pip.
run: pip install --break-system-packages codespell==v2.3.0
- name: run codespell
run: codespell

space-at-eol:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- run: rm -fr vendor
- run: if git -P grep -I -n '\s$'; then echo "^^^ extra whitespace at EOL, please fix"; exit 1; fi

unit:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "${{ env.GO_VERSION }}"
- name: run go test
run: go test -v ./...
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
linters:
enable:
- unconvert
- unparam
- gofumpt
48 changes: 24 additions & 24 deletions capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,21 @@ type Capabilities interface {
//
// Deprecated: Replace with NewPid2. For example, replace:
//
// c, err := NewPid(0)
// if err != nil {
// return err
// }
// c, err := NewPid(0)
// if err != nil {
// return err
// }
//
// with:
//
// c, err := NewPid2(0)
// if err != nil {
// return err
// }
// err = c.Load()
// if err != nil {
// return err
// }
// c, err := NewPid2(0)
// if err != nil {
// return err
// }
// err = c.Load()
// if err != nil {
// return err
// }
func NewPid(pid int) (Capabilities, error) {
c, err := newPid(pid)
if err != nil {
Expand All @@ -101,21 +101,21 @@ func NewPid2(pid int) (Capabilities, error) {
//
// Deprecated: Replace with NewFile2. For example, replace:
//
// c, err := NewFile(path)
// if err != nil {
// return err
// }
// c, err := NewFile(path)
// if err != nil {
// return err
// }
//
// with:
//
// c, err := NewFile2(path)
// if err != nil {
// return err
// }
// err = c.Load()
// if err != nil {
// return err
// }
// c, err := NewFile2(path)
// if err != nil {
// return err
// }
// err = c.Load()
// if err != nil {
// return err
// }
func NewFile(path string) (Capabilities, error) {
c, err := newFile(path)
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions capability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@ package capability
import "testing"

func TestState(t *testing.T) {
testEmpty := func(name string, c Capabilities, whats CapType) {
testEmpty := func(name string, c Capabilities, what CapType) {
for i := CapType(1); i <= BOUNDING; i <<= 1 {
if (i&whats) != 0 && !c.Empty(i) {
if (i&what) != 0 && !c.Empty(i) {
t.Errorf(name+": capabilities set %q wasn't empty", i)
}
}
}
testFull := func(name string, c Capabilities, whats CapType) {
testFull := func(name string, c Capabilities, what CapType) {
for i := CapType(1); i <= BOUNDING; i <<= 1 {
if (i&whats) != 0 && !c.Full(i) {
if (i&what) != 0 && !c.Full(i) {
t.Errorf(name+": capabilities set %q wasn't full", i)
}
}
}
testPartial := func(name string, c Capabilities, whats CapType) {
testPartial := func(name string, c Capabilities, what CapType) {
for i := CapType(1); i <= BOUNDING; i <<= 1 {
if (i&whats) != 0 && (c.Empty(i) || c.Full(i)) {
if (i&what) != 0 && (c.Empty(i) || c.Full(i)) {
t.Errorf(name+": capabilities set %q wasn't partial", i)
}
}
}
testGet := func(name string, c Capabilities, whats CapType, max Cap) {
testGet := func(name string, c Capabilities, what CapType, max Cap) {
for i := CapType(1); i <= BOUNDING; i <<= 1 {
if (i & whats) == 0 {
if (i & what) == 0 {
continue
}
for j := Cap(0); j <= max; j++ {
Expand Down
6 changes: 4 additions & 2 deletions enumgen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import (
"strings"
)

const fileName = "enum.go"
const genName = "enum_gen.go"
const (
fileName = "enum.go"
genName = "enum_gen.go"
)

type generator struct {
buf bytes.Buffer
Expand Down
4 changes: 1 addition & 3 deletions syscall_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ type vfscapData struct {
version int8
}

var (
_vfsXattrName *byte
)
var _vfsXattrName *byte

func init() {
_vfsXattrName, _ = syscall.BytePtrFromString(vfsXattrName)
Expand Down

0 comments on commit 9289123

Please sign in to comment.