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"
|
2023-02-03 03:20:24 +00:00
|
|
|
"strings"
|
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
|
2022-06-03 06:28:14 +00:00
|
|
|
version := commons.LoadVersion()
|
2022-04-15 16:53:37 +00:00
|
|
|
// get target
|
|
|
|
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)
|
|
|
|
}
|
2022-05-18 03:49:21 +00:00
|
|
|
// get target
|
|
|
|
flutterVersion := os.Getenv("flutter_version")
|
|
|
|
if target == "" {
|
|
|
|
println("Env ${flutter_version} is not set")
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2022-04-15 16:53:37 +00:00
|
|
|
//
|
|
|
|
var releaseFileName string
|
|
|
|
switch target {
|
|
|
|
case "macos":
|
2023-02-03 03:20:24 +00:00
|
|
|
releaseFileName = fmt.Sprintf("pikapika-%v-macos-intel.dmg", version.Code)
|
2022-04-15 16:53:37 +00:00
|
|
|
case "ios":
|
2023-02-03 03:20:24 +00:00
|
|
|
releaseFileName = fmt.Sprintf("pikapika-%v-ios-nosign.ipa", version.Code)
|
2022-04-15 16:53:37 +00:00
|
|
|
case "windows":
|
2023-02-03 03:20:24 +00:00
|
|
|
releaseFileName = fmt.Sprintf("pikapika-%v-windows-x86_64.zip", version.Code)
|
2022-04-15 16:53:37 +00:00
|
|
|
case "linux":
|
2023-02-03 03:20:24 +00:00
|
|
|
releaseFileName = fmt.Sprintf("pikapika-%v-linux-x86_64.AppImage", version.Code)
|
2022-04-15 16:53:37 +00:00
|
|
|
case "android-arm32":
|
2023-02-03 03:20:24 +00:00
|
|
|
releaseFileName = fmt.Sprintf("pikapika-%v-android-arm32.apk", version.Code)
|
2022-04-15 16:53:37 +00:00
|
|
|
case "android-arm64":
|
2023-02-03 03:20:24 +00:00
|
|
|
releaseFileName = fmt.Sprintf("pikapika-%v-android-arm64.apk", version.Code)
|
2022-04-15 16:53:37 +00:00
|
|
|
case "android-x86_64":
|
2023-02-03 03:20:24 +00:00
|
|
|
releaseFileName = fmt.Sprintf("pikapika-%v-android-x86_64.apk", version.Code)
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(flutterVersion, "2.") {
|
|
|
|
releaseFileName = "z-of-" + releaseFileName
|
2022-04-15 16:53:37 +00:00
|
|
|
}
|
|
|
|
// get version
|
|
|
|
getReleaseRequest, err := http.NewRequest(
|
|
|
|
"GET",
|
2022-06-03 06:28:14 +00:00
|
|
|
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)
|
|
|
|
}
|
2022-06-03 06:28:14 +00:00
|
|
|
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
|
|
|
}
|