Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tagging option to deploy:git #556

Open
tess-ten7 opened this issue May 1, 2024 · 2 comments
Open

Add tagging option to deploy:git #556

tess-ten7 opened this issue May 1, 2024 · 2 comments

Comments

@tess-ten7
Copy link

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
@deviantintegral
Copy link
Member

@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.

@tess-ten7
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants