Skip to content

Commit

Permalink
handy running CI locally
Browse files Browse the repository at this point in the history
Doesn't work for things that run Docker-in-Docker with fancy volume
mounts, though.
  • Loading branch information
robbkidd committed Sep 26, 2024
1 parent 70d15d1 commit 65a3c0c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.circleci/config-processed.yml
/artifacts/*
/bin/ocb*
/build/*
Expand Down
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,37 @@ $(OCB)-$(OTELCOL_VERSION):
curl --fail --location --output $@ \
"https://github.com/open-telemetry/opentelemetry-collector/releases/download/cmd/builder/v${OTELCOL_VERSION}/ocb_${OTELCOL_VERSION}_${GOOS}_${GOARCH}"
chmod u+x $@

JOB ?= build
#: run a CI job in docker locally, set JOB=some-job to override default 'build'
ci_local_exec: local_ci_prereqs
circleci local execute $(JOB) --config .circleci/config-processed.yml

### Utilities

# To use the circleci CLI to run jobs on your laptop.
circle_cli_docs_url = https://circleci.com/docs/local-cli/
local_ci_prereqs: forbidden_in_real_ci circle_cli_available .circleci/config-processed.yml

# the config must be processed to do things like expand matrix jobs.
.circleci/config-processed.yml: circle_cli_available .circleci/config.yml
circleci config process .circleci/config.yml > .circleci/config-processed.yml

circle_cli_available:
ifneq (, $(shell which circleci))
@echo "🔎:✅ circleci CLI available"
else
@echo "🔎:💥 circleci CLI command not available for local run."
@echo ""
@echo " ❓ Is it installed? For more info: ${circle_cli_docs_url}\n\n" && exit 1
endif

forbidden_in_real_ci:
ifeq ($(CIRCLECI),) # if not set, safe to assume not running in CircleCI compute
@echo "🔎:✅ not running in real CI"
else
@echo "🔎:🛑 CIRCLECI environment variable is present, a sign that we're running in real CircleCI compute."
@echo ""
@echo " 🙈 circleci CLI can't local execute in Circle. That'd be 🍌🍌🍌."
@echo "" && exit 1
endif

0 comments on commit 65a3c0c

Please sign in to comment.