From 376fa19c78878dd59c9fb302f7d6426d75e7d241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=8C=AF=E5=AE=87?= <> Date: Tue, 4 Feb 2025 10:29:49 +0800 Subject: [PATCH] refactor(ChangedComponentsDetector, CommitMessageLinter, DependenciesResolver, executeFreeleapsPipeline): standardize workspace handling in directory operations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙振宇 <> --- .../devops/ChangedComponentsDetector.groovy | 2 +- .../devops/CommitMessageLinter.groovy | 4 +++- .../devops/DependenciesResolver.groovy | 20 +++++++++++++------ .../vars/executeFreeleapsPipeline.groovy | 1 + 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/first-class-pipeline/src/com/freeleaps/devops/ChangedComponentsDetector.groovy b/first-class-pipeline/src/com/freeleaps/devops/ChangedComponentsDetector.groovy index ac38ebcd..71773c3e 100644 --- a/first-class-pipeline/src/com/freeleaps/devops/ChangedComponentsDetector.groovy +++ b/first-class-pipeline/src/com/freeleaps/devops/ChangedComponentsDetector.groovy @@ -11,7 +11,7 @@ class ChangedComponentsDetector { def detect(workspace, components) { def changedComponents = [] as Set - dir(workspace) { + steps.dir(workspace) { // using git command to get changed files list def changedFiles = sh(script: 'git diff --name-only HEAD~1 HEAD', returnStdout: true) .trim() diff --git a/first-class-pipeline/src/com/freeleaps/devops/CommitMessageLinter.groovy b/first-class-pipeline/src/com/freeleaps/devops/CommitMessageLinter.groovy index e33e8955..e2e0ff67 100644 --- a/first-class-pipeline/src/com/freeleaps/devops/CommitMessageLinter.groovy +++ b/first-class-pipeline/src/com/freeleaps/devops/CommitMessageLinter.groovy @@ -23,6 +23,8 @@ class CommitMessageLinter { steps.log.info "Linting commit messages from HEAD..." - steps.sh "commitlint --verbose -g ${rules} -f HEAD^" + steps.dir(steps.env.workspace) { + steps.sh "commitlint --verbose -g ${rules} -f HEAD^" + } } } \ No newline at end of file diff --git a/first-class-pipeline/src/com/freeleaps/devops/DependenciesResolver.groovy b/first-class-pipeline/src/com/freeleaps/devops/DependenciesResolver.groovy index a074b207..32162010 100644 --- a/first-class-pipeline/src/com/freeleaps/devops/DependenciesResolver.groovy +++ b/first-class-pipeline/src/com/freeleaps/devops/DependenciesResolver.groovy @@ -53,11 +53,15 @@ class DependenciesResolver { def packageJsonFile = configurations.npmPackageJsonFile if (cachingEnabled) { - steps.cache(maxCacheSize: 512, caches: [[$class: 'ArbitraryFileCache', excludes: '', includes: '**/*', path: '.npm-cache']]) { - steps.sh "npm install --cache .npm-cache" + steps.dir(steps.env.workspace) { + steps.cache(maxCacheSize: 512, caches: [[$class: 'ArbitraryFileCache', excludes: '', includes: '**/*', path: '.npm-cache']]) { + steps.sh "npm install --cache .npm-cache" + } } } else { - steps.sh "npm install" + steps.dir(steps.env.workspace) { + steps.sh "npm install" + } } break @@ -69,11 +73,15 @@ class DependenciesResolver { def packageJsonFile = configurations.yarnPackageJsonFile if (cachingEnabled) { - steps.cache(maxCacheSize: 512, caches: [[$class: 'ArbitraryFileCache', excludes: '', includes: '**/*', path: '.yarn-cache']]) { - steps.sh "yarn install --cache-folder .yarn-cache" + steps.dir(steps.env.workspace) { + steps.cache(maxCacheSize: 512, caches: [[$class: 'ArbitraryFileCache', excludes: '', includes: '**/*', path: '.yarn-cache']]) { + steps.sh "yarn install --cache-folder .yarn-cache" + } } } else { - steps.sh "yarn install" + steps.dir(steps.env.workspace) { + steps.sh "yarn install" + } } break diff --git a/first-class-pipeline/vars/executeFreeleapsPipeline.groovy b/first-class-pipeline/vars/executeFreeleapsPipeline.groovy index dfb383b6..03f4a5f7 100644 --- a/first-class-pipeline/vars/executeFreeleapsPipeline.groovy +++ b/first-class-pipeline/vars/executeFreeleapsPipeline.groovy @@ -185,6 +185,7 @@ spec: dependenciesResolver.disableCachingSupport() } + sourceFetcher.fetch(configurations) dependenciesResolver.resolve(configurations) } }