Skip to content

Instantly share code, notes, and snippets.

@spk
Created January 7, 2020 10:36
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spk/7be27d8f0f9fa0264fa24417ec40c742 to your computer and use it in GitHub Desktop.
Save spk/7be27d8f0f9fa0264fa24417ec40c742 to your computer and use it in GitHub Desktop.
Github Action Heroku Git Deploy
# https://github.com/marketplace/actions/checkout
# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#issue-comment-event-issue_comment
# https://devcenter.heroku.com/changelog-items/775
# https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches
# https://github.com/cirrus-actions/rebase#installation
# https://github.com/actions/heroku/issues/10
---
name: Deploy to HEROKU_APP_NAME
on:
issue_comment:
types: [created]
jobs:
deploy:
name: deploy
if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/deploy')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: |
git fetch --prune --unshallow
- name: Deploy to Heroku
env:
HEROKU_APP_NAME: "HEROKU_APP_NAME"
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
HEROKU_LOGIN: ${{ secrets.HEROKU_LOGIN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cat > ~/.netrc << EOF
machine api.heroku.com
login $HEROKU_LOGIN
password $HEROKU_API_KEY
machine git.heroku.com
login $HEROKU_LOGIN
password $HEROKU_API_KEY
EOF
PR_NUMBER=$(jq -r ".issue.number" "$GITHUB_EVENT_PATH")
URI=https://api.github.com
API_HEADER="Accept: application/vnd.github.v3+json"
AUTH_HEADER="Authorization: token $GITHUB_TOKEN"
pr_resp=$(curl -s -H "${AUTH_HEADER}" -H "${API_HEADER}" \
"${URI}/repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER")
HEAD_BRANCH=$(echo "$pr_resp" | jq -r .head.ref)
echo "HEAD_BRANCH is $HEAD_BRANCH"
git push --force https://git.heroku.com/$HEROKU_APP_NAME.git \
"origin/${HEAD_BRANCH}:master"
@dfl
Copy link

dfl commented Mar 5, 2024

with latest updates to git, line 46 should now be "origin/${HEAD_BRANCH}:refs/heads/master"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment