Skip to content

Commit

Permalink
Add CI: test and build (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcbattirola authored May 16, 2024
1 parent bbe7f81 commit eb30870
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 15 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.21

- name: Install raylib-go dependencies
run: |
sudo apt-get update
sudo apt-get install -y libgl1-mesa-dev libxi-dev libxcursor-dev libxrandr-dev libxinerama-dev libxxf86vm-dev wayland-protocols libwayland-dev libxkbcommon-dev
go get -v github.com/gen2brain/raylib-go/raylib
- name: Build project
run: |
make build
make build-w
- name: Archive build artifacts
uses: actions/upload-artifact@v2
with:
name: build-artifacts
path: ./dist
33 changes: 33 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Test

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test:

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.21

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libgl1-mesa-dev libxi-dev libxcursor-dev libxrandr-dev libxinerama-dev libxxf86vm-dev wayland-protocols libwayland-dev libxkbcommon-dev
go get -v github.com/gen2brain/raylib-go/raylib
- name: Run tests
run: |
make test
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ all: build
build:
go build -o $(BUILD_PATH) main.go

# build on Windows
# build to Windows
build-w:
go build -o $(BUILD_PATH).exe -ldflags "-H=windowsgui" main.go
GOOS=windows GOARCH=amd64 go build -o $(BUILD_PATH).exe -ldflags "-H=windowsgui" main.go

run:
go run main.go

test:
go test ./...
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,26 @@ show-help=true
save-path=/home/user/
```

# Roadmap
## Development

Pre-requisites:

- Go
- [raylib-go](https://github.com/gen2brain/raylib-go?tab=readme-ov-file#raylib-go) requirements

```bash
make run # run the project
make build # builds the project
make build-w # builds the project for windows
```

Builds go to `/dist`.

## Roadmap

- [ ] Test on other OSs
- [x] Linux
- [x] x
- [ ] Wayland
- [x] Windows
- [ ] Run on multiple monitors
- [ ] Builds and install instructions
- [ ] CD
- [ ] Linux
- [ ] Windows
- [ ] Work with multi-monitor
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/mcbattirola/qss

go 1.21.3
go 1.21

require (
github.com/gen2brain/raylib-go/raylib v0.0.0-20240227114648-c3665eb9abf8
Expand Down
2 changes: 1 addition & 1 deletion pkg/qss/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func ReadConfig() (Config, error) {
}

// overwrite defaults with user configs
err = parseConfigFile(&config)
err = loadConfig(&config)
if err != nil {
return Config{}, err
}
Expand Down
19 changes: 14 additions & 5 deletions pkg/qss/configfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func getConfigFilePath() (string, error) {
return path.Join(homeDir, configFileName), nil
}

func parseConfigFile(config *Config) error {
func loadConfig(config *Config) error {
path, err := getConfigFilePath()
if err != nil {
return err
Expand All @@ -34,11 +34,18 @@ func parseConfigFile(config *Config) error {
}
return err
}
defer file.Close()
logger.Info("reading config file")

defer file.Close()
scanner := bufio.NewScanner(file)
parseConfigFile(file, config)
return nil
}

// parseConfigFile parses the content of the pointed file into config.
// In case of an unknown key, it logs the error and don't fail.
// Caller is responsible for closing the file descriptor.
func parseConfigFile(file *os.File, config *Config) {
scanner := bufio.NewScanner(file)
for scanner.Scan() {
split := strings.Split(scanner.Text(), "=")
if len(split) >= 2 {
Expand All @@ -50,6 +57,8 @@ func parseConfigFile(config *Config) error {
continue
}

k = strings.TrimSpace(k)

switch k {
case "font-size":
size, err := strconv.Atoi(v)
Expand All @@ -60,6 +69,8 @@ func parseConfigFile(config *Config) error {
case "show-help":
if v == "true" {
config.ShowHelp = true
} else {
config.ShowHelp = false
}
case "save-path":
config.FilePath = v
Expand All @@ -68,6 +79,4 @@ func parseConfigFile(config *Config) error {
}
}
}

return nil
}
65 changes: 65 additions & 0 deletions pkg/qss/configfile_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package qss

import (
"os"
"testing"

"github.com/mcbattirola/qss/pkg/require"
)

func TestParseConfigFile(t *testing.T) {
tt := []struct {
name string
content string
expected Config
}{
{
name: "empty",
content: "",
expected: Config{},
},
{
name: "with values",
content: `
font-size=24
show-help=true
save-path=/`,
expected: Config{
FontSize: 24,
ShowHelp: true,
FilePath: "/",
},
},
{
name: "ignores comments",
content: `
#font-size=24
#show-help=true
save-path=/`,
expected: Config{
FontSize: 0,
ShowHelp: false,
FilePath: "/",
},
},
}

for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
tmpfile, err := os.CreateTemp("", "config")
require.NoError(t, err)

defer os.Remove(tmpfile.Name())

_, err = tmpfile.Write([]byte(tc.content))
require.NoError(t, err)

_, err = tmpfile.Seek(0, 0)
require.NoError(t, err)
config := &Config{}

parseConfigFile(tmpfile, config)
require.Equal(t, &tc.expected, config)
})
}
}
18 changes: 18 additions & 0 deletions pkg/require/require.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package require

import (
"reflect"
"testing"
)

func NoError(t *testing.T, err error) {
if err != nil {
t.Fatalf("Expected no error but got error '%s'", err.Error())
}
}

func Equal(t *testing.T, expected any, actual any) {
if !reflect.DeepEqual(expected, actual) {
t.Fatalf("Expected %v to be equal to %v, but result is different", expected, actual)
}
}

0 comments on commit eb30870

Please sign in to comment.