From cd7d8a2e4c450d5e9f420c3e70281945c85a4b3c Mon Sep 17 00:00:00 2001 From: Josh Klar Date: Sat, 20 Jul 2019 16:14:58 -0700 Subject: [PATCH] Ability to build release zips in CI --- .circleci/config.yml | 23 +++++++++++++++++++++++ .gitignore | 1 + Dockerfile | 2 +- Makefile | 25 ++++++++++++++++++++++--- 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5a53c34..056a3a8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,6 +1,22 @@ --- version: 2 jobs: + build: + docker: + - image: 'kmkfw/base' + + environment: + KMK_TEST: 1 + PIPENV_VENV_IN_PROJECT: 1 + + steps: + - checkout + - restore_cache: + keys: + - v2-kmk-venv-{{ checksum "Pipfile.lock" }} + + - run: make dist + test: docker: - image: 'kmkfw/base' @@ -21,6 +37,13 @@ workflows: version: 2 build-deploy: jobs: + - build: + filters: + branches: + # only: /master/ + only: /.*/ + tags: + only: /.*/ - test: filters: branches: diff --git a/.gitignore b/.gitignore index 6292408..56723e2 100644 --- a/.gitignore +++ b/.gitignore @@ -102,6 +102,7 @@ venv.bak/ # mypy .mypy_cache/ +.compiled/ .ampy .submodules diff --git a/Dockerfile b/Dockerfile index 7f433cb..d26d6a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM python:3.7-alpine RUN mkdir -p /app WORKDIR /app -RUN apk update && apk add alpine-sdk curl gettext git git-lfs openssh rsync wget +RUN apk update && apk add alpine-sdk curl gettext git git-lfs openssh rsync wget zip RUN pip install pipenv diff --git a/Makefile b/Makefile index 7792be7..b4cba53 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,8 @@ .DEFAULT: all +DIST_DESCRIBE_CMD = git describe --always --abbrev=0 --dirty --broken + DOCKER_BASE_TAG ?= latest DOCKER_TAG ?= latest @@ -22,14 +24,31 @@ MPY_TARGET_DIR ?= .compiled all: copy-kmk copy-bootpy copy-keymap compile: $(MPY_TARGET_DIR)/.mpy.compiled + +$(MPY_TARGET_DIR)/.mpy.compiled: $(shell find $(MPY_SOURCES) -name "*.py") ifeq ($(MPY_CROSS),) @echo "===> Could not find mpy-cross in PATH, exiting" @false endif - -$(MPY_TARGET_DIR)/.mpy.compiled: $(shell find $(MPY_SOURCES) -name "*.py") @mkdir -p $(MPY_TARGET_DIR) @find $(MPY_SOURCES) -name "*.py" -exec sh -c 'mkdir -p $(MPY_TARGET_DIR)/$$(dirname {}) && mpy-cross $(MPY_FLAGS) {} -o $(MPY_TARGET_DIR)/$$(dirname {})/$$(basename -s .py {}).mpy' \; + @touch $(MPY_TARGET_DIR)/.mpy.compiled + +dist: dist/latest.zip dist/latest.unoptimized.zip dist/$(shell $(DIST_DESCRIBE_CMD)).zip dist/$(shell $(DIST_DESCRIBE_CMD)).unoptimized.zip + +dist/latest.zip: compile + @mkdir -p dist + @cd $(MPY_TARGET_DIR) && zip -r ../dist/latest.zip kmk + +dist/$(shell $(DIST_DESCRIBE_CMD)).zip: dist/latest.zip + @cp dist/latest.zip dist/$$($(DIST_DESCRIBE_CMD)).zip + +dist/latest.unoptimized.zip: + @mkdir -p dist + @zip -r dist/latest.unoptimized.zip kmk + +dist/$(shell $(DIST_DESCRIBE_CMD)).unoptimized.zip: dist/latest.unoptimized.zip + @cp dist/latest.unoptimized.zip dist/$$($(DIST_DESCRIBE_CMD)).unoptimized.zip .docker_base: Dockerfile @echo "===> Building Docker base image kmkfw/base:${DOCKER_BASE_TAG}" @@ -57,7 +76,7 @@ fix-isort: devdeps clean: clean-build-log @echo "===> Cleaning build artifacts" - @rm -rf .devdeps build + @rm -rf .devdeps build dist $(MPY_TARGET_DIR) clean-build-log: @echo "===> Clearing previous .build.log"