How to skip cloning when there are cached files and perform cloning when there are no cached files

This is what I do now :


Is that ok?
Is there a better way? If anyone knows, please tell me. Thank you very much.

I have the same issues. Then I implemented it in a rather stupid way.

First, the commands cannot execute multi-line commands like this:

commands:
  - if [ ! s "xxx" ]; then
      git clone xxx
  - fi

You need to run a shell script file for multi-line commands:

commands:
  - /bin/sh get_depends.sh

For example, my demo for cache repos:

  - name: restore-cache
    image: drillster/drone-volume-cache
    ...
    ...
  - name: get_depends
    image: drone/git
    environment:
      GIT_USERNAME:
        from_secret: user_name
      GIT_USERTOKEN:
        from_secret: access_token
    commands:
      - export CICD_PATH=_tmp_cicd
      - git clone https://$GIT_USERNAME:$GIT_USERTOKEN@git.itfanr.cc/leafney/demo.git
      - mv $DRONE_REPO_NAME/cicd ./$CICD_PATH
      - rm -rf $DRONE_REPO_NAME
      - echo "start download all depend repos"
      - /bin/sh ./$CICD_PATH/get_depends.sh
      - rm -rf $CICD_PATH
  - name: rebuild-cache
    image: drillster/drone-volume-cache
    ...
  - name: test
    ...

repo files:

- demo
  - cicd
    - dep_repos
    - get_depends.sh
 - others

the dep_repos contains all dependent libraries:

git.itfanr.cc/leafney/demo_utils

the get_depends.sh:

#!/bin/sh
for repo in $(cat ./$CICD_PATH/dep_repos); do

  # Get the name of the dependent library
  repo_name=${repo##*/}
  echo "the repo name is: ${repo_name}"

  # Determine if the dependent library is cached
  if [ ! -d "${repo_name}/.git" ]; then

    # no cached, download it
    echo "the repo ${repo_name} no cached, download it"
    git clone https://$GIT_USERNAME:$GIT_USERTOKEN@${repo}.git

  else

    # cached, update it
    echo "the repo ${repo_name} cached, update it"
    cd ${repo_name}

    # Define the master branch as the latest available branch
    git pull origin master:master

    # Return to the parent directory
    cd ..
  fi

done

There should be better ways to achieve it, and I am constantly exploring it.