Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 2 of 6 · Worked example · 20 min · revision 3

One entry point: wrapping your toolchain in Make or a task runner

Put the commands that lint, test and package a project behind one entry point, such as `make ci`, so that a laptop and the CI runner run the same steps.

Contentsand lesson path

What you will learn

  • Script a build that runs identically on a laptop and a CI runner, with pinned toolchain versions and locked dependencies.

01. The Unified Entry Point Pattern: Parity Between Local and CI

A common problem is that the commands developers run locally and the commands CI runs drift apart. In many projects, developers run custom ad-hoc commands locally—such as pytest -v, npm test, or cargo check—while the remote CI pipeline executes a fifty-line sequence of complex inline bash commands embedded directly within a YAML workflow file (such as .github/workflows/ci.yml or .gitlab-ci.yml).

This drift causes several problems:

  • Slow feedback and noisy history: when a pull request fails in CI, developers cannot easily reproduce the failure locally, so they push guesses ("fix CI syntax", "try setting env var") to trigger the runners again, which wastes time and clutters the history.
  • CI vendor lock-in: build logic written in one provider's YAML ties the project to that provider. Moving from Jenkins to GitHub Actions or GitLab CI then means rewriting and retesting every workflow file.
  • Working offline: without access to the CI service, a local entry point still lets engineers run the tests, formatting checks and packaging with the same commands CI uses.

The remedy is a single, standard entry point at the root of every repository, traditionally make ci or task ci. The CI workflow then shrinks to a few steps that install the toolchain and run this one command. Developers can execute the exact same command locally before pushing code. The same command, run with the same pinned toolchain (see lesson 01), gives the same result locally and in CI; with a different Python or tar version on the laptop, results can still differ.

When orchestrating complex multi-language repositories or monorepos, a top-level Makefile can cleanly delegate lifecycle targets to specific service directories using directory flags ($(MAKE) -C services/auth test). Each service keeps its own Makefile, and the repository still has one make ci for CI to call. A new team member also needs to learn only one set of commands.

02. Authoring Production Makefiles: Targets, Variables, and Traps

GNU Make is installed on most Unix-like systems and has been used for decades. It was designed to rebuild files whose inputs have newer timestamps, but it also works well as a top-level command runner if you follow a few conventions:

  • Phony targets (.PHONY): By default, Make assumes that every target name represents a file to be generated on disk. If a target is named test and a developer or tool creates a directory or file named test in the project root, Make sees that file, decides that test is already up to date, and does not run the recipe. Declaring .PHONY: lint test build ci clean explicitly tells Make that these targets represent executable commands rather than files.
  • Machine-readable reports: The test target in the Makefile below writes reports/junit.xml with pytest --junitxml, so CI can upload it and show which tests failed. The plain unittest runner prints results but writes no JUnit XML file. The package target reuses lesson 01's rules (sorted names, clamped mtime, fixed owner, gzip -n) and excludes __pycache__, which py_compile in lint creates; --sort=name needs GNU tar 1.28 or later.
  • Overridable configuration variables: Declare variables using conditional assignment operators (PYTHON ?= python3 or CI ?= false). This permits developers or continuous integration runners to override variables from the command line (e.g. make ci PYTHON=/opt/custom/python) without modifying Makefile source text.
  • Target dependencies and chaining: ci: lint test package lists the prerequisites of ci. Without -j, Make builds them one at a time from left to right and stops at the first recipe that exits with a non-zero code. With -j, independent prerequisites can run in parallel, so do not rely on their order unless one lists the other as a prerequisite.
  • Automatic variables and the default goal: Make provides automatic variables such as $@ (the target name), $< (the first prerequisite), and $^ (all prerequisites). Plain make runs the first target in the file (here all, which runs ci); setting .DEFAULT_GOAL := help would make it print the help list instead.
Makefile · Phony targets, a JUnit XML test report and a reproducible package
.PHONY: all lint test package ci clean help

# Configurable variables with overridable defaults
PYTHON ?= python3
SRC_DIR = src
TEST_DIR = tests
DIST_DIR = dist
REPORT_DIR = reports
SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct 2>/dev/null || echo 0)

all: ci

help: ## Show this help message
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
		awk 'BEGIN {FS = ":.*?## "}; {printf "%-12s %s\n", $$1, $$2}'

clean: ## Remove compiled artifacts, reports and caches
	rm -rf $(DIST_DIR) $(REPORT_DIR) .pytest_cache
	find . -name __pycache__ -type d -prune -exec rm -rf {} +

lint: ## Execute static analysis and syntax checks
	@echo "==> Running static analysis..."
	$(PYTHON) -m py_compile $(SRC_DIR)/service.py

test: ## Run the tests and write a JUnit XML report
	@echo "==> Running automated tests..."
	mkdir -p $(REPORT_DIR)
	PYTHONPATH=$(SRC_DIR) $(PYTHON) -m pytest $(TEST_DIR) \
		--junitxml=$(REPORT_DIR)/junit.xml

package: ## Build a reproducible distribution archive
	@echo "==> Creating distribution package..."
	mkdir -p $(DIST_DIR)
	tar --sort=name --format=gnu --mtime="@$(SOURCE_DATE_EPOCH)" \
		--owner=0 --group=0 --numeric-owner --mode=a=rX,u+w \
		--exclude=__pycache__ \
		-cf - -C $(SRC_DIR) . | gzip -n > $(DIST_DIR)/service.tar.gz
	sha256sum $(DIST_DIR)/service.tar.gz

ci: lint test package ## Execute complete pipeline locally or in CI
	@echo "==> [SUCCESS] All pipeline stages passed successfully."

The help recipe lists every target that has a ## description comment, so the Makefile documents itself. Save the file as Makefile and run make help; this target needs no project files.

Bash · list the targets
make help
Expected output
help         Show this help message
clean        Remove compiled artifacts, reports and caches
lint         Execute static analysis and syntax checks
test         Run the tests and write a JUnit XML report
package      Build a reproducible distribution archive
ci           Execute complete pipeline locally or in CI

03. Modern Alternatives: Just and Taskfile

Newer task runners avoid some of Make's quirks, such as the Tab rule, terse automatic variables like $< and $@, and awkward shell quoting:

  • just (justfile): a command runner built for project tasks rather than for building files. Recipe names are not files, so there is nothing like .PHONY; recipes can be indented with spaces or Tabs (consistently), and recipes can take named arguments.
  • task (Taskfile.yml): a task runner written in Go and configured in YAML. It has variable templating, runs commands through a built-in shell interpreter, so the same Taskfile works on Linux, macOS and Windows, and can skip a task when the checksums of its declared sources have not changed.

Whichever tool you choose, the principle is the same: one repository-level entry point that runs the same steps on a laptop and on a CI worker.

04. Check your understanding

Practice check · 3 questions

Phony targets, recipe syntax and variable defaults

Three questions on Makefile behaviour that trips people up.

Q1. A repository Makefile includes a target `test:`. A developer creates a directory named `test` in the project root to store integration fixtures. When running `make test`, Make outputs `make: 'test' is up to date.` and exits without running any tests. How should this be fixed?
Q2. A newly hired engineer modifies a Makefile by copying commands from a text editor, but running `make build` immediately fails with `Makefile:12: *** missing separator. Stop.`. What is the root cause of this failure?
Q3. A Makefile sets `PYTHON ?= python3`. What does `make ci PYTHON=.venv/bin/python` do?
Practice only: not graded, not saved, not evidence.

05. Apply it

In your own repositories:

  • Provide a make ci target: make sure every repository defines a single entry point (make ci or task ci) that runs dependencies, lints, tests, and builds.
  • Declare all non-file targets in .PHONY: list every command-style target, so a file or directory with the same name cannot block it.
  • Keep Tabs with EditorConfig: add [Makefile] indent_style = tab to .editorconfig so that editors do not replace recipe Tabs with spaces.
  • Add a help target: include an automated make help target that parses comments to display target summaries for new contributors.
  • Keep CI YAML thin: treat CI workflow files as thin execution wrappers that invoke repository task runners rather than storing business logic.

06. Review prompt

Explain why divergent local and CI workflows impair team velocity and code quality. Describe the role of .PHONY declarations in Makefiles, detail the indentation rule for recipe lines, and explain how a single entry point reduces CI vendor lock-in.

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

6 questions · about 5 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check