From c4fb14018c5d9857c8ec931daba35faa4da69565 Mon Sep 17 00:00:00 2001 From: tdstein Date: Tue, 11 Jun 2024 13:53:07 -0400 Subject: [PATCH] build: reduces makefile boilerplate --- .github/workflows/site.yaml | 9 ++++---- Dockerfile | 2 +- Makefile | 13 ++++-------- docs/Makefile | 29 ++++---------------------- integration/Makefile | 19 ++--------------- vars.mk | 41 +++++++++++++++++++++++++++++++++++++ 6 files changed, 57 insertions(+), 56 deletions(-) create mode 100644 vars.mk diff --git a/.github/workflows/site.yaml b/.github/workflows/site.yaml index 1f175569..23e90177 100644 --- a/.github/workflows/site.yaml +++ b/.github/workflows/site.yaml @@ -21,10 +21,11 @@ jobs: - run: make deps - run: make dev - run: make docs - - run: | - preview_url=$(make deploy | jq '.deploy_url' | tail -n 1 | tr -d '"') - echo "# 🚀 Site Preview" >> $GITHUB_STEP_SUMMARY - echo "$preview_url" >> $GITHUB_STEP_SUMMARY + - id: preview working-directory: docs env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} + run: | + preview_url=$(make deploy | jq '.deploy_url' | tail -n 1 | tr -d '"') + echo "# 🚀 Site Preview" >> $GITHUB_STEP_SUMMARY + echo "$preview_url" >> $GITHUB_STEP_SUMMARY diff --git a/Dockerfile b/Dockerfile index 0cd07112..b431ff06 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ RUN apt-get update && apt-get install -y make WORKDIR /sdk -COPY requirements.txt requirements-dev.txt Makefile ./ +COPY requirements.txt requirements-dev.txt vars.mk Makefile ./ RUN make deps diff --git a/Makefile b/Makefile index e990ad13..3d509030 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,6 @@ -.DEFAULT_GOAL := all - -NAME := posit-sdk -PYTHON := python3 +include vars.mk -ifneq ($(shell command -v uv 2>/dev/null),) -PIP := uv pip -else -PIP := pip3 -endif +.DEFAULT_GOAL := all .PHONY: build clean cov default deps dev docs fmt fix install it lint test uninstall version @@ -17,6 +10,8 @@ build: $(PYTHON) -m build clean: + $(MAKE) -C ./docs $@ + $(MAKE) -C ./integration $@ rm -rf .coverage .mypy_cache .pytest_cache .ruff_cache *.egg-info build coverage.xml dist htmlcov coverage.xml find . -name "*.egg-info" -exec rm -rf {} + find . -name "*.pyc" -exec rm -f {} + diff --git a/docs/Makefile b/docs/Makefile index 00d5f7c7..086f8c63 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -1,29 +1,8 @@ -.DEFAULT_GOAL := all +include ../vars.mk + +VERSION := $(shell $(MAKE) -C ../ -s version) -# Command aliases -PIP ?= pip3 -QUARTO ?= quarto -QUARTODOC ?= quartodoc - -# Environment variables -NETLIFY_SITE_ID ?= 5cea1f56-7935-4387-975a-18a7905d15ee -CURRENT_YEAR ?= $(shell date +%Y) -VERSION ?= $(shell make --silent -C ../ version | tail -n 1) -ENV ?= dev - -# Determine Netlify arguments from environment -ifeq ($(ENV), prod) - NETLIFY_ARGS := --prod -else - NETLIFY_ARGS := -endif - -# Determine if `uv` is available -ifneq ($(shell command -v uv 2>/dev/null),) -PIP := uv pip -else -PIP := pip3 -endif +.DEFAULT_GOAL := all .PHONY: all \ api \ diff --git a/integration/Makefile b/integration/Makefile index 9c0eaabb..d4a453c0 100644 --- a/integration/Makefile +++ b/integration/Makefile @@ -1,3 +1,5 @@ +include ../vars.mk + .DEFAULT_GOAL := all .PHONY: $(CONNECT_VERSIONS) \ @@ -29,23 +31,6 @@ CONNECT_VERSIONS := 2024.05.0 \ 2022.12.0 \ 2022.11.0 -# Environment Variables -NAME = posit-sdk -IMAGE_TAG ?= posit-sdk-py:latest -CONNECT_BOOTSTRAP_SECRETKEY ?= $(shell head -c 32 /dev/random | base64) -CONNECT_IMAGE ?= rstudio/rstudio-connect - -# Binaries -DOCKER_COMPOSE ?= docker compose -PYTHON ?= python3 - -# Determine if `uv` is available -ifneq ($(shell command -v uv 2>/dev/null),) -PIP := uv pip -else -PIP := pip3 -endif - clean: rm -rf logs reports find . -type d -empty -delete diff --git a/vars.mk b/vars.mk new file mode 100644 index 00000000..c4bc464e --- /dev/null +++ b/vars.mk @@ -0,0 +1,41 @@ +# Makefile variables file. +# +# Variables shared across project Makefiles via 'include vars.mk'. +# +# - ./Makefile +# - ./docs/Makefile +# - ./integration/Makefile + +CONNECT_BOOTSTRAP_SECRETKEY ?= $(shell head -c 32 /dev/random | base64) + +CONNECT_IMAGE ?= rstudio/rstudio-connect + +CURRENT_YEAR ?= $(shell date +%Y) + +DOCKER_COMPOSE ?= docker compose + +ENV ?= dev + +IMAGE_TAG ?= $(NAME):latest + +NAME := posit-sdk-py + +ifeq ($(ENV), prod) + NETLIFY_ARGS := --prod +else + NETLIFY_ARGS := +endif + +NETLIFY_SITE_ID ?= 5cea1f56-7935-4387-975a-18a7905d15ee + +PYTHON := python3 + +ifneq ($(shell command -v uv 2>/dev/null),) +PIP := uv pip +else +PIP := pip3 +endif + +QUARTO ?= quarto + +QUARTODOC ?= quartodoc