Skip to content

Commit 4db6595

Browse files
authored
chore: refactor pre-commit workflow to correctly detect new lint issues (#12302)
Signed-off-by: kaikaila <[email protected]>
1 parent 844b40b commit 4db6595

26 files changed

+293
-291
lines changed

.github/workflows/pre-commit.yml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,22 @@ jobs:
1212
pre-commit:
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v5
16-
- uses: actions/setup-python@v3
17-
- uses: actions/setup-go@v5
18-
with:
19-
go-version-file: go.mod
20-
- name: golangci-lint
21-
uses: golangci/golangci-lint-action@v8
22-
with:
23-
version: v2.3
24-
args: --new-from-rev HEAD
15+
- uses: actions/checkout@v5
16+
with:
17+
fetch-depth: 0
18+
- name: Fetch base branch
19+
run: git fetch origin ${{ github.base_ref || github.ref_name }}
20+
- uses: actions/setup-python@v3
21+
- uses: actions/setup-go@v5
22+
with:
23+
go-version-file: go.mod
24+
- name: golangci-lint
25+
uses: golangci/golangci-lint-action@v8
26+
with:
27+
version: v2.3
28+
args: --new --whole-files --new-from-merge-base=origin/${{ github.base_ref || github.ref_name }}
2529
#- uses: pre-commit/[email protected]
26-
# # This is set to only run the golangci-lint pre-commit hooks
30+
# # This is set to only run the golangci-lint pre-commit hooks
2731
# # Remove in a later PR to run all hooks
2832
# with:
2933
# go-version: '>=1.24.2'

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ repos:
1818
- repo: https://github.com/PyCQA/flake8
1919
rev: 7.1.1
2020
hooks:
21-
- id: flake8
21+
- id: flake8
2222
args:
23-
- --select=W605
23+
- --select=W605
2424
# required formatting jobs (run these last)
2525

2626
# add comment "noqa" to ignore an import that should not be removed
@@ -60,7 +60,7 @@ repos:
6060
- id: golangci-lint
6161
name: golangci-lint
6262
description: Fast linters runner for Go.
63-
entry: golangci-lint run --new-from-rev HEAD --fix
63+
entry: golangci-lint run --new-from-rev HEAD --fix --whole-files
6464
types: [go]
6565
language: golang
6666
require_serial: true

backend/test/compiler/argo_ginkgo_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
workflowutils "github.com/kubeflow/pipelines/backend/test/compiler/utils"
2727
. "github.com/kubeflow/pipelines/backend/test/constants"
2828
"github.com/kubeflow/pipelines/backend/test/logger"
29-
"github.com/kubeflow/pipelines/backend/test/test_utils"
29+
"github.com/kubeflow/pipelines/backend/test/testutil"
3030

3131
. "github.com/onsi/ginkgo/v2"
3232
. "github.com/onsi/gomega"
@@ -38,7 +38,7 @@ var _ = BeforeEach(func() {
3838
})
3939

4040
var _ = Describe("Verify Spec Compilation to Workflow >", Label(POSITIVE, WORKFLOW_COMPILER), func() {
41-
pipelineFilePaths := test_utils.GetListOfAllFilesInDir(filepath.Join(pipelineFilesRootDir, pipelineDirectory))
41+
pipelineFilePaths := testutil.GetListOfAllFilesInDir(filepath.Join(pipelineFilesRootDir, pipelineDirectory))
4242

4343
testParams := []struct {
4444
compilerOptions argocompiler.Options
@@ -68,7 +68,7 @@ var _ = Describe("Verify Spec Compilation to Workflow >", Label(POSITIVE, WORKFL
6868
compiledWorkflowFileName := fileNameWithoutExtension + ".yaml"
6969
compiledWorkflowFilePath := filepath.Join(argoYAMLDir, compiledWorkflowFileName)
7070
It(fmt.Sprintf("When I compile %s pipeline spec, then the compiled yaml should be %s", pipelineSpecFileName, compiledWorkflowFileName), func() {
71-
test_utils.CheckIfSkipping(pipelineSpecFileName)
71+
testutil.CheckIfSkipping(pipelineSpecFileName)
7272
pipelineSpecs, platformSpec := workflowutils.LoadPipelineSpecsFromIR(pipelineSpecFilePath, param.compilerOptions.CacheDisabled, nil)
7373
compiledWorkflow := workflowutils.GetCompiledArgoWorkflow(pipelineSpecs, platformSpec, &param.compilerOptions)
7474
if *createMissingGoldenFiles || *updateGoldenFiles {

backend/test/compiler/compiler_suite_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ import (
2424
"testing"
2525

2626
"github.com/kubeflow/pipelines/backend/test/logger"
27-
"github.com/kubeflow/pipelines/backend/test/test_utils"
27+
"github.com/kubeflow/pipelines/backend/test/testutil"
2828

2929
. "github.com/onsi/ginkgo/v2"
3030
"github.com/onsi/ginkgo/v2/types"
3131
. "github.com/onsi/gomega"
3232
)
3333

34-
var pipelineFilesRootDir = test_utils.GetPipelineFilesDir()
34+
var pipelineFilesRootDir = testutil.GetPipelineFilesDir()
3535
var pipelineDirectory = "valid"
36-
var argoYAMLDir = filepath.Join(test_utils.GetTestDataDir(), "compiled-workflows")
36+
var argoYAMLDir = filepath.Join(testutil.GetTestDataDir(), "compiled-workflows")
3737
var updateGoldenFiles = flag.Bool("updateCompiledFiles", false, "update golden/expected compiled workflow files")
3838
var createMissingGoldenFiles = flag.Bool("createGoldenFiles", true, "create missing golden/expected compiled workflow files")
3939

@@ -60,7 +60,7 @@ var _ = ReportAfterEach(func(specReport types.SpecReport) {
6060
Expect(err).NotTo(HaveOccurred(), "Failed to get current directory")
6161
testName := GinkgoT().Name()
6262
testNameSplit := strings.Split(testName, ">")
63-
test_utils.WriteLogFile(specReport, testNameSplit[len(testNameSplit)-1], filepath.Join(currentDir, testLogsDirectory))
63+
testutil.WriteLogFile(specReport, testNameSplit[len(testNameSplit)-1], filepath.Join(currentDir, testLogsDirectory))
6464
} else {
6565
log.Printf("Test passed")
6666
}

backend/test/compiler/compiler_visitor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"github.com/kubeflow/pipelines/backend/src/v2/compiler"
2525
workflowutils "github.com/kubeflow/pipelines/backend/test/compiler/utils"
2626
. "github.com/kubeflow/pipelines/backend/test/constants"
27-
"github.com/kubeflow/pipelines/backend/test/test_utils"
27+
"github.com/kubeflow/pipelines/backend/test/testutil"
2828

2929
. "github.com/onsi/ginkgo/v2"
3030
. "github.com/onsi/gomega"
@@ -116,7 +116,7 @@ var _ = Describe("Verify iteration over the pipeline components >", Label(POSITI
116116
},
117117
}
118118
for _, testParam := range testParams {
119-
pipelineSpecFilePath := filepath.Join(test_utils.GetValidPipelineFilesDir(), testParam.pipelineSpecPath)
119+
pipelineSpecFilePath := filepath.Join(testutil.GetValidPipelineFilesDir(), testParam.pipelineSpecPath)
120120
It(fmt.Sprintf("Load the the pipeline IR yaml %s, and verify the visited component", testParam.pipelineSpecPath), func() {
121121
pipelineJob, platformSpec := workflowutils.LoadPipelineSpecsFromIR(pipelineSpecFilePath, false, nil)
122122

backend/test/compiler/utils/workflow_utils.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ import (
2828
"github.com/kubeflow/pipelines/api/v2alpha1/go/pipelinespec"
2929
"github.com/kubeflow/pipelines/backend/src/v2/compiler/argocompiler"
3030
"github.com/kubeflow/pipelines/backend/test/logger"
31-
"github.com/kubeflow/pipelines/backend/test/test_utils"
32-
utils "github.com/kubeflow/pipelines/backend/test/test_utils"
31+
"github.com/kubeflow/pipelines/backend/test/testutil"
3332

3433
"github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
3534
"github.com/onsi/ginkgo/v2"
@@ -39,7 +38,7 @@ import (
3938

4039
// LoadPipelineSpecsFromIR - Unmarshall Pipeline Spec IR into a tuple of (pipelinespec.PipelineJob, pipelinespec.SinglePlatformSpec)
4140
func LoadPipelineSpecsFromIR(pipelineIRFilePath string, cacheDisabled bool, defaultWorkspace *v1.PersistentVolumeClaimSpec) (*pipelinespec.PipelineJob, *pipelinespec.SinglePlatformSpec) {
42-
pipelineSpecsFromFile := utils.ParseFileToSpecs(pipelineIRFilePath, cacheDisabled, defaultWorkspace)
41+
pipelineSpecsFromFile := testutil.ParseFileToSpecs(pipelineIRFilePath, cacheDisabled, defaultWorkspace)
4342
platformSpec := pipelineSpecsFromFile.PlatformSpec()
4443
var singlePlatformSpec *pipelinespec.SinglePlatformSpec = nil
4544
if platformSpec != nil {
@@ -49,6 +48,7 @@ func LoadPipelineSpecsFromIR(pipelineIRFilePath string, cacheDisabled bool, defa
4948
pipelineSpecBytes, marshallingError := protojson.Marshal(pipelineSpecsFromFile.PipelineSpec())
5049
gomega.Expect(marshallingError).NotTo(gomega.HaveOccurred(), "Failed to marshall pipeline spec")
5150
err := json.Unmarshal(pipelineSpecBytes, &pipelineSpecMap)
51+
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to unmarshal pipeline spec into map")
5252
pipelineSpecMapNew := make(map[string]interface{})
5353
pipelineSpecMapNew["pipelineSpec"] = pipelineSpecMap
5454
pipelineSpecBytes, marshallingError = json.Marshal(pipelineSpecMapNew)
@@ -86,7 +86,7 @@ func CreateCompiledWorkflowFile(compiledWorflow *v1alpha1.Workflow, compiledWork
8686
ginkgo.GinkgoHelper()
8787
fileContents, err := yaml.Marshal(compiledWorflow)
8888
gomega.Expect(err).NotTo(gomega.HaveOccurred())
89-
return test_utils.CreateFile(compiledWorkflowFilePath, [][]byte{fileContents})
89+
return testutil.CreateFile(compiledWorkflowFilePath, [][]byte{fileContents})
9090
}
9191

9292
// ConfigureCacheSettings - Add/Remove cache_disabled args in the workflow

backend/test/end2end/e2e_suite_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
apiserver "github.com/kubeflow/pipelines/backend/src/common/client/api_server/v2"
2727
"github.com/kubeflow/pipelines/backend/test/config"
2828
"github.com/kubeflow/pipelines/backend/test/logger"
29-
"github.com/kubeflow/pipelines/backend/test/test_utils"
29+
"github.com/kubeflow/pipelines/backend/test/testutil"
3030
"github.com/kubeflow/pipelines/backend/test/v2"
3131

3232
. "github.com/onsi/ginkgo/v2"
@@ -65,8 +65,8 @@ var _ = BeforeSuite(func() {
6565
var newPipelineClient func() (*apiserver.PipelineClient, error)
6666
var newRunClient func() (*apiserver.RunClient, error)
6767
var newExperimentClient func() (*apiserver.ExperimentClient, error)
68-
clientConfig := test_utils.GetClientConfig(*config.Namespace)
69-
k8Client, err = test_utils.CreateK8sClient()
68+
clientConfig := testutil.GetClientConfig(*config.Namespace)
69+
k8Client, err = testutil.CreateK8sClient()
7070
Expect(err).To(BeNil(), "Failed to initialize K8s client")
7171

7272
if *config.KubeflowMode {
@@ -86,7 +86,7 @@ var _ = BeforeSuite(func() {
8686
userToken = *config.AuthToken
8787
} else {
8888
logger.Log("Creating API Clients for Multi User Mode")
89-
userToken = test_utils.CreateUserToken(k8Client, *config.UserNamespace, *config.UserServiceAccountName)
89+
userToken = testutil.CreateUserToken(k8Client, *config.UserNamespace, *config.UserServiceAccountName)
9090
}
9191
newPipelineClient = func() (*apiserver.PipelineClient, error) {
9292
return apiserver.NewMultiUserPipelineClient(clientConfig, userToken, *config.DebugMode)
@@ -131,7 +131,7 @@ var _ = BeforeEach(func() {
131131

132132
// Create Experiment so that we can use it to associate pipeline runs with
133133
experimentName := fmt.Sprintf("E2EExperiment-%s", strconv.FormatInt(time.Now().UnixNano(), 10))
134-
experiment := test_utils.CreateExperiment(experimentClient, experimentName, test_utils.GetNamespace())
134+
experiment := testutil.CreateExperiment(experimentClient, experimentName, testutil.GetNamespace())
135135
experimentID = &experiment.ExperimentID
136136
})
137137

@@ -141,7 +141,7 @@ var _ = ReportAfterEach(func(specReport types.SpecReport) {
141141
AddReportEntry("Test Log", specReport.CapturedGinkgoWriterOutput)
142142
currentDir, err := os.Getwd()
143143
Expect(err).NotTo(HaveOccurred(), "Failed to get current directory")
144-
test_utils.WriteLogFile(specReport, GinkgoT().Name(), filepath.Join(currentDir, testLogsDirectory))
144+
testutil.WriteLogFile(specReport, GinkgoT().Name(), filepath.Join(currentDir, testLogsDirectory))
145145
} else {
146146
log.Printf("Test passed")
147147
}

0 commit comments

Comments
 (0)