Skip to content

Commit

Permalink
fix circle trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
basejump committed Jul 22, 2022
1 parent af456e3 commit 2ce7e30
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 38 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ include $(SHIPKIT_MAKEFILES)/git-tools.make
include $(SHIPKIT_MAKEFILES)/ship-version.make
include $(SHIPKIT_MAKEFILES)/circle.make
include $(SHIPKIT_MAKEFILES)/bats-testing.make
include $(SHIPKIT_MAKEFILES)/git-dev.make
include $(SHIPKIT_MAKEFILES)/kube.make
include $(SHIPKIT_MAKEFILES)/kubectl-config.make

Expand Down
31 changes: 26 additions & 5 deletions bin/circle
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,42 @@ core.import "git_tools"

##
# uses curl to trigger a pipeline for a branch.
# Expect the PROJECT_FULLNAME and CIRCLE_TOKEN to be set before calling.
# Expect the CIRCLE_TOKEN to be set before calling. will try and setup the PROJECT_FULLNAME (slug) from current repo if not set
# NOTE: if the branch passed in does not exist then it will still run and end up using whatever is set as master branch.
# - $1 - the branch name. OPTIONAL, if not provided then will use git to read the current branch
circle.trigger(){
circle.trigger-this(){
local branch_name=${1:-}
# read from github if not specified
[ ! "$branch_name" ] && branch_name=$(git rev-parse --abbrev-ref HEAD)
local branch_data="{\"branch\":\"${branch_name}\"}"

# if no project name then get it.
[ ! "${PROJECT_FULLNAME:-}" ] && project_fullname_from_git_remote

echo "triggering ${PROJECT_FULLNAME} branch: ${branch_data}"
circle.trigger "${PROJECT_FULLNAME:-}" "$branch_name"

}

##
# uses curl to trigger a pipeline for a branch.
# Expect CIRCLE_TOKEN to be set before calling.
# NOTE: if the branch passed in does not exist then it will still run and end up using whatever is set as master branch.
# - $1 - the project name.
# - $2 - the branch name.
# @see circle.trigger-this() to trigger current project
circle.trigger(){
local slug=${1:-}
local branch_name=${2:-}

local branch_data="{\"branch\":\"${branch_name}\"}"
# if not branch then just blank it out and circle will use defualt
[[ ! "$branch_name" ]] && branch_data=""

echo "triggering slug: ${slug} branch_data: ${branch_data}"

[[ ! "${slug}" ]] && echo "bad project slug" && return 1

curl --location --request POST \
"https://circleci.com/api/v2/project/github/${PROJECT_FULLNAME}/pipeline" \
"https://circleci.com/api/v2/project/github/${slug}/pipeline" \
--header 'Content-Type: application/json' \
-u "${CIRCLE_TOKEN}:" \
--data "${branch_data}"
Expand Down
13 changes: 10 additions & 3 deletions makefiles/circle.make
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ circle.sh := $(SHIPKIT_BIN)/circle
help.circle:
$(MAKE) help HELP_REGEX="^circle.*"

# Triggers circle to build project call. Will use PROJECT_FULLNAME and defaults to current branch.
# pass `b=some_branch` to specify a different one.
# Triggers circle to build project call.
# `make circle.trigger` will use PROJECT_FULLNAME and defaults to current branch.
# `make circle.trigger slug=yakworks/foo b=some_branch` can pass slug for different project and b for branch.
circle.trigger: | _verify_CIRCLE_TOKEN _verify_PROJECT_FULLNAME
$(circle.sh) trigger $(b)
if [[ "$(slug)" ]]; then
# will blow up if branch is not passed too
$(circle.sh) trigger "$(slug)" "$(b)"
else
$(circle.sh) trigger-this "$(b)"
fi



# opens the circle pipeline for this project in the default web browser. only works on mac right now.
Expand Down
37 changes: 9 additions & 28 deletions makefiles/git-tools.make
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,12 @@ git.config-signed-commits:
$(logr) "signing commits with key id $${secKeyId::-6}******"
fi

# GITHUB_BOT_URL = https://dummy:$(GITHUB_BOT_TOKEN)@$(GITHUB_BASE_URL)

# changes verison.properties to snapshot=false and force pushes commit with release message to git.
# git.update-release:
# echo $(GITHUB_BOT_URL)
# # changed_files=$$(git status --porcelain --untracked-files=no | wc -l)
# # unpushed=$$(git cherry -v)
# # if [ $$changed_files -gt 0 ] || [ "$$unpushed" ] ; then
# # $(logr.error) "uncommitted changes detected. must be in a clean state"
# # git status
# # else
# sed -i.bak -e "s/^release=.*/release=true/g" version.properties && rm version.properties.bak
# git add version.properties
# git commit -m "trigger release"
# git push $(GITHUB_BOT_URL)
# $(logr.done)
# # fi

# git.update-release:
# echo $(GITHUB_BOT_URL)
# sed -i.bak -e "s/^release=.*/release=true/g" version.properties && rm version.properties.bak
# git add version.properties
# git commit -m "trigger release"
# git push $(GITHUB_BOT_URL)
# $(logr.done)

# trigger-release: push-snapshot-false

# gets the simple commit message for the SHA1. `make git.get-commit-message SHA1=de6b96efd....`
# if no SHA1 is passed then will show the last one.
git.get-commit-message:
if [[ "$${SHA1:-}" ]]; then
git log --format=%B -n 1 $$SHA1
else
git log -1 --format=%B
fi
# export GIT_COMMIT_MESSAGE=\"$(git log --format=%B -n 1 $CIRCLE_SHA1)\"" >> $BASH_ENV
2 changes: 1 addition & 1 deletion version.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ publishedVersion=2.0.8
# when this is false will append -SNAPSHOT to version and if on publishable branch will 'publish' to snapshotUrl
# when true IS_RELEASEBALE will be set and will go through full release process cycle to
# automatically bump version and push a v tag to github
release=false
release=true

0 comments on commit 2ce7e30

Please sign in to comment.