diff --git a/plugins/github/deploy.sh b/plugins/github/deploy.sh new file mode 100755 index 0000000..f2da1bd --- /dev/null +++ b/plugins/github/deploy.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +environment=$1 +auto_merge=$2 +task=$3 + +if git fetch && git diff @"{push}" --shortstat --exit-code > /dev/null 2>&1; then + # Trigger the deployment event + gh api repos/:owner/:repo/deployments -H "Accept: application/vnd.github.ant-man-preview+json" \ + --method POST -F ref=":branch" -F environment="$environment" -F auto_merge="$auto_merge" \ + -F task="$task" + + echo "Looking for active runs..." && sleep 5 + + # List all runs for current branch + branch=$(git branch --show-current) + run_id=$(gh run list --limit 1 | grep "$branch" | grep -v "completed" | rev | cut -f1 | rev) + gh run watch "$run_id" + else + echo "There is a git diff ⤴️ or no remote branch, exiting..." + fi; diff --git a/plugins/github/github-deploy.mk b/plugins/github/github-deploy.mk index 4f8062b..d0a271a 100644 --- a/plugins/github/github-deploy.mk +++ b/plugins/github/github-deploy.mk @@ -10,13 +10,8 @@ AUTO_MERGE=true define deploy @echo Checking diff local against remote - @if git fetch && git diff @{push} --shortstat --exit-code > /dev/null 2>&1; then \ - gh api repos/:owner/:repo/deployments -H "Accept: application/vnd.github.ant-man-preview+json" \ - --method POST -F ref=":branch" -F environment="$(strip $1)" -F auto_merge=${AUTO_MERGE} \ - -F task="$(strip $(if $2, $2, deploy))"; \ - echo "Looking for active runs..." && sleep 5; \ - gh run list --limit 1 | grep -v "completed" | rev | cut -f1 | rev | xargs gh run watch; \ - else \ - echo "There is a git diff ⤴️ or no remote branch, exiting..."; \ - fi; + ./deploy.sh \ + $(strip $1) \ + ${AUTO_MERGE} \ + $(strip $(if $2, $2, deploy)) endef