drainpipe icon indicating copy to clipboard operation
drainpipe copied to clipboard

Add tagging option to deploy:git

Open tess-ten7 opened this issue 1 year ago • 2 comments

Some workflows require tags be enforced for builds rather than branch name. Adding this option enables those workflows to work:

  git:
    desc: "Pushes a directory to a git remote"
    summary: |
      Given a directory, pushes it to a git remote whilst maintaining a linear
      history with the remote.

      usage: task deploy:git directory="/tmp/release" branch=main remote="[email protected]:Lullabot/drainpipe.git" message="Initial commit" push=true"

      directory=<directory>   A directory containing the files to be pushed
      branch=<branch>         Name of the branch to push to e.g. "main"
      tag=<tag>               Name of the tag to push
      remote=<remote>         Git remote to push to
      message=<message>       Commit message
      push=true               (optional) Push to the remote repository
    cmds:
      - if [ ! -d {{ shellQuote (.directory | default "") }} ]; then echo "Please provide a path to a directory to deploy" && exit 1; fi
      - if [ "" == {{ shellQuote (.branch | default "") }} ]; then echo "Please provide a branch to deploy to" && exit 1; fi
      - if [ "" == {{ shellQuote (.remote | default "") }} ]; then echo "Please provide a remote git repository to push to" && exit 1; fi
      - if [ "" == {{ shellQuote (.message | default "") }} ]; then echo "Please provide a commit message" && exit 1; fi
      - |
        TMP_DIR=$(mktemp -d)
        (git clone --depth 1 --branch {{.branch}} {{.remote}} $TMP_DIR && cd $TMP_DIR) || true
        if [[ ! -d "$TMP_DIR/.git" ]]; then
          git clone --depth 1 {{.remote}} $TMP_DIR
          cd $TMP_DIR
          git checkout -b {{.branch}}
        fi
        mv $TMP_DIR/.git {{.directory}}
        cd {{.directory}}
        git checkout -B {{.branch}}
        git add -A
        git commit --quiet --message {{shellQuote .message}} --allow-empty
        if [ {{shellQuote (.push | default "true") }} == "true" ]; then
          git push origin {{.branch}}
        fi
        if [ {{shellQuote (.tag | default "") }} != "" ]; then
          git tag {{.tag}}
          git push --tags
        fi

tess-ten7 avatar May 01 '24 15:05 tess-ten7

@justafish I was sure there was an existing issue around this, but I don't see one. Perhaps we just talked about this internally at some point?

We did something like this on a project, except we didn't actually push tags to Pantheon. It went like:

  1. Create a tag / release in GitHub.
  2. Build code with task build... and attach it as an archive to the release.
  3. Push that code to the main (or master) branch of the dev / test environments when the release is published on GitHub.
  4. One final manual action triggered to actually go from test to prod.

deviantintegral avatar May 03 '24 19:05 deviantintegral

Yeah, this is more for an acquia site. We use tags and switching the refspec for the prod environment to do deploys. It makes more sense there than on Pantheon. Still, it would be nice if the task supported tags too.

tess-ten7 avatar May 06 '24 17:05 tess-ten7