From 2ce7e30e469879cc3713f48cfe1e2ae24e357a3a Mon Sep 17 00:00:00 2001 From: Joshua B Date: Fri, 22 Jul 2022 00:46:33 -0600 Subject: [PATCH] fix circle trigger --- Makefile | 1 - bin/circle | 31 ++++++++++++++++++++++++++----- makefiles/circle.make | 13 ++++++++++--- makefiles/git-tools.make | 37 +++++++++---------------------------- version.properties | 2 +- 5 files changed, 46 insertions(+), 38 deletions(-) diff --git a/Makefile b/Makefile index 7ad2bd6..24ab6c3 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/bin/circle b/bin/circle index 3d687be..48ffeb2 100755 --- a/bin/circle +++ b/bin/circle @@ -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}" diff --git a/makefiles/circle.make b/makefiles/circle.make index 251583e..4ad70d6 100644 --- a/makefiles/circle.make +++ b/makefiles/circle.make @@ -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. diff --git a/makefiles/git-tools.make b/makefiles/git-tools.make index fc6666c..d3a2727 100644 --- a/makefiles/git-tools.make +++ b/makefiles/git-tools.make @@ -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 diff --git a/version.properties b/version.properties index 1d64a87..b4bdff7 100644 --- a/version.properties +++ b/version.properties @@ -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