Commit fcc2094e authored by Addshore's avatar Addshore 🏄
Browse files

Switch update code to only use Gitlab

parent f8b31fb0
......@@ -8,6 +8,17 @@ Each tagged release MUST have a section 2 heading starting at the time of releas
- ...
## v0.2.0
This is the second release built by CI on Gitlab, but the first that will be served to users.
From this point forward users will automatiacly update from Gitlab releases.
- Added verbose flags to the `version` and `update` commands.
- Changed default output of the `version` command.
- Changed default output of the `update` command when no update is availible, making the output more useful.
- Removed `update_channel` from the configuration, the only update channel is now Gitlab.
## v0.1.0-dev.20210920.1
There are no functionality changes in this release compared to `v0.1.0-dev-addshore.20210916.1`.
......
......@@ -25,10 +25,10 @@ get-dev:
build:
@echo "Building $(GOFILES) to ./bin"
GOPATH=$(GOPATH) GOBIN=$(GOBIN) go build -v -ldflags "$(shell ./bin/govvv -flags)" -o bin/mw ./
GOPATH=$(GOPATH) GOBIN=$(GOBIN) go build -v -ldflags "$(shell ./bin/govvv -flags -version $(SEMVER))" -o bin/mw ./
release:
GOPATH=$(GOPATH) GOBIN=$(GOBIN) ./bin/gox -output="$(RELEASE_DIR)/$(SEMVER)/mw_$(VERSION)_{{.OS}}_{{.Arch}}" -osarch='$(TARGETS)' -ldflags '$(shell ./bin/govvv -flags)' $(GO_PACKAGES)
GOPATH=$(GOPATH) GOBIN=$(GOBIN) ./bin/gox -output="$(RELEASE_DIR)/$(SEMVER)/mw_$(VERSION)_{{.OS}}_{{.Arch}}" -osarch='$(TARGETS)' -ldflags '$(shell ./bin/govvv -flags -version $(SEMVER))' $(GO_PACKAGES)
cp LICENSE "$(RELEASE_DIR)"
for f in "$(RELEASE_DIR)"/$(SEMVER)/mw_*; do \
shasum -a 256 "$${f}" | awk '{print $$1}' > "$${f}.sha256"; \
......
......@@ -88,15 +88,6 @@ func wizardDevMode() {
c.WriteToDisk()
}
func wizardUpdateChannel() {
c := config.LoadFromDisk()
fmt.Println("\nYou need to choose an update channel in order to continue:")
fmt.Println(" - '" + config.UpdateChannelDev + "' is the only current release channel, so will be set now.")
c.UpdateChannel = config.UpdateChannelDev
c.WriteToDisk()
}
/*Execute the root command*/
func Execute(GitCommitIn string, GitBranchIn string, GitStateIn string, GitSummaryIn string, BuildDateIn string, VersionIn string) {
GitCommit = GitCommitIn
......@@ -112,10 +103,6 @@ func Execute(GitCommitIn string, GitBranchIn string, GitStateIn string, GitSumma
wizardDevMode()
c = config.LoadFromDisk()
}
if !config.UpdateChannelValues.Contains(c.UpdateChannel) {
wizardUpdateChannel()
c = config.LoadFromDisk()
}
// mwdd mode
if c.DevMode == config.DevModeMwdd {
......
......@@ -20,7 +20,6 @@ import (
"fmt"
"os"
"gerrit.wikimedia.org/r/mediawiki/tools/cli/internal/config"
"gerrit.wikimedia.org/r/mediawiki/tools/cli/internal/updater"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
......@@ -30,9 +29,6 @@ var updateCmd = &cobra.Command{
Use: "update",
Short: "Checks for and performs updates",
Run: func(cmd *cobra.Command, args []string) {
c := config.LoadFromDisk()
fmt.Println("You are on the " + c.UpdateChannel + " channel.")
canUpdate, toUpdateToOrMessage := updater.CanUpdate(Version, GitSummary, Verbosity >= 2)
if !canUpdate {
......
......@@ -26,6 +26,10 @@ var versionCmd = &cobra.Command{
Use: "version",
Short: "Output the version information",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("mw version", Version, "(", BuildDate, ")")
fmt.Println("https://gitlab.wikimedia.org/releng/cli/-/releases")
if Verbosity > 1 {
fmt.Printf(`GitCommit: %s
GitBranch: %s
GitState: %s
......@@ -33,9 +37,11 @@ GitSummary: %s
BuildDate: %s
Version: %s
`, GitCommit, GitBranch, GitState, GitSummary, BuildDate, Version)
}
},
}
func init() {
versionCmd.PersistentFlags().IntVarP(&Verbosity, "verbosity", "v", 1, "verbosity level (1-2)")
rootCmd.AddCommand(versionCmd)
}
......@@ -17,7 +17,6 @@ require (
github.com/gorilla/mux v1.8.0 // indirect
github.com/joho/godotenv v1.3.0
github.com/manifoldco/promptui v0.7.0
github.com/mitchellh/gox v1.0.1 // indirect
github.com/moby/term v0.0.0-20201216013528-df9cb8a40635 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
......@@ -27,8 +26,8 @@ require (
github.com/spf13/cobra v1.0.0
github.com/stretchr/testify v1.6.1 // indirect
github.com/txn2/txeh v1.3.0
github.com/xanzy/go-gitlab v0.50.4
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b // indirect
gotest.tools/v3 v3.0.3 // indirect
)
......
......@@ -93,8 +93,12 @@ github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoA
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/hashicorp/go-version v1.0.0 h1:21MVWPKDphxa7ineQQTrCU5brh7OuVVAzGOCnnCPtE8=
github.com/hashicorp/go-version v1.0.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-retryablehttp v0.6.8 h1:92lWxgpa+fF3FozM4B3UZtHZMJX8T5XT+TFdCxsPyWs=
github.com/hashicorp/go-retryablehttp v0.6.8/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
......@@ -131,10 +135,6 @@ github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/gox v1.0.1 h1:x0jD3dcHk9a9xPSDN6YEL4xL6Qz0dvNYm8yZqui5chI=
github.com/mitchellh/gox v1.0.1/go.mod h1:ED6BioOGXMswlXa2zxfh/xdd5QhwYliBFn9V18Ap4z4=
github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY=
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/moby/term v0.0.0-20201216013528-df9cb8a40635 h1:rzf0wL0CHVc8CEsgyygG0Mn9CNCCPZqOPaz8RiiHYQk=
github.com/moby/term v0.0.0-20201216013528-df9cb8a40635/go.mod h1:FBS0z0QWA44HXygs7VXDUOGoN/1TV3RuWkLO04am3wc=
......@@ -208,6 +208,8 @@ github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGr
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/ulikunitz/xz v0.5.9 h1:RsKRIA2MO8x56wkkcd3LbtcE/uMszhb6DpRf+3uwa3I=
github.com/ulikunitz/xz v0.5.9/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/xanzy/go-gitlab v0.50.4 h1:DA0+D9eTBnZvrGBOQ66XV4ZV9gOFXKbbgm9L99EKCUs=
github.com/xanzy/go-gitlab v0.50.4/go.mod h1:Q+hQhV508bDPoBijv7YjK/Lvlb4PhVhJdKqXVQrUoAE=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
......@@ -218,6 +220,7 @@ golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnf
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
......@@ -231,8 +234,8 @@ golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190522155817-f3200d17e092 h1:4QSRKanuywn15aTZvI/mIDEgPQpswuFndXpOj3rKEco=
golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288 h1:JIqe8uIcRBHXDQVvZtHwp80ai3Lw3IJAeJEs55Dc1W0=
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
......@@ -240,6 +243,7 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
......@@ -250,18 +254,23 @@ golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a h1:i47hUS795cOydZI4AwJQCKXOr4BvxzvikwDoDtHhP2Y=
golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
......
......@@ -23,19 +23,9 @@ var DevModeValues = AllowedOptions([]string{DevModeMwdd})
/*DevModeMwdd value for DevMode that will use the docker/mediawiki-docker-dev command set*/
const DevModeMwdd string = "docker"
/*UpdateChannelValues allowed values for UpdateChannel*/
var UpdateChannelValues = AllowedOptions([]string{UpdateChannelDev, UpdateChannelStable})
/*UpdateChannelDev value for UpdateChannel that will pull updates from addshore's dev builds*/
const UpdateChannelDev string = "dev-addshore"
/*UpdateChannelStable value for UpdateChannel that will pull updates from wikimedia's stable builds*/
const UpdateChannelStable string = "stable-wikimedia"
/*Config representation of a cli config*/
type Config struct {
DevMode string `json:"dev_mode"`
UpdateChannel string `json:"update_channel"`
}
/*AllowedOptions representation of allowed options for a config value*/
......
......@@ -62,10 +62,10 @@ func LoadFromDisk() Config {
ensureExists()
var config Config
configFile, err := os.Open(configPath())
defer configFile.Close()
if err != nil {
fmt.Println(err.Error())
}
defer configFile.Close()
jsonParser := json.NewDecoder(configFile)
jsonParser.Decode(&config)
return config
......
[
{
"name": "Some Release Name",
"tag_name": "REL_TAG_NAME",
"assets": {
"count": 3,
"sources": [
{
"format": "zip",
"url": "someUrlOfSource"
}
],
"links": [
{
"id": 1,
"name": "mw_REL_TAG_NAME_firstOS_fakeArch",
"url": "someUrl1",
"direct_asset_url": "someDirectUrl1",
"external": true,
"link_type": "other"
},
{
"id": 2,
"name": "mw_REL_TAG_NAME_secondOS_fakeArch",
"url": "someUrl2",
"direct_asset_url": "someDirectUrl2",
"external": true,
"link_type": "other"
}
]
}
},
{
"name": "Fake second release we don't care about",
"description": "We don't care about this as the API default return has the latest release at the top"
}
]
\ No newline at end of file
/*Package gitlab in internal utils is functionality talking to gitlab
Copyright © 2020 Addshore
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gitlab
import (
"errors"
"fmt"
"runtime"
gitlab "github.com/xanzy/go-gitlab"
)
var wikimediav4ApiURL = "https://gitlab.wikimedia.org/api/v4/"
var os = runtime.GOOS
var arch = runtime.GOARCH
func wikimediaClient() *gitlab.Client {
git, err := gitlab.NewClient(
"",
gitlab.WithBaseURL(wikimediav4ApiURL),
)
if err != nil {
panic(err)
}
return git
}
/*RelengCliLatestRelease from gitlab*/
func RelengCliLatestRelease() (*gitlab.Release, error) {
// ID 16 in releng/mwcli
releases, response, err := wikimediaClient().Releases.ListReleases(16, nil)
if err != nil {
fmt.Println(response.Status)
fmt.Println(response.Body)
panic(err)
}
if len(releases) < 1 {
return nil, errors.New("this gitlab project has no releases")
}
return releases[0], nil
}
/*RelengCliLatestReleaseBinary from gitlab for this OS and ARCH*/
func RelengCliLatestReleaseBinary() (*gitlab.ReleaseLink, error) {
release, err := RelengCliLatestRelease()
if err != nil {
return nil, err
}
// Look for something like mw_v0.1.0-dev.20210920.1_linux_386
lookFor := "mw_" + release.TagName + "_" + os + "_" + arch
for _, link := range release.Assets.Links {
if link.Name == lookFor {
return link, nil
}
}
return nil, errors.New("no binary release found matching VERSION, OS and ARCH")
}
/*Package gitlab in internal utils is functionality talking to gitlab
Copyright © 2020 Addshore
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gitlab
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"reflect"
"testing"
gitlab "github.com/xanzy/go-gitlab"
)
func TestLatestReleaseBinary(t *testing.T) {
// Start a local HTTP server
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
// Test request parameters
if req.URL.Path == "/api/v4/projects/16/releases" {
b, err := ioutil.ReadFile("testdata/wikimedia_test_data.json")
if err != nil {
panic(err)
}
rw.Write(b)
}
}))
// Close the server when test finishes
defer server.Close()
// Override the URL with our test server
wikimediav4ApiURL = server.URL + "/api/v4/"
os = "fakeOS"
arch = "fakeArch"
tests := []struct {
name string
fakeOS string
want *gitlab.ReleaseLink
wantErr bool
}{
{
name: "valid, first link",
fakeOS: "firstOS",
want: &gitlab.ReleaseLink{
ID: 1,
Name: "mw_REL_TAG_NAME_firstOS_fakeArch",
URL: "someUrl1",
DirectAssetURL: "someDirectUrl1",
External: true,
LinkType: "other",
},
},
{
name: "valid, second link",
fakeOS: "secondOS",
want: &gitlab.ReleaseLink{
ID: 2,
Name: "mw_REL_TAG_NAME_secondOS_fakeArch",
URL: "someUrl2",
DirectAssetURL: "someDirectUrl2",
External: true,
LinkType: "other",
},
},
{
name: "invalid",
fakeOS: "thirdOS",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
os = tt.fakeOS
got, err := RelengCliLatestReleaseBinary()
if (err != nil) != tt.wantErr {
t.Errorf("LatestReleaseBinary() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("LatestReleaseBinary() = %v, want %v", got, tt.want)
}
})
}
}
/*Package updater is used to update the cli
Copyright © 2020 Addshore
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package updater
import (
"fmt"
"log"
"os"
"strings"
"github.com/blang/semver"
"github.com/rhysd/go-github-selfupdate/selfupdate"
)
/*CanUpdateFromAddshore ...*/
func CanUpdateFromAddshore(currentVersion string, gitSummary string, verboseOutput bool) (bool, *selfupdate.Release) {
if verboseOutput {
selfupdate.EnableLog()
}
// TODO when builds are on wm.o then allow for a "dev" or "stable" update option and checks
v, err := semver.Parse(strings.Trim(gitSummary, "v"))
if err != nil {
if verboseOutput {
log.Println("Could not parse git summary version, maybe you are not using a real release?")
}
return false, nil
}
rel, ok, err := selfupdate.DetectLatest("addshore/mwcli")
if err != nil {
if verboseOutput {
log.Println("Some unknown error occurred")
}
return false, rel
}
if !ok {
if verboseOutput {
log.Println("No release detected. Current version is considered up-to-date")
}
return false, rel
}
if v.Equals(rel.Version) {
if verboseOutput {
log.Println("Current version", v, "is the latest. Update is not needed")
}
return false, rel
}
if verboseOutput {
log.Println("Update available", rel.Version)
}
return true, rel
}
/*UpdateFromAddshoreTo ...*/
func UpdateFromAddshoreTo(release selfupdate.Release, verboseOutput bool) (success bool, message string) {
if verboseOutput {
selfupdate.EnableLog()
}
cmdPath, err := os.Executable()
if err != nil {
return false, "Failed to grab local executable location"
}
err = selfupdate.UpdateTo(release.AssetURL, cmdPath)
if err != nil {
return false, "Binary update failed" + err.Error()
}
return true, "successfuly updated to version" + release.Version.String() + "\nRelease note:\n" + release.ReleaseNotes
}
/*UpdateFromAddshore ...*/
func UpdateFromAddshore(currentVersion string, gitSummary string, verboseOutput bool) (success bool, message string) {
canUpdate, nextRelease := CanUpdateFromAddshore(currentVersion, gitSummary, verboseOutput)
if !canUpdate || nextRelease == nil {
return false, "Nothing to update to"
}
updateSuccess, updateMessage := UpdateFromAddshoreTo(*nextRelease, verboseOutput)
if !updateSuccess {
fmt.Println(updateMessage)
os.Exit(1)
}
return updateSuccess, updateMessage
}
......@@ -18,87 +18,73 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package updater
import (
"io/ioutil"
"net/http"
"os"
"runtime"
"strings"
"gerrit.wikimedia.org/r/mediawiki/tools/cli/internal/gitlab"
"github.com/blang/semver"
"github.com/rhysd/go-github-selfupdate/selfupdate"
)
/*CanUpdateFromWikimedia ...*/
func CanUpdateFromWikimedia(currentVersion string, gitSummary string, verboseOutput bool) (bool, string) {
/*CanUpdateFromGitlab ...*/
func CanUpdateFromGitlab(version string, gitSummary string, verboseOutput bool) (bool, string) {
if verboseOutput {
selfupdate.EnableLog()
}
latestRelease := latestWikimediaRelease()
if latestRelease == "404" {
return false, "No Wikimedia releases yet"
}
latestRelease := latestGitlabRelease()
newVersion, newErr := semver.Parse(strings.Trim(latestRelease, "v"))
currentVerion, currentErr := semver.Parse(strings.Trim(gitSummary, "v"))
currentVerion, currentErr := semver.Parse(strings.Trim(version, "v"))
if newErr != nil {
return false, "Could not remote release version?"
return false, "Could not parse latest release version from Gitlab"
}
if currentErr != nil {
return false, "Could not parse current git summary version '" + gitSummary + "', maybe you are not using a real release? Next release would be " + newVersion.String()
return false, "Could not parse current version '" + version + "'. Next release would be " + newVersion.String()
}
return currentVerion.Compare(newVersion) == -1, newVersion.String()
}
func latestWikimediaRelease() string {
url := "https://releases.wikimedia.org/mwcli/latest.txt"
client := http.Client{}
resp, err := client.Get(url)