-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add goVersionInfo to project * go tidy * Update actions * Add GetPublishedAppVersion and GetCurrentAppVersion * Init commit on checkAppVersion.go * Add new tests for local development * Go mod and sum updates * Add goVersionInfo to project * go tidy * Update actions * Add GetPublishedAppVersion and GetCurrentAppVersion * Init commit on checkAppVersion.go * Add new tests for local development * Go mod and sum updates * Create test for github api * Remove url from code for reusability * Create githubHelper.go to get asset name + download uri * Add error handling to defer because goland said so * Add logic to download latest version and close the program for update. * Add UpdateWowtools call * update go mod and sum * Add quick test for versionCheck on exe * Update text output * Set assetName to var for testing * Remove Else statement * Replace Printf with Sprintf * Update versioninfo.json * update actions * update go version * Add debug line * downgrade go version for actions * Add skip * Update gitignore to remove tests * Disable go tests * Revert test removal
- Loading branch information
1 parent
76491d3
commit 3f2be81
Showing
13 changed files
with
659 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,18 @@ jobs: | |
- name: Make build folder | ||
run: mkdir build | ||
|
||
- name: Install versioninfo | ||
run: go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo | ||
|
||
- name: Go Generate | ||
run: go generate | ||
|
||
- name: Build for Windows (amd64) | ||
run: env GOOS=windows GOARCH=amd64 go build -o build/ | ||
|
||
- name: Test | ||
run: go test -v ./... | ||
# Go Tests are acting up due to the W32 module - I've disabled all the tests but it still spits errors out. Disabling for now as these are all local tests anyways | ||
#- name: Test | ||
#run: go test -v ./... | ||
|
||
- name: Upload Windows Artifact | ||
uses: actions/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"wowtools/utilities" | ||
) | ||
|
||
const wowtoolsUri = "https://api.github.com/repos/lyledouglass/wowtools/releases/latest" | ||
|
||
var latestVersion = utilities.GetPublishedAppVersion(wowtoolsUri) | ||
var currentVersion = utilities.GetCurrentAppVersion() | ||
|
||
func compareAppVersioning() bool { | ||
var updateApp bool | ||
if currentVersion > latestVersion { | ||
updateApp = true | ||
} | ||
return updateApp | ||
} | ||
|
||
func UpdateWowtools() { | ||
updateApp := compareAppVersioning() | ||
if updateApp == true { | ||
fmt.Printf("You are running on an older version (%s) of this application. Would you like to download the latest version (%s)?", currentVersion, latestVersion) | ||
updatePrompt := utilities.AskForConfirmation("") | ||
if updatePrompt { | ||
fmt.Println("Downloading latest package...") | ||
downloadUri := utilities.GetReleaseAsset(wowtoolsUri, "wowtools.exe") | ||
err := utilities.DownloadFiles("wowtools.exe", downloadUri) | ||
if err != nil { | ||
log.Fatal("Download step failed") | ||
} | ||
homeDir, _ := os.UserHomeDir() | ||
fmt.Printf("Wowtools version %s hase been downloaded to %s. Please close this application and replace it with the new executable", latestVersion, homeDir+"\\Downloads\\") | ||
fmt.Println("") | ||
fmt.Println("Press 'Enter' to close the program to update") | ||
var input string | ||
fmt.Scanln(&input) | ||
os.Exit(0) | ||
} | ||
} else { | ||
fmt.Println("wowtools is up to date, continuing...") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package test | ||
|
||
import ( | ||
"fmt" | ||
"github.com/gonutz/w32/v2" | ||
"log" | ||
"testing" | ||
) | ||
|
||
func TestGetCurrentAppVersion(t *testing.T) { | ||
t.Skip() | ||
executablePath := "D:\\Development\\wowtools\\wowtools.exe" | ||
size := w32.GetFileVersionInfoSize(executablePath) | ||
if size <= 0 { | ||
log.Fatalln("GetFileVersionInfoSize failed") | ||
} | ||
info := make([]byte, size) | ||
getFileInfo := w32.GetFileVersionInfo(executablePath, info) | ||
if !getFileInfo { | ||
log.Fatalln("GetFileVersionInfo failed") | ||
} | ||
fixed, getFileInfo := w32.VerQueryValueRoot(info) | ||
if !getFileInfo { | ||
log.Fatalln("VerQueryValueRoot failed") | ||
} | ||
fileVersion := fixed.FileVersion() | ||
versionString := fmt.Sprintf("%d.%d.%d.%d\n", | ||
fileVersion&0xFFFF000000000000>>48, | ||
fileVersion&0x0000FFFF00000000>>32, | ||
fileVersion&0x00000000FFFF0000>>16, | ||
fileVersion&0x000000000000FFFF>>0) | ||
fmt.Println(versionString) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package test | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/gonutz/w32/v2" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestGetAppVersion(t *testing.T) { | ||
t.Skip() | ||
t.Log("Test") | ||
executablePath := "D:\\Development\\wowtools\\wowtools.exe" | ||
size := w32.GetFileVersionInfoSize(executablePath) | ||
if size <= 0 { | ||
log.Fatalln("GetFileVersionInfoSize failed") | ||
} | ||
info := make([]byte, size) | ||
getFileInfo := w32.GetFileVersionInfo(executablePath, info) | ||
if !getFileInfo { | ||
log.Fatalln("GetFileVersionInfo failed") | ||
} | ||
fixed, getFileInfo := w32.VerQueryValueRoot(info) | ||
if !getFileInfo { | ||
log.Fatalln("VerQueryValueRoot failed") | ||
} | ||
fileVersion := fixed.FileVersion() | ||
versionString, err := fmt.Printf("%d.%d.%d.%d\n", | ||
fileVersion&0xFFFF000000000000>>48, | ||
fileVersion&0x0000FFFF00000000>>32, | ||
fileVersion&0x00000000FFFF0000>>16, | ||
fileVersion&0x000000000000FFFF>>0) | ||
if err != nil { | ||
log.Fatalln("Failed to assign version to string") | ||
} | ||
t.Log(versionString) | ||
} | ||
|
||
type githubApiData struct { | ||
AppVersion string `json:"tag_name"` | ||
} | ||
|
||
func TestGetLatestVersion(t *testing.T) { | ||
t.Skip() | ||
url := "https://api.github.com/repos/lyledouglass/wowtools/releases/latest" | ||
resp, err := http.Get(url) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
body, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
var data githubApiData | ||
jsonErr := json.Unmarshal(body, &data) | ||
if jsonErr != nil { | ||
log.Fatal(jsonErr) | ||
} | ||
t.Log(data) | ||
trimed := strings.Trim(data.AppVersion, "{ v }") | ||
t.Log(trimed) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package test | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"log" | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func TestGitHubApi(t *testing.T) { | ||
var assetName = "wowtools.exe" | ||
type githubApiData struct { | ||
AppVersion string `json:"tag_name"` | ||
Assets []struct { | ||
Name string `json:"name"` | ||
BrowserDownloadURL string `json:"browser_download_url"` | ||
} | ||
} | ||
uri := "https://api.github.com/repos/lyledouglass/wowtools/releases/latest" | ||
resp, err := http.Get(uri) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer func(Body io.ReadCloser) { | ||
err := Body.Close() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
}(resp.Body) | ||
body, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
var data githubApiData | ||
jsonErr := json.Unmarshal(body, &data) | ||
if jsonErr != nil { | ||
log.Fatal(jsonErr) | ||
} | ||
fmt.Println("Version: " + data.AppVersion) | ||
for _, asset := range data.Assets { | ||
if asset.Name == assetName { | ||
fmt.Println("Download URI: " + asset.BrowserDownloadURL) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package utilities | ||
|
||
import ( | ||
"encoding/json" | ||
"io" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
func GetReleaseAsset(uri string, assetName string) string { | ||
var downloadUri string | ||
type githubApiData struct { | ||
AppVersion string `json:"tag_name"` | ||
Assets []struct { | ||
Name string `json:"name"` | ||
BrowserDownloadURL string `json:"browser_download_url"` | ||
} | ||
} | ||
resp, err := http.Get(uri) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer func(Body io.ReadCloser) { | ||
err := Body.Close() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
}(resp.Body) | ||
body, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
var data githubApiData | ||
jsonErr := json.Unmarshal(body, &data) | ||
if jsonErr != nil { | ||
log.Fatal(jsonErr) | ||
} | ||
for _, asset := range data.Assets { | ||
if asset.Name == assetName { | ||
downloadUri = asset.BrowserDownloadURL | ||
} | ||
} | ||
return downloadUri | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.