pikapika/ci/cmd/check_asset/main.go

78 lines
1.7 KiB
Go
Raw Normal View History

2022-03-22 09:12:48 +00:00
package main
import (
2022-04-15 16:53:37 +00:00
"ci/commons"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
2022-03-22 09:12:48 +00:00
)
func main() {
2022-04-15 16:53:37 +00:00
// get ghToken
ghToken := os.Getenv("GH_TOKEN")
if ghToken == "" {
println("Env ${GH_TOKEN} is not set")
os.Exit(1)
}
// get version
version := commons.LoadVersion()
2023-07-07 06:27:02 +00:00
// get TARGET
2022-04-15 16:53:37 +00:00
target := os.Getenv("TARGET")
2022-05-18 03:49:21 +00:00
if target == "" {
2022-04-15 16:53:37 +00:00
println("Env ${TARGET} is not set")
os.Exit(1)
}
2023-07-07 06:27:02 +00:00
// get FLUTTER_VERSION
flutterVersion := os.Getenv("FLUTTER_VERSION")
2022-05-18 03:49:21 +00:00
if target == "" {
2023-07-07 06:27:02 +00:00
println("Env ${FLUTTER_VERSION} is not set")
2022-05-18 03:49:21 +00:00
os.Exit(1)
}
2023-07-07 06:27:02 +00:00
// get BRANCH
branch := os.Getenv("BRANCH")
if target == "" {
println("Env ${BRANCH} is not set")
os.Exit(1)
2022-04-15 16:53:37 +00:00
}
2023-07-07 06:27:02 +00:00
//
var releaseFileName = commons.AssetName(version, flutterVersion, target, branch)
2022-04-15 16:53:37 +00:00
// get version
getReleaseRequest, err := http.NewRequest(
"GET",
fmt.Sprintf("https://api.github.com/repos/%v/%v/releases/tags/%v", commons.Owner, commons.Repo, version.Code),
2022-04-15 16:53:37 +00:00
nil,
)
if err != nil {
panic(err)
}
getReleaseRequest.Header.Set("User-Agent", commons.Ua)
2022-04-15 16:53:37 +00:00
getReleaseRequest.Header.Set("Authorization", "token "+ghToken)
getReleaseResponse, err := http.DefaultClient.Do(getReleaseRequest)
if err != nil {
panic(err)
}
defer getReleaseResponse.Body.Close()
if getReleaseResponse.StatusCode == 404 {
panic("NOT FOUND RELEASE")
}
buff, err := ioutil.ReadAll(getReleaseResponse.Body)
if err != nil {
panic(err)
}
var release commons.Release
err = json.Unmarshal(buff, &release)
if err != nil {
println(string(buff))
panic(err)
}
for _, asset := range release.Assets {
if asset.Name == releaseFileName {
println("::set-output name=skip_build::true")
os.Exit(0)
}
}
print("::set-output name=skip_build::false")
2022-03-22 09:12:48 +00:00
}