Skip to content

Commit 04e45e7

Browse files
authored
Merge pull request #2302 from lizardruss/v5
fix: update asset download urls
2 parents 025444a + 294d413 commit 04e45e7

File tree

11 files changed

+69
-72
lines changed

11 files changed

+69
-72
lines changed

.github/workflows/docs.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ name: Documentation
33
on:
44
push:
55
branches:
6-
- master
6+
- v5
77
paths:
88
- "docs/**"
99
- ".github/workflows/docs.yaml"
1010
pull_request:
1111
branches:
12-
- master
12+
- v5
1313
paths:
1414
- "docs/**"
1515
- ".github/workflows/docs.yaml"

.github/workflows/e2e-tests.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
types: [created]
66
pull_request:
77
branches:
8-
- master
8+
- v5
99
paths:
1010
- "Dockerfile"
1111
- "**.go"

.github/workflows/lint.yaml

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
types: [created]
66
pull_request:
77
branches:
8-
- master
8+
- v5
99
paths:
1010
- "**.go"
1111
- ".github/workflows/lint.yaml"
@@ -16,11 +16,13 @@ jobs:
1616
name: lint
1717
runs-on: ubuntu-latest
1818
steps:
19-
- uses: actions/checkout@v2
20-
- name: golangci-lint
21-
uses: golangci/golangci-lint-action@v2
19+
- uses: actions/setup-go@v3
20+
with:
21+
go-version: 1.18
22+
- uses: actions/checkout@v3
23+
- name: Run golangci-lint
24+
uses: golangci/golangci-lint-action@v3.2.0
2225
with:
23-
version: v1.29
2426
args:
2527
-v
2628
--config=.golangci.yml

.github/workflows/npm.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Test NPM Installer
33
on:
44
pull_request:
55
branches:
6-
- master
6+
- v5
77
paths:
88
- "dist/npm/**"
99
- ".github/workflows/npm.yaml"

.github/workflows/release.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ on:
55
types: [created]
66
push:
77
branches:
8-
- master
8+
- v5
99
paths:
1010
- "Dockerfile"
1111
- "**.go"
1212
- "hack/coverage.bash"
1313
- ".github/workflows/release.yaml"
1414
pull_request:
1515
branches:
16-
- master
16+
- v5
1717
paths:
1818
- "Dockerfile"
1919
- "**.go"

.github/workflows/ui.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Test UI
33
on:
44
pull_request:
55
branches:
6-
- master
6+
- v5
77
paths:
88
- "ui/**"
99
- "hack/build-ui.bash"

.github/workflows/unit-tests.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
types: [created]
66
pull_request:
77
branches:
8-
- master
8+
- v5
99
paths:
1010
- "**.go"
1111
- "!e2e/**" # exclude files from e2e tests

dist/npm/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const inquirer = require('inquirer');
88
const findProcess = require('find-process');
99

1010
const downloadPathTemplate =
11-
"https://github.com/loft-sh/devspace/releases/download/{{version}}/devspace-{{platform}}-{{arch}}";
11+
"https://github.com/loft-sh/devspace/releases/download/v{{version}}/devspace-{{platform}}-{{arch}}";
1212
const ARCH_MAPPING = {
1313
ia32: "386",
1414
x64: "amd64",
@@ -460,4 +460,4 @@ if (process.ppid > 1) {
460460
})
461461
} else {
462462
continueProcess(true);
463-
}
463+
}

pkg/devspace/server/download.go

+10-26
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,27 @@ import (
66
"compress/gzip"
77
"fmt"
88
"io"
9-
"io/ioutil"
109
"net/http"
1110
"os"
1211
"path/filepath"
13-
"regexp"
1412
"strings"
1513
"time"
1614

1715
"github.com/loft-sh/devspace/assets"
1816

1917
"github.com/loft-sh/devspace/pkg/devspace/config/constants"
2018
"github.com/loft-sh/devspace/pkg/devspace/upgrade"
19+
"github.com/loft-sh/devspace/pkg/util/git"
2120

2221
homedir "github.com/mitchellh/go-homedir"
2322
"github.com/pkg/errors"
2423
)
2524

26-
// UIDownloadBaseURL is the base url where to look for the ui
27-
const UIDownloadBaseURL = "https://github.com/loft-sh/devspace/releases"
25+
// UIRepository is the repository containing the devspace UI
26+
const UIRepository = "https://github.com/loft-sh/devspace"
2827

29-
// UIDownloadRegEx is the regexp that finds the correct download link for the ui
30-
var UIDownloadRegEx = regexp.MustCompile(`href="(\/loft-sh\/devspace\/releases\/download\/[^\/]*\/ui.tar.gz)"`)
28+
// UIDownloadBaseURL is the base url where to look for the ui
29+
const UIDownloadBaseURL = UIRepository + "/releases/download"
3130

3231
// UITempFolder is the temp folder to cache the ui in
3332
const UITempFolder = "ui"
@@ -77,30 +76,15 @@ func downloadFile(version string, folder string) error {
7776
}
7877

7978
// Create download url
80-
url := ""
8179
if version == "latest" {
82-
url = fmt.Sprintf("%s/%s", UIDownloadBaseURL, version)
83-
} else {
84-
url = fmt.Sprintf("%s/tag/%s", UIDownloadBaseURL, version)
80+
version, err = git.GetLatestVersion(UIRepository)
81+
if err != nil {
82+
return errors.Wrap(err, "get latest version")
83+
}
8584
}
8685

87-
// Download html
86+
url := fmt.Sprintf("%s/%s/%s", UIDownloadBaseURL, version, "ui.tar.gz")
8887
resp, err := http.Get(url)
89-
if err != nil {
90-
return errors.Wrap(err, "get url")
91-
}
92-
93-
body, err := ioutil.ReadAll(resp.Body)
94-
if err != nil {
95-
return errors.Wrap(err, "read body")
96-
}
97-
98-
matches := UIDownloadRegEx.FindStringSubmatch(string(body))
99-
if len(matches) != 2 {
100-
return errors.Errorf("Couldn't find ui in github release %s at url %s", version, url)
101-
}
102-
103-
resp, err = http.Get("https://github.com" + matches[1])
10488
if err != nil {
10589
return errors.Wrap(err, "download ui archive")
10690
}

pkg/devspace/services/inject/inject.go

+12-31
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,38 @@ import (
55
"bytes"
66
"compress/gzip"
77
"fmt"
8-
"github.com/loft-sh/devspace/assets"
98
"io"
109
"io/fs"
1110
"io/ioutil"
1211
"net/http"
1312
"os"
1413
"path/filepath"
15-
"regexp"
1614
"strings"
1715
"sync"
1816
"time"
1917

18+
"github.com/loft-sh/devspace/assets"
2019
"github.com/loft-sh/devspace/pkg/devspace/config/constants"
2120
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
2221
"github.com/loft-sh/devspace/pkg/devspace/kubectl"
2322
"github.com/loft-sh/devspace/pkg/devspace/upgrade"
23+
"github.com/loft-sh/devspace/pkg/util/git"
2424
"github.com/loft-sh/devspace/pkg/util/hash"
2525
logpkg "github.com/loft-sh/devspace/pkg/util/log"
2626
"github.com/mitchellh/go-homedir"
2727
"github.com/pkg/errors"
2828
v1 "k8s.io/api/core/v1"
2929
)
3030

31+
// DevSpaceHelperRepository is the repository containing the devspace helper
32+
const DevSpaceHelperRepository = "https://github.com/loft-sh/devspace"
33+
3134
// DevSpaceHelperBaseURL is the base url where to look for the sync helper
32-
const DevSpaceHelperBaseURL = "https://github.com/loft-sh/devspace/releases"
35+
const DevSpaceHelperBaseURL = DevSpaceHelperRepository + "/releases/download"
3336

3437
// DevSpaceHelperTempFolder is the local folder where we store the sync helper
3538
const DevSpaceHelperTempFolder = "devspacehelper"
3639

37-
// helperBinaryRegEx is the regexp that finds the correct download link for the sync helper binary
38-
var helperBinaryRegEx = `href="(\/loft-sh\/devspace\/releases\/download\/[^\/]*\/%s)"`
39-
4040
// DevSpaceHelperContainerPath is the path of the devspace helper in the container
4141
const DevSpaceHelperContainerPath = "/tmp/devspacehelper"
4242

@@ -143,34 +143,15 @@ func installDevSpaceHelperInContainer(client kubectl.Client, pod *v1.Pod, contai
143143

144144
// getDownloadURL
145145
func devSpaceHelperDownloadURL(version, filename string) (string, error) {
146-
url := ""
147146
if version == "latest" {
148-
url = fmt.Sprintf("%s/%s", DevSpaceHelperBaseURL, version)
149-
} else {
150-
url = fmt.Sprintf("%s/tag/%s", DevSpaceHelperBaseURL, version)
151-
}
152-
153-
// Download html
154-
resp, err := http.Get(url)
155-
if err != nil {
156-
return "", errors.Wrap(err, "get url")
157-
}
158-
159-
body, err := ioutil.ReadAll(resp.Body)
160-
if err != nil {
161-
return "", errors.Wrap(err, "read body")
162-
}
163-
164-
regEx, err := regexp.Compile(fmt.Sprintf(helperBinaryRegEx, filename))
165-
if err != nil {
166-
return "", err
147+
var err error
148+
version, err = git.GetLatestVersion(DevSpaceHelperRepository)
149+
if err != nil {
150+
return "", errors.Wrap(err, "get latest version")
151+
}
167152
}
168153

169-
matches := regEx.FindStringSubmatch(string(body))
170-
if len(matches) != 2 {
171-
return "", errors.Errorf("couldn't find %s in github release %s at url %s", filename, version, url)
172-
}
173-
return "https://github.com" + matches[1], nil
154+
return fmt.Sprintf("%s/%s/%s", DevSpaceHelperBaseURL, version, filename), nil
174155
}
175156

176157
func downloadSyncHelper(helperName, syncBinaryFolder, version string, log logpkg.Logger) error {

pkg/util/git/helper.go

+30
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
package git
22

33
import (
4+
"fmt"
5+
"net/http"
46
"os"
57
"os/exec"
8+
"regexp"
69
"strings"
710

811
"github.com/pkg/errors"
912
"gopkg.in/src-d/go-git.v4"
1013
)
1114

15+
var LatestTagRegEx = regexp.MustCompile(`\/tag\/(.*)$`)
16+
1217
// GetBranch retrieves the current HEADs name
1318
func GetBranch(localPath string) (string, error) {
1419
repo, err := git.PlainOpen(localPath)
@@ -77,3 +82,28 @@ func GetRemote(localPath string) (string, error) {
7782

7883
return urls[0], nil
7984
}
85+
86+
func GetLatestVersion(repository string) (string, error) {
87+
client := &http.Client{
88+
CheckRedirect: func(req *http.Request, via []*http.Request) error {
89+
return http.ErrUseLastResponse
90+
},
91+
}
92+
93+
resp, err := client.Get(repository + "/releases/latest")
94+
if err != nil {
95+
return "", err
96+
}
97+
98+
redirect := resp.Header.Get("location")
99+
if redirect == "" {
100+
return "", fmt.Errorf("redirect URL not found")
101+
}
102+
103+
matches := LatestTagRegEx.FindStringSubmatch(redirect)
104+
if len(matches) != 2 {
105+
return "", errors.Errorf("Couldn't find latest release version")
106+
}
107+
108+
return matches[1], nil
109+
}

0 commit comments

Comments
 (0)