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

Add a Github action to run GoLang unittests. #12

Merged
merged 6 commits into from
Apr 4, 2024
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
31 changes: 31 additions & 0 deletions .github/workflows/test-go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# A basic workflow for Go
name: test-go
on: [push]
defaults:
run:
shell: bash -ieo pipefail {0}
jobs:
test:
name: golang test & build
# Must run on github hosted runners
runs-on: [ubuntu-20.04]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.21.3' # The Go version to download (if necessary) and use.
- run: go test ./...
working-directory: app
- run: go build ./...
working-directory: app
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
# https://github.com/golangci/golangci-lint/releases
version: v1.57
# These options work around the errors in this issue
# https://github.com/golangci/golangci-lint-action/issues/244
skip-pkg-cache: true
skip-build-cache: true
working-directory: app
8 changes: 8 additions & 0 deletions app/.golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
linters:
enable:
- gofmt
- goimports
- staticcheck
run:
# Use skip-dirs if there are any directors that must be skipped
skip-dirs: []
3 changes: 2 additions & 1 deletion app/cmd/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package cmd
import (
"context"
"fmt"
"os"

"github.com/jlewi/foyle/app/pkg/application"
"github.com/jlewi/foyle/app/pkg/assets"
"github.com/jlewi/monogo/helpers"
"github.com/spf13/cobra"
"os"
)

// NewAssetsCmd returns a command to download the assets
Expand Down
3 changes: 2 additions & 1 deletion app/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package cmd

import (
"fmt"
"os"

"github.com/jlewi/foyle/app/pkg/config"
"github.com/spf13/cobra"
"os"
)

const (
Expand Down
3 changes: 2 additions & 1 deletion app/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package cmd

import (
"fmt"
"github.com/jlewi/foyle/app/pkg/application"
"os"

"github.com/jlewi/foyle/app/pkg/application"

"github.com/jlewi/monogo/helpers"
"github.com/spf13/cobra"
)
Expand Down
7 changes: 4 additions & 3 deletions app/pkg/application/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package application

import (
"fmt"
"io"
"os"
"strings"

"github.com/go-logr/zapr"
"github.com/jlewi/foyle/app/pkg/config"
"github.com/jlewi/foyle/app/pkg/server"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"go.uber.org/zap"
"io"
"os"
"strings"
)

// App is a struct to hold values needed across all commands.
Expand Down
11 changes: 6 additions & 5 deletions app/pkg/assets/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ package assets
import (
"archive/tar"
"context"
"io"
"net/url"
"os"
"path/filepath"

"github.com/go-logr/zapr"
"github.com/jlewi/foyle/app/pkg/config"
"github.com/jlewi/foyle/app/pkg/logs"
"github.com/jlewi/hydros/pkg/files"
"github.com/jlewi/hydros/pkg/images"
"github.com/pkg/errors"
"go.uber.org/zap"
"io"
"net/url"
"os"
"path/filepath"
)

const (
Expand Down Expand Up @@ -44,7 +45,7 @@ func (m *Manager) Download(ctx context.Context) error {
log := logs.FromContext(ctx)
// Map from the name of the asset to the source of the location
assets := map[string]asset{
vscode: asset{
vscode: {
source: m.config.Assets.VSCode.URI,
stripPrefix: "assets",
},
Expand Down
5 changes: 3 additions & 2 deletions app/pkg/assets/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package assets

import (
"context"
"github.com/jlewi/foyle/app/pkg/config"
"go.uber.org/zap"
"os"
"testing"

"github.com/jlewi/foyle/app/pkg/config"
"go.uber.org/zap"
)

func Test_Download(t *testing.T) {
Expand Down
11 changes: 6 additions & 5 deletions app/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package config

import (
"fmt"
"io/fs"
"os"
"os/user"
"path/filepath"
"strings"

"github.com/go-logr/zapr"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.uber.org/zap"
"gopkg.in/yaml.v3"
"io/fs"
"os"
"os/user"
"path/filepath"
"strings"
)

// Note: The application uses viper for configuration management. Viper merges configurations from various sources
Expand Down
5 changes: 3 additions & 2 deletions app/pkg/server/extensions.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package server

import (
"os"
"path/filepath"

"github.com/go-logr/zapr"
"github.com/pkg/errors"
"go.uber.org/zap"
"os"
"path/filepath"
)

// findExtensionsInDir returns a list of all the extensions
Expand Down
12 changes: 7 additions & 5 deletions app/pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ package server
import (
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"github.com/go-logr/zapr"
"github.com/jlewi/foyle/app/pkg/config"
"github.com/pkg/errors"
"go.uber.org/zap"
"html/template"
"log"
"net/http"
Expand All @@ -16,6 +11,12 @@ import (
"path/filepath"
"strings"
"syscall"

"github.com/gin-gonic/gin"
"github.com/go-logr/zapr"
"github.com/jlewi/foyle/app/pkg/config"
"github.com/pkg/errors"
"go.uber.org/zap"
)

// Server is the main application server for foyle
Expand Down Expand Up @@ -181,6 +182,7 @@ func (s *Server) setHTMLTemplates(router *gin.Engine) error {
func (s *Server) Run() error {
address := fmt.Sprintf("%s:%d", s.config.Server.BindAddress, s.config.Server.HttpPort)
log.Print("Server listening on http://" + address)
trapInterrupt()
if err := http.ListenAndServe(address, s.engine); err != nil {
log.Fatalf("There was an error with the http server: %v", err)
}
Expand Down
Loading