Skip to content

Commit

Permalink
Reference download manual
Browse files Browse the repository at this point in the history
  • Loading branch information
minottic committed Jun 3, 2024
1 parent 18f0f5a commit 93395d0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 65 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,25 @@ module load Pmodules/1.0.0
./build 1.1.10 -f
```

As descripted in the buildblock README, the
As described in the buildblock README, the
[GUI](https://git.psi.ch/MELANIE/rollout/-/tree/master/Software/00-General/SciCatArchiverGUI)
needs to be compiled separately and manually copied to AFS.

### Manual deployment
### Manual deployment and upgrade

Some machines need the tools deployed manually. This can be done as follows:
This can be followed to deploy or upgrade the tool manually:

1. Go to the GitHub [releases page](https://github.com/paulscherrerinstitute/scicat-cli/releases).

2. Choose the release of interest (`latest` is recommended)

3. Download the file from the `Assets` of the chosen release, making sure to select the one compatible with your OS

4. Decompress the asset

5. Open the folder and run the required APP (grant `execute` permissions if required)

#### One liner for Linux systems

```bash
curl -s 'https://api.github.com/repos/paulscherrerinstitute/scicat-cli/releases/latest' \
Expand Down
39 changes: 9 additions & 30 deletions datasetUtils/checkForNewVersion.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"log"
"net/http"
"os"
"runtime"
"strconv"
"strings"
version "github.com/mcuadros/go-version"
Expand All @@ -17,7 +16,7 @@ var scanner = bufio.NewScanner(os.Stdin)

var (
GitHubAPI = "https://api.github.com/repos/paulscherrerinstitute/scicat-cli/releases/latest"
DeployLocation = "https://github.com/paulscherrerinstitute/scicat-cli/releases/download"
DonwloadInstructions = "https://github.com/paulscherrerinstitute/scicat-cli?tab=readme-ov-file#manual-deployment-and-upgrade"
)

type Release struct {
Expand All @@ -44,14 +43,6 @@ func fetchLatestVersion(client *http.Client) (string, error) {
return strings.TrimSpace(release.TagName), nil
}

// Make sure the version number is stripped of the 'v' prefix. That's required for `strconv.Atoi` to work.
func generateDownloadURL(deployLocation, latestVersion, osName string) string {
if strings.ToLower(osName) == "windows" {
return fmt.Sprintf("%s/v%s/scicat-cli_v%s_%s_x86_64.zip", deployLocation, latestVersion, latestVersion, strings.Title(osName))
}
return fmt.Sprintf("%s/v%s/scicat-cli_v%s_%s_x86_64.tar.gz", deployLocation, latestVersion, latestVersion, strings.Title(osName))
}

func CheckForNewVersion(client *http.Client, APP string, VERSION string) {
// avoid checking for new version in test mode
if os.Getenv("TEST_MODE") == "true" {
Expand All @@ -74,26 +65,14 @@ func CheckForNewVersion(client *http.Client, APP string, VERSION string) {
}
log.Printf("Latest version: %s", latestVersion)

// Get the operating system name
osName := runtime.GOOS

// Generate the download URL
downloadURL := generateDownloadURL(DeployLocation, latestVersion, osName)

if version.Compare(latestVersion, VERSION, ">") {
// Notify an update if the version has changed
log.Println("You should upgrade to a newer version")
log.Println("Current Version: ", VERSION)
log.Println("Latest Version: ", latestVersion)
log.Println("You can either download the file using the browser or use the following command:")

if strings.ToLower(osName) == "windows" {
log.Printf("Browser: %s\nCommand: curl -L -O %s; unzip scicat-cli_v%s_%s_x86_64.zip; cd scicat-cli\n", downloadURL, downloadURL, latestVersion, strings.Title(osName))
} else {
log.Printf("Browser: %s\nCommand: curl -L -O %s; tar xzf scicat-cli_v%s_%s_x86_64.tar.gz; cd scicat-cli; chmod +x %s\n", downloadURL, downloadURL, latestVersion, strings.Title(osName), APP)
}
} else {
if !version.Compare(latestVersion, VERSION, ">") {
log.Println("Your version of this program is up-to-date")
return
}
return

// Notify an update if the version has changed
log.Println("You should upgrade to a newer version")
log.Println("Current Version:", VERSION)
log.Println("Latest Version:", latestVersion)
log.Println("You can find the download instructions here:", DonwloadInstructions)
}
33 changes: 1 addition & 32 deletions datasetUtils/checkForNewVersion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,6 @@ func TestFetchLatestVersion(t *testing.T) {
}
}

func TestGenerateDownloadURL(t *testing.T) {
deployLocation := "https://github.com/paulscherrerinstitute/scicat-cli/releases/download"
latestVersion := "0.1.0"

testCases := []struct {
osName string
expectedURL string
}{
{
osName: "Linux",
expectedURL: "https://github.com/paulscherrerinstitute/scicat-cli/releases/download/v0.1.0/scicat-cli_v0.1.0_Linux_x86_64.tar.gz",
},
{
osName: "Windows",
expectedURL: "https://github.com/paulscherrerinstitute/scicat-cli/releases/download/v0.1.0/scicat-cli_v0.1.0_Windows_x86_64.zip",
},
{
osName: "Darwin",
expectedURL: "https://github.com/paulscherrerinstitute/scicat-cli/releases/download/v0.1.0/scicat-cli_v0.1.0_Darwin_x86_64.tar.gz",
},
}

for _, testCase := range testCases {
actualURL := generateDownloadURL(deployLocation, latestVersion, testCase.osName)

if actualURL != testCase.expectedURL {
t.Errorf("Expected URL to be %s, but got %s", testCase.expectedURL, actualURL)
}
}
}

type MockUserInput struct {
Input string
}
Expand All @@ -87,7 +56,7 @@ func TestCheckForNewVersion(t *testing.T) {
name: "New version available, non-interactive mode",
currentVersion: "0.9.0",
mockResponse: `{"tag_name": "v1.0.0"}`,
expectedLog: "You should upgrade to a newer version",
expectedLog: "You can find the download instructions here: https://github.com/paulscherrerinstitute/scicat-cli?tab=readme-ov-file#manual-deployment",
},
{
name: "No new version available, non-interactive mode",
Expand Down

0 comments on commit 93395d0

Please sign in to comment.