CircleCI-Public / heroku-orb

Easily install and use the Heroku CLI with CircleCI to build, test, and deploy your applications to Heroku.
https://circleci.com/orbs/registry/orb/circleci/heroku
MIT License
6 stars 20 forks source link

Deployment with tags #7

Closed campbecf closed 4 years ago

campbecf commented 4 years ago

Orb Version 1.0.1

Describe the bug

When using a tag to trigger a deployment the deploy-via-git command fails with the following message:

#!/bin/bash -eo pipefail
if false;then
  force="-f"
fi
git push $force https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git $CIRCLE_BRANCH:master
remote: 
remote: !   Push rejected, cannot delete master branch        
remote: 
To https://git.heroku.com/example.git
 ! [remote rejected]     master (pre-receive hook declined)
error: failed to push some refs to 'https://heroku:************************************@git.heroku.com/example.git'
Exited with code exit status 1
CircleCI received exit code 1

To Reproduce

Trigger a deployment via a tag.

Expected behavior

Should deploy the tag.

Additional context

I believe this has to do with the CIRCLE_TAG variable being set but not CIRCLE_BRANCH ?

a14m commented 4 years ago

there are 2 problems causing this to fail, the first one is CIRCLE_BRANCH has empty value (when CIRCLE_TAG has it)... The second problem (more importantly), there will be miss-matching references... changing the value of the parameters.branch to eq $CIRCLE_TAG or even $CIRCLE_TAG^{} isn't guaranteed to work... because the :master part on heroku will try to infer what is the pushed reference... and since it will find the <src> reference is a tag, it'll try to create the tag on <dest> which will succeed but won't trigger any deployment (Ref: https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-push.html check <refspec> docs)

Writing objects: 100% (2058/2058), 1.54 MiB | 882.00 KiB/s, done.
Total 2058 (delta 1189), reused 280 (delta 143), pack-reused 0
remote: Pushed to branch other than [main, master], skipping build.
To https://git.heroku.com/XXXXXXXXXXXX.git
 * [new tag]         v2.0.0 -> main

(it creates a tag on heroku remote called main, not pushing to the heroku branch, denoted by * [new tag] in logs)

for this to work, the <dest> has always to be refs/heads/master (or refs/heads/main) otherwise it'll be ignored by heroku Ref: https://devcenter.heroku.com/articles/git#deploying-code