Skip to content

Instantly share code, notes, and snippets.

@spk

spk/deploy.yaml

Created Jan 7, 2020
Embed
What would you like to do?
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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.