| 1 | /* |
| 2 | Copyright 2022 The Kubernetes Authors. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package magescip-go gomod sigs.k8s.io/release-utils . `sigs.k8s.io/release-utils/mage`/ |
| 18 | |
| 19 | import ( |
| 20 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 21 | "logscip-go gomod github.com/golang/go/src go1.24.0 log/" |
| 22 | "runtimescip-go gomod github.com/golang/go/src go1.24.0 runtime/" |
| 23 | |
| 24 | "github.com/uwu-tools/magex/pkgscip-go gomod github.com/uwu-tools/magex v0.10.1 `github.com/uwu-tools/magex/pkg`/" |
| 25 | "github.com/uwu-tools/magex/pkg/downloadsscip-go gomod github.com/uwu-tools/magex v0.10.1 `github.com/uwu-tools/magex/pkg/downloads`/" |
| 26 | ) |
| 27 | |
| 28 | const defaultCosignVersionscip-go gomod sigs.k8s.io/release-utils . `sigs.k8s.io/release-utils/mage`/defaultCosignVersion. = "v2.6.0" |
| 29 | |
| 30 | // EnsureCosign makes sure that the specified cosign version is available. |
| 31 | func EnsureCosignscip-go gomod sigs.k8s.io/release-utils . `sigs.k8s.io/release-utils/mage`/EnsureCosign().(version string) error { |
| 32 | if version == "" { |
| 33 | version = defaultCosignVersionscip-go gomod sigs.k8s.io/release-utils . `sigs.k8s.io/release-utils/mage`/defaultCosignVersion. |
| 34 | } |
| 35 | |
| 36 | logscip-go gomod github.com/golang/go/src go1.24.0 log/.Printfscip-go gomod github.com/golang/go/src go1.24.0 log/Printf().("Checking if `cosign` version %s is installed\n", version) |
| 37 | |
| 38 | found, err := pkgscip-go gomod github.com/uwu-tools/magex v0.10.1 `github.com/uwu-tools/magex/pkg`/.IsCommandAvailablescip-go gomod github.com/uwu-tools/magex v0.10.1 `github.com/uwu-tools/magex/pkg`/IsCommandAvailable().("cosign", "version", version) |
| 39 | if err != nil { |
| 40 | return err |
| 41 | } |
| 42 | |
| 43 | if !found { |
| 44 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.24.0 fmt/Println().("`cosign` not found") |
| 45 | |
| 46 | return InstallCosignscip-go gomod sigs.k8s.io/release-utils . `sigs.k8s.io/release-utils/mage`/InstallCosign().(version) |
| 47 | } |
| 48 | |
| 49 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.24.0 fmt/Println().("`cosign` is installed!") |
| 50 | |
| 51 | return nil |
| 52 | } |
| 53 | |
| 54 | // InstallCosign installs the required cosign version. |
| 55 | func InstallCosignscip-go gomod sigs.k8s.io/release-utils . `sigs.k8s.io/release-utils/mage`/InstallCosign().(version string) error { |
| 56 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.24.0 fmt/Println().("Will install `cosign`") |
| 57 | |
| 58 | target := "cosign" |
| 59 | if runtimescip-go gomod github.com/golang/go/src go1.24.0 runtime/.GOOSscip-go gomod github.com/golang/go/src go1.24.0 runtime/GOOS. == "windows" { |
| 60 | target = "cosign.exe" |
| 61 | } |
| 62 | |
| 63 | opts := downloadsscip-go gomod github.com/uwu-tools/magex v0.10.1 `github.com/uwu-tools/magex/pkg/downloads`/.DownloadOptionsscip-go gomod github.com/uwu-tools/magex v0.10.1 `github.com/uwu-tools/magex/pkg/downloads`/DownloadOptions#{ |
| 64 | UrlTemplatescip-go gomod github.com/uwu-tools/magex v0.10.1 `github.com/uwu-tools/magex/pkg/downloads`/DownloadOptions#UrlTemplate.: "https://github.com/sigstore/cosign/releases/download/{{.VERSION}}/cosign-{{.GOOS}}-{{.GOARCH}}", |
| 65 | Namescip-go gomod github.com/uwu-tools/magex v0.10.1 `github.com/uwu-tools/magex/pkg/downloads`/DownloadOptions#Name.: target, |
| 66 | Versionscip-go gomod github.com/uwu-tools/magex v0.10.1 `github.com/uwu-tools/magex/pkg/downloads`/DownloadOptions#Version.: version, |
| 67 | Extscip-go gomod github.com/uwu-tools/magex v0.10.1 `github.com/uwu-tools/magex/pkg/downloads`/DownloadOptions#Ext.: "", |
| 68 | } |
| 69 | |
| 70 | return downloadsscip-go gomod github.com/uwu-tools/magex v0.10.1 `github.com/uwu-tools/magex/pkg/downloads`/.DownloadToGopathBinscip-go gomod github.com/uwu-tools/magex v0.10.1 `github.com/uwu-tools/magex/pkg/downloads`/DownloadToGopathBin().(opts) |
| 71 | } |