Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try linting composite action #17

Merged
merged 8 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,9 @@ name: Lint
on:
pull_request:
push:
branches:
- master

jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: '^1.18'
- name: Run Lint
run: |
docker run --privileged -v /var/run/docker.sock:/var/run/docker.sock --rm -t -v $(pwd):/workspace -v earthly-tmp:/tmp/earthly:rw earthly/earthly:v0.6.21 +lint
Footer
call-workflow:
uses: kairos-io/linting-composite-action/.github/workflows/reusable-linting.yaml@main
5 changes: 3 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ builds:
goarch:
- amd64
- arm64
- 386
- "386"
main: ./
id: "peg"
binary: "peg"
source:
enabled: true
name_template: '{{ .ProjectName }}-{{ .Tag }}-source'
archives:
- format: binary # this removes the tar of the archives, leaving the binaries alone
# this removes the tar of the archives, leaving the binaries alone
- format: binary
name_template: peg-{{ .Tag }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}
checksum:
name_template: '{{ .ProjectName }}-{{ .Tag }}-checksums.txt'
Expand Down
21 changes: 21 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
extends: default

rules:
# 80 chars should be enough, but don't fail if a line is longer
line-length:
max: 150
level: warning

# accept both key:
# - item
#
# and key:
# - item
indentation:
indent-sequences: whatever

truthy:
check-keys: false

document-start:
present: false
32 changes: 16 additions & 16 deletions examples/example.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
machine:
engine: "qemu"
iso: "/some/c3os.iso"
ssh:
user: "c3os"
pass: "c3os"
engine: "qemu"
iso: "/some/c3os.iso"
ssh:
user: "c3os"
pass: "c3os"

specs:
- label: "foo"
describe: "bar"
assertions:
"Simple test":
- preOps:
- eventuallyConnects: 120
command: |
echo aaa
expect:
containString: "aaa"
postOps:
- receiveFile:
src: /etc/os-release
dst: ./os-release-test
"Simple test":
- preOps:
- eventuallyConnects: 120
command: |
echo aaa
expect:
containString: "aaa"
postOps:
- receiveFile:
src: /etc/os-release
dst: ./os-release-test
50 changes: 24 additions & 26 deletions examples/example_docker.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
machine:
image: alpine
engine: docker

image: alpine
engine: docker
specs:
- label: "foo"
describe: "bar"
assertions:
"Test":
- describe: "Sanity check and grab file"
command: |
echo aaa
expect:
containString: "aaa"
preOps:
- eventuallyConnects: 120
postOps:
- receiveFile:
src: /etc/os-release
dst: ./os-release-test
- describe: "check release file"
# run command on the host
onHost: true
command: |
cat os-release-test
expect:
containString: "Alpine"

- label: foo
describe: bar
assertions:
Test:
- describe: Sanity check and grab file
command: |
echo aaa
expect:
containString: aaa
preOps:
- eventuallyConnects: 120
postOps:
- receiveFile:
src: /etc/os-release
dst: ./os-release-test
- describe: check release file
# run command on the host
onHost: true
command: |
cat os-release-test
expect:
containString: Alpine
31 changes: 15 additions & 16 deletions examples/example_download.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
machine:
engine: "qemu"
iso: "https://github.com/c3os-io/c3os/releases/download/v1.24.3-56/c3os-opensuse-v1.24.3-56-ipxe.iso.ipxe"
ssh:
user: "c3os"
pass: "c3os"

engine: qemu
iso: https://github.com/c3os-io/c3os/releases/download/v1.24.3-56/c3os-opensuse-v1.24.3-56-ipxe.iso.ipxe
ssh:
user: c3os
pass: c3os
specs:
- label: "download"
describe: "bar"
assertions:
"Download":
- preOps:
- eventuallyConnects: 10
command: |
echo aaa
expect:
containString: "aaa"
- label: download
describe: bar
assertions:
Download:
- preOps:
- eventuallyConnects: 10
command: |
echo aaa
expect:
containString: aaa
54 changes: 26 additions & 28 deletions examples/example_vbox.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
machine:
iso: "/some/c3os.iso"
ssh:
user: "c3os"
pass: "c3os"

iso: /some/c3os.iso
ssh:
user: c3os
pass: c3os
specs:
- label: "foo"
describe: "bar"
assertions:
"Test":
- describe: "Sanity check and grab file"
command: |
echo aaa
expect:
containString: "aaa"
preOps:
- eventuallyConnects: 120
postOps:
- receiveFile:
src: /etc/os-release
dst: ./os-release-test
- describe: "check release file"
# run command on the host
onHost: true
command: |
cat os-release-test
expect:
containString: "c3os-io/c3os/issues"

- label: foo
describe: bar
assertions:
Test:
- describe: Sanity check and grab file
command: |
echo aaa
expect:
containString: aaa
preOps:
- eventuallyConnects: 120
postOps:
- receiveFile:
src: /etc/os-release
dst: ./os-release-test
- describe: check release file
# run command on the host
onHost: true
command: |
cat os-release-test
expect:
containString: c3os-io/c3os/issues
2 changes: 1 addition & 1 deletion internal/utils/sh.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
logging "github.com/ipfs/go-log"
)

// SH is a convenience wrapper over sh
// SH is a convenience wrapper over sh.
func SH(c string) (string, error) {
logging.Logger("sh").Debugf("Executing sh command: %s", c)
o, err := exec.Command("/bin/sh", "-c", c).CombinedOutput()
Expand Down
15 changes: 10 additions & 5 deletions matcher/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/spectrocloud/peg/pkg/machine/types"
"go.uber.org/zap/buffer"

. "github.com/onsi/gomega"
. "github.com/onsi/gomega" //nolint:revive
)

type VM struct {
Expand Down Expand Up @@ -137,24 +137,29 @@ func Scp(s, d, permissions string) error {
return machineScp(Machine, s, d, permissions)
}

// GatherAllLogs will try to gather as much info from the system as possible, including services, dmesg and os related info
// GatherAllLogs will try to gather as much info from the system as possible, including services, dmesg and os related info.
func GatherAllLogs(services []string, logFiles []string) {
machineGatherAllLogs(Machine, services, logFiles)
}

// GatherLog will try to scp the given log from the machine to a local file
// GatherLog will try to scp the given log from the machine to a local file.
func GatherLog(logPath string) {
machineGatherLog(Machine, logPath)
}

func machineGatherLog(m types.Machine, logPath string) {
machineSudo(m, "chmod 777 "+logPath)
out, err := machineSudo(m, "chmod 777 "+logPath)
if err != nil {
fmt.Printf("Couldn't change permissions on %s\nError: %sOutput:%s\n", logPath, err.Error(), out)
return
}

fmt.Printf("Trying to get file: %s\n", logPath)

scpClient := controller.NewSCPClient(m)
defer scpClient.Close()

err := scpClient.Connect()
err = scpClient.Connect()
if err != nil {
fmt.Println("Couldn't establish a connection to the remote server ", err)
return
Expand Down
4 changes: 2 additions & 2 deletions peg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (a AssertionBlock) Show(logger logging.StandardLogger) {
}
}

// FromFile populates a machineconfig from a peg config file
// FromFile populates a machineconfig from a peg config file.
func FromFile(f string) types.MachineOption {
return func(mc *types.MachineConfig) error {

Expand All @@ -150,7 +150,7 @@ func FromFile(f string) types.MachineOption {
}
}

// FromFile populates a machineconfig from a peg config file
// FromFile populates a machineconfig from a peg config file.
func FromData(data []byte) types.MachineOption {
return func(mc *types.MachineConfig) error {
mm := types.DefaultMachineConfig()
Expand Down
28 changes: 14 additions & 14 deletions peg/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"sync"

logging "github.com/ipfs/go-log"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/ginkgo/v2" //nolint:revive
. "github.com/onsi/gomega" //nolint:revive
"github.com/spectrocloud/peg/internal/utils"

"github.com/spectrocloud/peg/matcher"
Expand Down Expand Up @@ -113,7 +113,7 @@ func runAssertion(a AssertionBlock) {

var logOutline = logging.Logger("test-preview")

// Generates test suites from a peg file
// Generates test suites from a peg file.
func Generate(c *Config) error {
logOutline.Info("Testsuite outline")

Expand Down Expand Up @@ -159,38 +159,38 @@ func Generate(c *Config) error {
return nil
}

// Failer returns a simple fails that exists on failure
func Failer() *failer {
return &failer{}
// Failer returns a simple fails that exists on failure.
func NewFailer() *Failer {
return &Failer{}
}

// SyncedFailer returns a thread-safe failer that collects
// a failure and makes it accessible for later inspection
func SyncedFailer() *syncfailer {
return &syncfailer{}
// a failure and makes it accessible for later inspection.
func NewSyncedFailer() *Syncfailer {
return &Syncfailer{}
}

func (f *syncfailer) Fail() {
func (f *Syncfailer) Fail() {
f.Lock()
defer f.Unlock()
f.failed = true
}

func (f *syncfailer) Failed() bool {
func (f *Syncfailer) Failed() bool {
f.Lock()
defer f.Unlock()
return f.failed
}

type syncfailer struct {
type Syncfailer struct {
sync.Mutex

failed bool
}

type failer struct {
type Failer struct {
}

func (f failer) Fail() {
func (f Failer) Fail() {
os.Exit(1)
}
Loading