drainpipe
drainpipe copied to clipboard
Add tagging option to deploy:git
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
@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:
- Create a tag / release in GitHub.
- Build code with
task build...and attach it as an archive to the release. - Push that code to the
main(ormaster) branch of the dev / test environments when the release is published on GitHub. - One final manual action triggered to actually go from test to prod.
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.