diff options
author | Achilleas Pipinellis <axil@gitlab.com> | 2022-10-14 06:03:04 +0300 |
---|---|---|
committer | Marcel Amirault <mamirault@gitlab.com> | 2022-10-14 06:03:04 +0300 |
commit | 14620adf4a3d76fc18ba8ad335bad9c7e34219c8 (patch) | |
tree | e93f36fb02af00e7d8335b7e919db8d181ec42a9 /lib | |
parent | 0ee5af27ef99a7cff82bf8c99db0f7d540e3315a (diff) |
Remove the cloned repository if it already exists
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tasks/build_site.rake | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/tasks/build_site.rake b/lib/tasks/build_site.rake index 7b831b57..b93478c2 100644 --- a/lib/tasks/build_site.rake +++ b/lib/tasks/build_site.rake @@ -25,6 +25,23 @@ task :clone_repositories do puts "\n#{TaskHelpers::COLOR_CODE_GREEN}INFO: Cloning #{product['repo']}..#{TaskHelpers::COLOR_CODE_RESET}" + # + # Handle the cases where we land on a runner that already ran a docs build, + # to make sure we're not reusing an old version of the docs, or a review + # app's content. + # + # Remove the cloned repository if it already exists and either the + # CI (when run in the runner context) or REMOVE_BEFORE_CLONE (when run localy) + # variables are set. + # + if Dir.exist?(product['project_dir']) + if ENV['CI'] || ENV['REMOVE_BEFORE_CLONE'] + FileUtils.rm_rf(product['project_dir']) + else + abort("\n#{TaskHelpers::COLOR_CODE_RED}ERROR: Failed to remove #{product['repo']}. To force remove it, use REMOVE_BEFORE_CLONE=true#{TaskHelpers::COLOR_CODE_RESET}") + end + end + `git clone --branch #{branch} --single-branch #{product['repo']} --depth 1 #{product['project_dir']}` latest_commit = `git -C #{product['project_dir']} log --oneline -n 1` |