From 2d9f773fe967479e21a88c85bb6b27607e953fd1 Mon Sep 17 00:00:00 2001 From: googs1025 Date: Mon, 25 Mar 2024 19:34:24 +0800 Subject: [PATCH] ci: add ci.yaml --- .github/workflows/ci.yml | 10 +++++++++- hack/update-gofmt.sh | 5 +++++ hack/verify-gofmt.sh | 24 ++++++++++++++++++++++++ pkg/apis/daemonjob/v1alpha1/types.go | 9 ++++++--- pkg/apis/jobflow/v1alpha1/types.go | 11 +++++++++-- 5 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 hack/update-gofmt.sh create mode 100644 hack/verify-gofmt.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7dd4a06..bb96c08 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,5 +25,13 @@ jobs: with: go-version: ${{ env.GO_VERSION }} + - name: Run go fmt test + run: sudo hack/verify-gofmt.sh + env: + GO111MODULE: auto + - name: Run unit test - run: go test -v ./pkg/controller \ No newline at end of file + run: go test -v ./pkg/controller + + - name: Build the project + run: go build -v ./... \ No newline at end of file diff --git a/hack/update-gofmt.sh b/hack/update-gofmt.sh new file mode 100644 index 0000000..d5b0a2f --- /dev/null +++ b/hack/update-gofmt.sh @@ -0,0 +1,5 @@ +set -o nounset +set -o errexit +set -o pipefail + +find . -name "*.go" | grep -v vendor | xargs gofmt -s -w \ No newline at end of file diff --git a/hack/verify-gofmt.sh b/hack/verify-gofmt.sh new file mode 100644 index 0000000..d95d20f --- /dev/null +++ b/hack/verify-gofmt.sh @@ -0,0 +1,24 @@ +set -o errexit +set -o nounset +set -o pipefail + +HELM_ROOT=$(dirname "${BASH_SOURCE}")/.. +cd "${HELM_ROOT}" + +find_files() { + find . -not \( \ + \( \ + -wholename './output' \ + -o -wholename '*/vendor/*' \ + \) -prune \ + \) -name '*.go' +} + +GOFMT="gofmt -s" + +bad_files=$(find_files | xargs $GOFMT -l) +if [[ -n "${bad_files}" ]]; then + echo "Please run hack/update-gofmt.sh to fix the following files:" + echo "${bad_files}" + exit 1 +fi \ No newline at end of file diff --git a/pkg/apis/daemonjob/v1alpha1/types.go b/pkg/apis/daemonjob/v1alpha1/types.go index 2e8b60f..3c94023 100644 --- a/pkg/apis/daemonjob/v1alpha1/types.go +++ b/pkg/apis/daemonjob/v1alpha1/types.go @@ -21,9 +21,11 @@ type DaemonJob struct { } type DaemonJobSpec struct { - // GlobalParameters 全局参数 - GlobalParams GlobalParams `json:"globalParams,omitempty"` - ExcludeNodeList string `json:"excludeNodeList,omitempty"` + // GlobalParams 全局参数 + GlobalParams GlobalParams `json:"globalParams,omitempty"` + // ExcludeNodeList 过滤出不需运行的 node List, ex: 如果 node3 node4 不需要 + // 运行 DaemonJob ,则填入: "node3,node4" + ExcludeNodeList string `json:"excludeNodeList,omitempty"` v1.JobSpec } @@ -43,6 +45,7 @@ type DaemonJobStatus struct { // 用于存储 map 是 name/namespace 进行存储 JobStatusList map[string]v1.JobStatus `json:"jobStatusList,omitempty"` // 记录 JobFlow 状态 + // TODO: 使用特定类型封装 State string `json:"state,omitempty"` } diff --git a/pkg/apis/jobflow/v1alpha1/types.go b/pkg/apis/jobflow/v1alpha1/types.go index da7fe02..bc7d568 100644 --- a/pkg/apis/jobflow/v1alpha1/types.go +++ b/pkg/apis/jobflow/v1alpha1/types.go @@ -44,8 +44,12 @@ type GlobalParams struct { type ErrorHandler struct { // 用于赋值 job 模版 corev1.PodSpec - + // JobTemplate 用于赋值 job 模版 JobTemplate v1.JobSpec `json:"jobTemplate,omitempty"` + // JobTemplateRef 模版实例对象 JobTemplate + // 如果 JobTemplateRef 不为空,会优先使用此对象, + // 自动忽略 JobTemplate 字段内容 + JobTemplateRef string `json:"jobTemplateRef,omitempty"` // 支持脚本命令 Script string `json:"script,omitempty"` } @@ -56,9 +60,11 @@ type Flow struct { // JobTemplate 用于赋值 job 模版 JobTemplate v1.JobSpec `json:"jobTemplate,omitempty"` // JobTemplateRef 模版实例对象 JobTemplate + // 如果 JobTemplateRef 不为空,会优先使用此对象, + // 自动忽略 JobTemplate 字段内容 JobTemplateRef string `json:"jobTemplateRef,omitempty"` // Dependencies 依赖项,其中可以填写多个 依赖的 job name - // ex: 如果 job3 依赖 job1 and job2, 就能 + // ex: 如果 job3 依赖 job1 and job2, 就在列表中放入 ["job1", "job2"] Dependencies []string `json:"dependencies"` } @@ -66,6 +72,7 @@ type JobFlowStatus struct { // 用于存储 map 是 name/namespace 进行存储 JobStatusList map[string]v1.JobStatus `json:"jobStatusList,omitempty"` // 记录 JobFlow 状态 + // TODO: 使用特定类型封装 State string `json:"state,omitempty"` }