diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index 3e1bbd8..0000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,71 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -name: "CodeQL" - -on: - push: - branches: [main] - pull_request: - # The branches below must be a subset of the branches above - branches: [main] - schedule: - - cron: '0 20 * * 2' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - # Override automatic language detection by changing the below list - # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] - language: ['go'] - # Learn more... - # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - # We must fetch at least the immediate parents so that if this is - # a pull request then we can checkout the head. - fetch-depth: 2 - - # If this run was triggered by a pull request event, then checkout - # the head of the pull request instead of the merge commit. - - run: git checkout HEAD^2 - if: ${{ github.event_name == 'pull_request' }} - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v3 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v3 - - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml deleted file mode 100644 index b99939e..0000000 --- a/.github/workflows/go.yaml +++ /dev/null @@ -1,29 +0,0 @@ -name: Go -on: [push] -jobs: - - build: - name: Build - runs-on: ubuntu-latest - steps: - - - name: Install X11/OpenGL - run: sudo apt-get update && sudo apt-get install -y xorg-dev - - - name: Set up Go 1.18 - uses: actions/setup-go@v5 - with: - go-version: 1.18 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v4 - - - name: Install Fyne tools - run: make install-fyne && make install-fyne-cross - - - name: Tests - run: make test - - - name: Build test binaries - run: PATH=${PATH}:~/go/bin make .build-test-binaries diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..e155ce0 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,171 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +name: "Tests" + +on: + push: + branches: [main] + pull_request: + # The branches below must be a subset of the branches above + branches: [main] + schedule: + - cron: '0 20 * * 2' + +env: + GO_VERSION: '1.22.5' + GOLANGCI_LINT_VERSION: 'v1.60.3' + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + + - name: Install X11/OpenGL + run: sudo apt-get update && sudo apt-get install -y xorg-dev + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + + - name: Install Fyne tools + run: make install-fyne && make install-fyne-cross + + - name: Tests + run: make test + + - name: Build test binaries + run: PATH=${PATH}:~/go/bin make .build-test-binaries + + govulncheck: + name: govulncheck + runs-on: ubuntu-latest + steps: + - name: Install X11/OpenGL + run: sudo apt-get update && sudo apt-get install -y xorg-dev + + - name: govulncheck + uses: golang/govulncheck-action@v1 + with: + go-version-input: '${{ env.GO_VERSION }}' + go-package: ./... + + golangci: + name: golanci-lint + runs-on: ubuntu-latest + steps: + - name: Install X11/OpenGL + run: sudo apt-get update && sudo apt-get install -y xorg-dev + + - uses: actions/setup-go@v5 + with: + go-version: '${{ env.GO_VERSION }}' + + - uses: actions/checkout@v4 + + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: '${{ env.GOLANGCI_LINT_VERSION }}' + + # Optional: working directory, useful for monorepos + # working-directory: somedir + + # Optional: golangci-lint command line arguments. + # args: --issues-exit-code=0 + args: --timeout 5m + + # Optional: show only new issues if it's a pull request. The default value is `false`. + # only-new-issues: true + + # Optional: if set to true then the all caching functionality will be complete disabled, + # takes precedence over all other caching options. + # skip-cache: true + + # Optional: if set to true then the action don't cache or restore ~/go/pkg. + # skip-pkg-cache: true + + # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. + # skip-build-cache: true + + codeql: + name: CodeQL Analyze + # Runner size impacts CodeQL analysis time. To learn more, please see: + # - https://gh.io/recommended-hardware-resources-for-running-codeql + # - https://gh.io/supported-runners-and-hardware-resources + # - https://gh.io/using-larger-runners + # Consider using larger runners for possible analysis time improvements. + runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} + timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'go' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ] + # Use only 'java' to analyze code written in Java, Kotlin or both + # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install X11/OpenGL + run: sudo apt-get update && sudo apt-get install -y xorg-dev + + - name: Install Go + uses: actions/setup-go@v5 + with: + go-version: '${{ env.GO_VERSION }}' + + + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). + # If this step fails, then you should remove it and run the build manually (see below) + # - name: Autobuild + # uses: github/codeql-action/autobuild@v2 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # Initializes the CodeQL tools for scanning. +# - name: Initialize CodeQL +# uses: github/codeql-action/init@v3 +# with: +# languages: ${{ matrix.language }} +# # If you wish to specify custom queries, you can do so here or in a config file. +# # By default, queries listed here will override any specified in a config file. +# # Prefix the list here with "+" to use these queries and those in the config file. +# +# # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs +# # queries: security-extended,security-and-quality + + - name: Generate Coverage Report + run: | + make unittest + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: codecov/codecov-action@v4 + with: + env_vars: OS + files: ./coverage.out + fail_ci_if_error: true + flags: unittests + token: '${{ secrets.CODECOV_TOKEN }}' + verbose: false \ No newline at end of file diff --git a/.gitignore b/.gitignore index 049f723..b21bba2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ dist AlpacaScope.exe.syso fyne-cross +coverage.out diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..da76c2f --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,29 @@ +linters: + enable: + - asciicheck + - ineffassign + - gocyclo + - dupl + # - funlen + - gofmt + - gosec + - misspell + - revive + - whitespace + # - unparam + +linters-settings: + revive: + rules: + - name: var-naming + severity: warning + disabled: false + arguments: + - ["ID", "URL", "JSON", "URI"] # AllowList + - [""] # DenyList + +issues: + exclude-rules: + - linters: + - revive + text: ALL_CAPS diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..082b194 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "makefile.configureOnOpen": false +} \ No newline at end of file diff --git a/Makefile b/Makefile index b71c239..1f9c907 100644 --- a/Makefile +++ b/Makefile @@ -4,12 +4,13 @@ ARCH ?= $(shell uname -m) ifeq ($(ARCH),x86_64) GOARCH := amd64 else -GOARCH := $(ARCH) # no idea if this works for other platforms.... +# no idea if this works for other platforms.... +GOARCH := $(ARCH) endif BUILDINFOSDET ?= PROGRAM_ARGS ?= -PROJECT_VERSION := 2.4.1 +PROJECT_VERSION := 2.4.2 BUILD_ID := 1 DOCKER_REPO := synfinatic PROJECT_NAME := alpacascope @@ -42,11 +43,13 @@ DARWIN_GUI := $(DIST_DIR)/$(PROJECT_NAME)-gui-$(PROJECT_VERSION)- WINDOWS_RELEASE := $(DIST_DIR)/AlpacaScope.exe WINDOWS_CLI := $(DIST_DIR)/AlpacaScope-CLI-$(PROJECT_VERSION).exe WINDOWS := $(DIST_DIR)/AlpacaScope-Debug-$(PROJECT_VERSION).exe +FYNE_VERSION := v2.5.0 +FYNE_CROSS_VERSION := v1.5.0 GUI_FILES = $(shell find . -type f -name '*.go' | grep -v _test.go | grep -v ./cmd/alpacascope/ ) Makefile CLI_FILES = $(shell find . -type f -name '*.go' | grep -v _test.go | grep -v ./cmd/alpacascope-gui/) Makefile -ALL: $(OUTPUT_NAME) ## Build binary. Needs to be a supported plaform as defined above +ALL: $(GOOS) ## Build binary. Needs to be a supported plaform as defined above include help.mk # place after ALL target and before all other targets @@ -77,10 +80,10 @@ build-gui: darwin-gui darwin-release-gui windows linux-gui ## Build GUI binaries install-fyne: ## Download and install Fyne - go install fyne.io/fyne/v2/cmd/fyne@v2.3.1 + go install fyne.io/fyne/v2/cmd/fyne@$(FYNE_VERSION) install-fyne-cross: ## Download and install Fyne-Cross - go install github.com/fyne-io/fyne-cross@v1.3.0 + go install github.com/fyne-io/fyne-cross@$(FYNE_CROSS_VERSION) # Install fyne binary in $GOPATh/bin .PHONY: .fyne .fyne-cross @@ -118,7 +121,7 @@ debug: .prepare ## Run debug in dlv .PHONY: unittest unittest: ## Run go unit tests - go test ./... + go test -ldflags='$(LDFLAGS)' -covermode=atomic -coverprofile=coverage.out ./... .PHONY: test-race test-race: ## Run `go test -race` on the code @@ -189,9 +192,9 @@ darwin-gui: $(DARWIN_GUI) ## Build MacOS/x86_64 GUI darwin-release-gui: $(DARWIN_RELEASE_GUI) ## Build MacOS/x86_64 Release GUI $(DARWIN_RELEASE_GUI): $(GUI_FILES) | .build-gui-check .prepare .fyne - @fyne package -appID net.synfin.alpacascope -name AlpacaScope \ - -appVersion $(PROJECT_VERSION) -appBuild $(BUILD_ID) \ - -os darwin -sourceDir cmd/alpacascope-gui && \ + @fyne package --appID net.synfin.alpacascope --name AlpacaScope \ + --appVersion $(PROJECT_VERSION) --appBuild $(BUILD_ID) \ + --target darwin -sourceDir cmd/alpacascope-gui && \ rm -rf $(DARWIN_RELEASE_GUI) && mv AlpacaScope.app $(DARWIN_RELEASE_GUI) $(DARWIN_RELEASE_ZIP): $(DARWIN_RELEASE_GUI) @@ -204,19 +207,20 @@ $(DARWIN_GUI): $(GUI_FILES) | .build-gui-check .prepare windows: $(WINDOWS) ## Build Windows/x86_64 GUI $(WINDOWS): $(GUI_FILES) | .fyne-cross .prepare - @fyne-cross windows -app-id net.synfin.alpacascope -developer "Aaron Turner" \ - -app-version $(PROJECT_VERSION) -ldflags '$(LDFLAGS)' \ - -icon $(shell pwd)/cmd/alpacascope-gui/Icon.png \ - -name AlpacaScope.exe $(shell pwd)/cmd/alpacascope-gui && \ - mv fyne-cross/bin/windows-amd64/AlpacaScope.exe $(WINDOWS) + fyne-cross windows -app-id net.synfin.alpacascope -developer "Aaron Turner" \ + -app-version $(PROJECT_VERSION) \ + -env FYNE_VERSION=$(FYNE_VERSION) \ + -icon ./cmd/alpacascope-gui/Icon.png \ + -name AlpacaScope-Debug-$(PROJECT_VERSION) ./cmd/alpacascope-gui && \ + mv ./fyne-cross/bin/windows-$(GOARCH)/AlpacaScope-Debug-$(PROJECT_VERSION).exe $(DIST_DIR) windows-release: $(WINDOWS_RELEASE) ## Build Windows/x86_64 release GUI $(WINDOWS_RELEASE): $(GUI_FILES) | .build-windows-check .prepare .fyne @rm -f dist/AlpacaScope-$(PROJECT_VERSION).exe && \ - fyne package -appID net.synfin.AlpacaScope -name net.synfin.AlpacaScope \ - -appVersion $(PROJECT_VERSION) -appBuild $(BUILD_ID) -os windows -release \ - -sourceDir cmd/alpacascope-gui && \ + fyne package --appID net.synfin.AlpacaScope --name net.synfin.AlpacaScope \ + --appVersion $(PROJECT_VERSION) --appBuild $(BUILD_ID) --target windows --release \ + --sourceDir cmd/alpacascope-gui && \ mv cmd/alpacascope-gui/alpacascope-gui.exe $(WINDOWS_RELEASE) windows-cli: $(WINDOWS_CLI) ## Build Windows/amd64 CLI diff --git a/cmd/alpacascope-gui/main.go b/cmd/alpacascope-gui/main.go index d6dfaa6..95c63c1 100644 --- a/cmd/alpacascope-gui/main.go +++ b/cmd/alpacascope-gui/main.go @@ -267,15 +267,15 @@ func (c *AlpacaScopeConfig) Run() { var connectAttempts int64 = 1 if c.AutoStart { connectAttempts, _ = strconv.ParseInt(c.AutoConnectAttempts, 10, 32) - sbox.AddLine(fmt.Sprintf("Attempting connecting to TelescopeID:%s %d times", + sbox.AddLine(fmt.Sprintf("Attempting connecting to TelescopeID=%s %d times", c.AscomTelescope, connectAttempts)) } for i := 1; !connected && int64(i) <= connectAttempts && c.isRunning; i++ { connected, err = scope.GetConnected() if err != nil { - sbox.AddLine(fmt.Sprintf("%d/%d Unable to connect to TelescopeID:%s", - i, connectAttempts, c.AscomTelescope)) + line := fmt.Sprintf("%d/%d Unable to connect to TelescopeID=%s: %s", i, connectAttempts, c.AscomTelescope, err.Error()) + sbox.AddLine(line) time.Sleep(time.Second) } } @@ -284,7 +284,7 @@ func (c *AlpacaScopeConfig) Run() { // Manually connect err = scope.PutConnected(true) if err != nil { - sbox.AddLine(fmt.Sprintf("Unable to connect to telescope ID %s", c.AscomTelescope)) + sbox.AddLine(fmt.Sprintf("Unable to connect to TelescopeID=%s: %s", c.AscomTelescope, err.Error())) sbox.AddLine(err.Error()) sbox.AddLine(CHECK) tempQuit <- true @@ -292,7 +292,7 @@ func (c *AlpacaScopeConfig) Run() { } connected, err = scope.GetConnected() if err != nil || !connected { - sbox.AddLine(fmt.Sprintf("Unable to connect to telescope ID %s", c.AscomTelescope)) + sbox.AddLine(fmt.Sprintf("Unable to connect to TelescopeID=%s: %s", c.AscomTelescope, err.Error())) sbox.AddLine(err.Error()) sbox.AddLine(CHECK) tempQuit <- true diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..822e46a --- /dev/null +++ b/codecov.yml @@ -0,0 +1,13 @@ +coverage: + precision: 2 + round: up + range: 60..80 + status: + project: + default: + target: auto + threshold: 0.25% + +# ignore: + # - "cmd/**/*" + #- "cmd" diff --git a/go.mod b/go.mod index e506a0d..c9bafcb 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/synfinatic/alpacascope -go 1.21 +go 1.22.5 // when you update the Fyne version, also update the Makefile target require ( diff --git a/telescope/coordinates_test.go b/telescope/coordinates_test.go index f6be2a4..c78c210 100644 --- a/telescope/coordinates_test.go +++ b/telescope/coordinates_test.go @@ -1,18 +1,28 @@ package telescope import ( + "runtime" "testing" "github.com/stretchr/testify/assert" ) func TestRAToHourAngle(t *testing.T) { - tests := map[float64]map[string]float64{ - 54.382619999999974: map[string]float64{ + tests := map[float64]map[string]float64{} + switch runtime.GOARCH { + case "arm64": + tests[54.38261999999998] = map[string]float64{ "ra": 250.425, "lst": 304.80762, - }, + } + + default: + tests[54.382619999999974] = map[string]float64{ + "ra": 250.425, + "lst": 304.80762, + } } + for check, test := range tests { ra := NewDMSDegrees(test["ra"]) assert.Equal(t, check, RAToHourAngle(ra.HMS(), test["lst"]))