Skip to content

Commit

Permalink
Merge pull request #7 from dhcgn/upgrade-and-cleanup
Browse files Browse the repository at this point in the history
Upgrade to Go 1.17 and remove update feature
  • Loading branch information
dhcgn authored Jan 19, 2022
2 parents 9e0a0e3 + fc07bc0 commit 930a551
Show file tree
Hide file tree
Showing 50 changed files with 23 additions and 2,695 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Download a file from a GitLab server and save it to disk if file is different.

## Latest

https://dl.equinox.io/dhcgn/gitlabfiledownloader/stable
See Releases

## Using

Expand All @@ -27,8 +27,6 @@ Usage of gitlabfiledownloader.exe:
File path in repo, like src/main.go
-token string
Private-Token with access right for "api" and "read_repository"
-update
Update executable from equinox.io
-url string
Url to Api v4, like https://my-git-lab-server.local/api/v4/
```
Expand Down
29 changes: 16 additions & 13 deletions _build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ if ((Get-Command Go -ErrorAction Ignore) -eq $null) {
}

$appName = "GitLabDownloader"
$version = "1.0.1"
$version = "1.0.2"
$publishFolder = "publish"
$debugFolder = "debug"
$compressPublish = $false

$commitID = Invoke-Expression "git rev-list -1 HEAD"
if ($LASTEXITCODE -ne 0) {
Write-Error "Couldn't get commit ID"
EXIT
}

$rootFolder = Split-Path -parent $PSCommandPath
$upx = [System.IO.Path]::Combine($rootFolder, "build", "tools", "upx.exe" )

# Just uncomment the platfoms you don't need
$platforms = @()
Expand All @@ -54,6 +58,10 @@ if($compressPublish)
$maxCount += $platforms.Count
}

# Save GO envs for restore
$savedGOOS = $env:GOOS
$savedGOARCH = $env:GOARCH

foreach ($item in $platforms ) {
# Write-Host "Build" $item.GOOS $item.GOARCH -ForegroundColor Green
Write-Progress -Activity ("Build $($item.GOOS) $($item.GOARCH)") -PercentComplete ([Double]$count / $maxCount * 100)
Expand All @@ -75,7 +83,7 @@ foreach ($item in $platforms ) {
Write-Progress -Activity ("Build $($item.GOOS) $($item.GOARCH)") -Status "Build publish" -PercentComplete ([Double]$count / $maxCount * 100)

$buildOutput = ([System.IO.Path]::Combine( $rootFolder, "build", $publishFolder, ("{0}_{1}_{2}_{3}{4}" -f $appName, $item.GOOS, $item.GOARCH, $version, $extension)))
$executeExpression = "go build -ldflags ""-s -w -X main.version={0}"" -trimpath -o {1} {2}" -f $version, $buildOutput, $buildCode
$executeExpression = "go build -ldflags ""-s -w -X main.version={0} -X main.commitID={1}"" -trimpath -o {2} {3}" -f $version, $commitID, $buildOutput, $buildCode
Write-Host "Execute", $executeExpression -ForegroundColor Green
Invoke-Expression $executeExpression

Expand All @@ -86,15 +94,6 @@ foreach ($item in $platforms ) {

Start-Sleep -Seconds 1 # Because of stupid AV-Shit

if ($compressPublish) {
$count += 1
Write-Progress -Activity ("Build $($item.GOOS) $($item.GOARCH)") -Status "Compress publish" -PercentComplete ([Double]$count / $maxCount * 100)

$executeExpression = "$upx --lzma $buildOutput -q"
Write-Host "Execute", $executeExpression -ForegroundColor Green
Invoke-Expression -Command $executeExpression >> $null
}

$count += 1
Write-Progress -Activity ("Build $($item.GOOS) $($item.GOARCH)") -Status "Build debug" -PercentComplete ([Double]$count / $maxCount * 100)

Expand All @@ -104,4 +103,8 @@ foreach ($item in $platforms ) {
Invoke-Expression $executeExpression
}

# Restore GO envs
$env:GOOS = $savedGOOS
$env:GOARCH = $savedGOARCH

Write-Host "Done!" -ForegroundColor Green
17 changes: 0 additions & 17 deletions _release.ps1

This file was deleted.

3 changes: 0 additions & 3 deletions build/tools/equinox.exe

This file was deleted.

3 changes: 0 additions & 3 deletions build/tools/upx.exe

This file was deleted.

23 changes: 4 additions & 19 deletions cmd/GitLabFileDownloader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
"os"
"path/filepath"
"strconv"

"github.com/dhcgn/GitLabFileDownloader/cmd/GitLabFileDownloader/updater"
)

const (
Expand All @@ -28,11 +26,11 @@ const (
flagUrl = "url"
flagProjectNumber = "projectNumber"
flagRepoFilePath = "repoFilePath"
flagUpdate = "update"
)

var (
version = "undef"
version = "undef"
commitID = "undef"

flagTokenPtr = flag.String(flagToken, ``, `Private-Token with access right for "api" and "read_repository"`)
flagOutPathPtr = flag.String(flagOutPath, ``, "Path to write file to disk")
Expand All @@ -42,8 +40,6 @@ var (
flagProjectNumberPtr = flag.Int(flagProjectNumber, 0, "The Project ID from your project")
flagRepoFilePathPar = flag.String(flagRepoFilePath, ``, "File path in repo, like src/main.go")

flagUpdatePtr = flag.Bool(flagUpdate, false, "Update executable from equinox.io")

exitCode int
)

Expand All @@ -67,27 +63,16 @@ func main() {
}

func mainSub(args []string) {
log.Println(AppName, "Version:", version)
log.Println(AppName, "Version:", version, "Commit:", commitID)
log.Println(`Project: https://github.com/dhcgn/GitLabFileDownloader/`)

if len(args) == 2 && args[1] == "update" {
updater.EquinoxUpdate()
Exit(2)
return
}

flag.Parse()

if *flagUpdatePtr == true {
updater.EquinoxUpdate()
Exit(2)
return
}

settings := getSettings()
isValid, args := isSettingsValid(settings)
if !isValid {
log.Println("Arguments are missing:", args)
flag.PrintDefaults()
Exit(-1)
return
}
Expand Down
49 changes: 1 addition & 48 deletions cmd/GitLabFileDownloader/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"os"
"strings"
"testing"
"time"
)

func Test_main_no_arguments(t *testing.T) {
Expand All @@ -26,50 +25,7 @@ func Test_main_no_arguments(t *testing.T) {
}
}

func Test_main_update(t *testing.T) {
tests := []struct {
name string
args []string
prepare func()
}{
{
name: "Use Flag",
args:[]string{""},
prepare: func() {
updateflag := true
flagUpdatePtr = &updateflag
},
},
{
name: "Use Args",
args:[]string{"", "update"},
prepare: func() {
updateflag := false
flagUpdatePtr = &updateflag
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.prepare()

output := captureOutput(func() {
mainSub(tt.args)
time.Sleep(time.Millisecond*100)
})

// fmt.Println(output)

expectedString := "Starting update"
if !strings.Contains(output, expectedString) {
t.Errorf("main() got console output = \"%v\", want \"%v\"", output, expectedString)
}
})
}
}

func Test_main_use_cases(t *testing.T) {
func Test_main_integration(t *testing.T) {
err, filePath := getTempFilePath()
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -164,9 +120,6 @@ func getTempFilePath() (error, string) {
}

func setFlags(path string) {
update := false
flagUpdatePtr = &update

filePath := "settings.json"
flagRepoFilePathPar = &filePath

Expand Down
47 changes: 0 additions & 47 deletions cmd/GitLabFileDownloader/updater/update.go

This file was deleted.

22 changes: 0 additions & 22 deletions cmd/GitLabFileDownloader/updater/update_test.go

This file was deleted.

4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module github.com/dhcgn/GitLabFileDownloader

go 1.14

require github.com/equinox-io/equinox v1.2.0
go 1.17
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
github.com/equinox-io/equinox v1.2.0 h1:bBS7Ou+Y7Jwgmy8TWSYxEh85WctuFn7FPlgbUzX4DBA=
github.com/equinox-io/equinox v1.2.0/go.mod h1:6s3HJB0PYUNgs0mxmI8fHdfVl3TQ25ieA/PVfr+eyVo=
13 changes: 0 additions & 13 deletions vendor/github.com/equinox-io/equinox/.travis.yml

This file was deleted.

21 changes: 0 additions & 21 deletions vendor/github.com/equinox-io/equinox/LICENSE

This file was deleted.

Loading

0 comments on commit 930a551

Please sign in to comment.