From 28bf70d0a9e20856d06372129f44e6aa86d5acea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=91=A8=E8=B5=B5=E5=98=89=E7=A8=8B521432910016?=
 <zzjc123@sjtu.edu.cn>
Date: Tue, 1 Oct 2024 23:30:07 +0800
Subject: [PATCH] fix: release check (#44)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: zzjc1234 <2359047351@qq.com>
Reviewed-on: https://focs.ji.sjtu.edu.cn/git/JOJ/JOJ3/pulls/44
Reviewed-by: 张泊明518370910136 <bomingzh@sjtu.edu.cn>
Co-authored-by: 周赵嘉程521432910016 <zzjc123@sjtu.edu.cn>
Co-committed-by: 周赵嘉程521432910016 <zzjc123@sjtu.edu.cn>
---
 cmd/healthcheck/main.go | 4 +---
 pkg/healthcheck/tag.go  | 6 +++++-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/cmd/healthcheck/main.go b/cmd/healthcheck/main.go
index ca09048..97f9515 100644
--- a/cmd/healthcheck/main.go
+++ b/cmd/healthcheck/main.go
@@ -39,7 +39,7 @@ var Version string
 
 // Generally, err is used for runtime errors, and checkRes is used for the result of the checks.
 func main() {
-	var gitWhitelist, metaFile, releaseTags []string
+	var gitWhitelist, metaFile []string
 	showVersion := flag.Bool("version", false, "print current version")
 	rootDir := flag.String("root", "", "")
 	repo := flag.String("repo", "", "")
@@ -51,7 +51,6 @@ func main() {
 	checkFileSumList := flag.String("checkFileSumList", "", "Comma-separated list of expected checksums.")
 	parseMultiValueFlag(&gitWhitelist, "whitelist", "")
 	parseMultiValueFlag(&metaFile, "meta", "")
-	parseMultiValueFlag(&releaseTags, "releaseTags", "")
 	flag.Parse()
 	if *showVersion {
 		fmt.Println(Version)
@@ -83,7 +82,6 @@ func main() {
 	if err != nil {
 		fmt.Printf("## Release Tag Check Failed:\n%s\n", err.Error())
 	}
-	// FIXME: for drone usage
 	err = healthcheck.VerifyFiles(*rootDir, *checkFileNameList, *checkFileSumList)
 	if err != nil {
 		fmt.Printf("## Repo File Check Failed:\n%s\n", err.Error())
diff --git a/pkg/healthcheck/tag.go b/pkg/healthcheck/tag.go
index d0f7f76..80c343f 100644
--- a/pkg/healthcheck/tag.go
+++ b/pkg/healthcheck/tag.go
@@ -32,6 +32,10 @@ func getTagsFromRepo(repoPath string) ([]string, error) {
 }
 
 func CheckTags(repoPath string, category string, n int) error {
+	// INFO: if category not specified, skipping this check by default
+	if category == "" {
+		return nil
+	}
 	tags, err := getTagsFromRepo(repoPath)
 	if err != nil {
 		return fmt.Errorf("error getting tags: %v", err)
@@ -56,7 +60,7 @@ func CheckTags(repoPath string, category string, n int) error {
 		}
 	}
 	if !found {
-		return fmt.Errorf("Wrong release tag '%s' or missing release tags. Please use one of '%s'.", target, strings.Join(tags, "', '"))
+		return fmt.Errorf("Wrong release tag '%s' or missing release tags. Please use one of '%s'.", strings.Join(tags, "', '"), target)
 	}
 	return nil
 }