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

chore: add pre-commit pipeline + configuration #15

Merged
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
35 changes: 35 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: pre-commit

on:
workflow_dispatch:
pull_request:
branches:
- master
- feat/wekahome-control-tool # temporary
push:
branches:
- master
- feat/wekahome-control-tool # temporary

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-python@v3

- name: set PY
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV

- uses: actions/cache@v1
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}

- run: go install mvdan.cc/gofumpt@latest
- run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH

- uses: pre-commit/[email protected]
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ bin

**/.DS_Store
.idea

19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix=lf]
- id: trailing-whitespace

- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.1
hooks:
- id: go-mod-tidy

- repo: https://github.com/Bahjat/pre-commit-golang
rev: v1.0.3
hooks:
- id: gofumpt
- id: go-vet
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ $(PLATFORMS):
@echo ok

.PHONY: all
all: default $(PLATFORMS)
all: default $(PLATFORMS)
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3
0.3
1 change: 0 additions & 1 deletion internal/cli/api/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ var analyticsCmd = &cobra.Command{
}
if clusterID != "" {
cluster, err := api.GetCluster(clusterID)

if err != nil {
utils.UserError(err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/api/diags.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ var diagsListCmd = &cobra.Command{
})
},
}

var diagsDownloadCmd = &cobra.Command{
Use: "download <cluster-id> <filename>",
Short: "Download cluster diagnostics file",
Expand All @@ -106,7 +107,6 @@ var diagsDownloadCmd = &cobra.Command{
if err != nil {
utils.UserError(err.Error())
}

},
}

Expand Down
8 changes: 4 additions & 4 deletions internal/cli/api/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func init() {
"show more information on events, specifically their params")
eventsCmd.Flags().BoolVar(&eventsCmdArgs.Json, "json", false,
"Use JSON output format")
//eventsCmd.Flags().StringVar(&eventsCmdArgs.Params, "param", "",
// eventsCmd.Flags().StringVar(&eventsCmdArgs.Params, "param", "",
// "show events having these parameters")
})
}
Expand All @@ -65,7 +65,7 @@ var eventsCmdArgs = struct {
EndTime string
Wide bool
Json bool
//Params string
// Params string
}{}

var eventsCmd = &cobra.Command{
Expand Down Expand Up @@ -108,13 +108,13 @@ var eventsCmd = &cobra.Command{
EndTime: endTime,
Limit: eventsCmdArgs.Limit,
Wide: eventsCmdArgs.Wide,
//Params: eventsCmdArgs.Params,
// Params: eventsCmdArgs.Params,
})
if err != nil {
utils.UserError(err.Error())
return
}
//query.Options.NoAutoFetchNextPage = false
// query.Options.NoAutoFetchNextPage = false
headers := []string{"Time", "Type", "Category"}
if eventsCmdArgs.ShowEventIDs {
headers = append(headers, "UUID")
Expand Down
7 changes: 4 additions & 3 deletions internal/env/aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package env

import (
"fmt"
"github.com/google/uuid"
"github.com/pelletier/go-toml"
"io/ioutil"
"os"

"github.com/google/uuid"
"github.com/pelletier/go-toml"
)

type Aliases struct {
Expand Down Expand Up @@ -113,7 +114,7 @@ func (aliases *Aliases) save() {
if err != nil {
logger.Panic().Err(err).Msg("Failed to serialize aliases")
}
file, err := os.OpenFile(aliases.FilePath, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, os.ModeExclusive|0644)
file, err := os.OpenFile(aliases.FilePath, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, os.ModeExclusive|0o644)
if err != nil {
logger.Fatal().Str("file", aliases.FilePath).Err(err).
Msg("Failed to open aliases file for writing")
Expand Down
4 changes: 2 additions & 2 deletions internal/env/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func createDefaultConfigFileAndExit(createDir bool) {
writeCLIConfig(&Config{
DefaultSite: DefaultSiteName,
Sites: map[string]*SiteConfig{
DefaultSiteName: &SiteConfig{
DefaultSiteName: {
CloudURL: DefaultCloudURL,
},
},
Expand Down Expand Up @@ -127,7 +127,7 @@ func writeCLIConfig(config *Config) {
logger.Panic().Err(e).Msg("Failed to marshal configuration values to TOML format")
}

e = ioutil.WriteFile(ConfigFilePath, data, os.ModeExclusive|0644)
e = ioutil.WriteFile(ConfigFilePath, data, os.ModeExclusive|0o644)
if e != nil {
logger.Fatal().
Str("file", ConfigFilePath).
Expand Down
2 changes: 1 addition & 1 deletion internal/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var validColors = map[string]bool{
func init() {
fileInfo, _ := os.Stdout.Stat()
IsInteractiveTerminal = (fileInfo.Mode() & os.ModeCharDevice) != 0
//IsColorOutputSupported = IsInteractiveTerminal
// IsColorOutputSupported = IsInteractiveTerminal
}

func IsValidColorMode() bool {
Expand Down
2 changes: 1 addition & 1 deletion internal/k3s/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func hasSystemd() bool {
}

func Hostname() string {
var hostname = os.Getenv("HOSTNAME")
hostname := os.Getenv("HOSTNAME")
if hostname == "" {
f, _ := os.Open("/etc/hostname")
hostname, _ = bufio.NewReader(f).ReadString('\n')
Expand Down
6 changes: 4 additions & 2 deletions internal/k3s/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"regexp"
)

const k3sResolvConfPath = "/etc/k3s-resolv.conf"
const fakeNameserver = "nameserver 127.0.0.1:9999"
const (
k3sResolvConfPath = "/etc/k3s-resolv.conf"
fakeNameserver = "nameserver 127.0.0.1:9999"
)

var resolvRegexp = regexp.MustCompile(`%s*nameserver.*`)

Expand Down
20 changes: 9 additions & 11 deletions internal/k3s/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ import (
"github.com/weka/gohomecli/internal/utils"
)

const k3sImagesPath = "/var/lib/rancher/k3s/agent/images/"
const defaultLocalStoragePath = "/opt/local-path-provisioner"

var (
ErrExists = errors.New("k3s already installed")
const (
k3sImagesPath = "/var/lib/rancher/k3s/agent/images/"
defaultLocalStoragePath = "/opt/local-path-provisioner"
)

var (
k3sBundleRegexp = regexp.MustCompile(`k3s.*\.(tar(\.gz)?)|(tgz)`)
)
var ErrExists = errors.New("k3s already installed")

var k3sBundleRegexp = regexp.MustCompile(`k3s.*\.(tar(\.gz)?)|(tgz)`)

type InstallConfig struct {
Iface string // interface for k3s network to work on, required
Expand Down Expand Up @@ -115,7 +113,7 @@ func copyK3S() bundle.TarCallback {
Callback: func(ctx context.Context, _ fs.FileInfo, r io.Reader) (err error) {
logger.Info().Msg("Copying k3s binary")

f, err := os.OpenFile(k3sBinary(), os.O_CREATE|os.O_WRONLY, fs.FileMode(0755))
f, err := os.OpenFile(k3sBinary(), os.O_CREATE|os.O_WRONLY, fs.FileMode(0o755))
if err != nil {
return err
}
Expand All @@ -140,10 +138,10 @@ func copyAirgapImages() bundle.TarCallback {
Callback: func(ctx context.Context, info fs.FileInfo, r io.Reader) (err error) {
logger.Info().Msg("Copying airgap images")

os.MkdirAll(k3sImagesPath, 0644)
os.MkdirAll(k3sImagesPath, 0o644)

var f *os.File
f, err = os.OpenFile(path.Join(k3sImagesPath, info.Name()), os.O_CREATE|os.O_WRONLY, fs.FileMode(0644))
f, err = os.OpenFile(path.Join(k3sImagesPath, info.Name()), os.O_CREATE|os.O_WRONLY, fs.FileMode(0o644))
if err != nil {
return err
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/weka/gohomecli/internal/env"
"github.com/weka/gohomecli/internal/utils"
"golang.org/x/sync/semaphore"
"io"
"net/http"
"net/url"
"os"
"strings"
"sync"
"time"

"github.com/weka/gohomecli/internal/env"
"github.com/weka/gohomecli/internal/utils"
"golang.org/x/sync/semaphore"
)

var logger = utils.GetLogger("API")
Expand Down Expand Up @@ -206,7 +207,7 @@ func (client *Client) SendRequest(method string, url string, result interface{},
return nil
}

//TODO check if mage sense to use SendRequest
// TODO check if mage sense to use SendRequest
func (client *Client) Download(url string, fileName string, options *RequestOptions) error {
if options == nil {
options = &RequestOptions{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type EventQueryOptions struct {
EndTime time.Time
Limit int
Wide bool
//Params string
// Params string
}

func (options *EventQueryOptions) ToQueryParams() (*QueryParams, error) {
Expand Down
7 changes: 5 additions & 2 deletions test/test_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package main

import (
"fmt"

"github.com/weka/gohomecli/pkg/client"
)

const hostname = "api.fries.home.weka.io"
const token = "Onjb8DYnP9DDVSargu11TrvEvpQEwS"
const (
hostname = "api.fries.home.weka.io"
token = "Onjb8DYnP9DDVSargu11TrvEvpQEwS"
)

func main() {
client := client.NewClient(hostname, token)
Expand Down
Loading