Skip to content

Commit

Permalink
Extract the deploy logic into a separate bash script to make it more …
Browse files Browse the repository at this point in the history
…readable
  • Loading branch information
Torbjørn Vatn committed Apr 27, 2021
1 parent 105fe43 commit 59d8abd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
21 changes: 21 additions & 0 deletions plugins/github/deploy.sh
Original file line number Diff line number Diff line change
@@ -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;
13 changes: 4 additions & 9 deletions plugins/github/github-deploy.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 59d8abd

Please sign in to comment.