Skip to content

Commit

Permalink
fix: check is there is new version
Browse files Browse the repository at this point in the history
  • Loading branch information
cchalop1 committed Sep 16, 2024
1 parent c0218b4 commit cdfcbc3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 15 deletions.
7 changes: 5 additions & 2 deletions cmd/just-deploy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ var flags struct {
}

func main() {
currentVersion := application.GetVersion()
fmt.Println("JustDeploy version: ", currentVersion.Version)
isNewVersion := application.CheckIsNewVersion()

if isNewVersion {
fmt.Println("There is a new version available. Please download it by typing: curl -fsSL https://get.justdeploy.app | bash")
}

port := adapter.FindOpenLocalPort(8080)

Expand Down
2 changes: 1 addition & 1 deletion internal/application/delete-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func deleteServiceWithoutDeploy(deployService *service.DeployService, s *domain.
return err
}

deployService.FilesystemAdapter.RemoveEnvsFromDotEnvFile(project.Path, s.Envs)
err = deployService.FilesystemAdapter.RemoveEnvsFromDotEnvFile(project.Path, s.Envs)

if err != nil {
return err
Expand Down
12 changes: 0 additions & 12 deletions internal/application/get-version.go

This file was deleted.

39 changes: 39 additions & 0 deletions internal/application/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package application

import (
"encoding/json"
"net/http"

"cchalop1.com/deploy/internal/api/dto"
)

var Version string

func GetVersion() dto.VersionDto {
return dto.VersionDto{
Version: Version,
GithubUrl: "https://github.com/cchalop1/JustDeploy/releases/tag/" + Version,
}
}

type GitHubRelease struct {
TagName string `json:"tag_name"`
}

func CheckIsNewVersion() bool {
resp, err := http.Get("https://api.github.com/repos/cchalop1/JustDeploy/releases/latest")
if err != nil {
return false
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return false
}

var release GitHubRelease
if err := json.NewDecoder(resp.Body).Decode(&release); err != nil {
return false
}
return Version != release.TagName
}

0 comments on commit cdfcbc3

Please sign in to comment.