Make

“GNU Make is a tool which controls the generation of executables and other non-source files of a program from the program’s source files.” - gnu.org

Install

I use https://chocolatey.org/ for Windows installs but you can also install by manually downloading the exe.

1
choco install make

Examples

The Makefile then resides in the root of the project source, the docs describe the shape of the make commands.

Docker Compose Local Dependency

  1. Define in the file the action to carry out, here its start-local-dependency, everything to the right are the commands for the action.
1
2
3
4
5
6
start-local-dependency:
docker compose up \
--wait \
my-database \
my-dependancy-api \
my-identity-service
  1. Run make start-local-dependency

Define AWS CLI Commands

  1. Define the action create-aws-secret
1
2
3
4
5
6
7
create-aws-secret:
echo "Creating AWS Secret"
aws secretsmanager create-secret \
--name '$(NAME)' \
--description '$(DESC)' \
--kms-key-id 'arn:aws:kms:ap-southeast-2:000000000001:key/xxx-e11111111111111e11cd1111d1e11111' \
--secret-string '$(SEC)'
  1. Run make create-aws-secret NAME=foo DESC=bar SEC=secret

Pipeline Use Case

This can be used in a GitHub Actions Workflow to run Component / Intergration tests that require external dependency like my-database, my-dependancy-api or my-identity-service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
jobs:
start-local-dependency
name: Sweet Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4.1.7
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Start Local Dependency
shell: bash
run: make start-local-dependency
- name: Run Tests
working-directory: src
run: dotnet test

References