Fixing CircleCI configuration without spamming commits

It bugs me that fixing CI config files requires committing and pushing to the repo. It seemed like I should be able to edit the config without creating an actual commit, as when changing a project’s architecture (new testing framework, etc) I often need several tries to get the CI right.

Thankfully I found this post describing how to do just that with the CircleCI API.

So I cleaned it up into a quick bash script which automatically extracts the repo name using git config.

#!/usr/bin/env bash
# circleci-try.sh -- Tries to run a new .circleci/config.yml from a checked out github repo without committing
# Usage: circleci-try.sh from the toplevel of a Git repo
# Requires $CIRCLECI_CLI_TOKEN to be set
# Thanks: https://discuss.circleci.com/t/running-new-config-files-without-committing/11842

set -x 
GITHUB_REPO_STR=`git config --get remote.origin.url`

if [ $RESULT -eq 0 ]; then
  if [[ $GITHUB_REPO_STR =~ git@github.com:([-0-9a-zA-Z/]+) ]]; then
    #echo ${BASH_REMATCH[1]}
    curl --user ${CIRCLECI_CLI_TOKEN}:        --request POST        --form config=@.circleci/config.yml        --form notify=false        https://circleci.com/api/v1.1/project/github/${BASH_REMATCH[1]}/tree/master
    echo ${BASH_REMATCH}
    echo "circleci-try.sh: Failed to match github repo. Are you sure you're in a repo checked out from GitHub?"

  echo "circleci-try.sh: git config --get remote.origin.url failed. Are you sure you're in a git repository?"