From b03f31b297e3b7c7ab519a5033f8ab45f5572da7 Mon Sep 17 00:00:00 2001 From: peaceiris <30958501+peaceiris@users.noreply.github.com> Date: Thu, 28 Apr 2022 06:13:22 +0900 Subject: [PATCH] build: improve make tasks --- .github/workflows/ci.yml | 3 ++ Makefile | 68 +++++++++++++++++++--------------------- docker-compose.yml | 2 +- 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 98427ffb3..527d00664 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,6 +47,8 @@ jobs: with: deno-version: "v1.x" + - run: make npm-ci + - run: make fetch-data env: GITHUB_TOKEN: ${{ secrets.GH_PAT }} @@ -145,6 +147,7 @@ jobs: run: | sed -i 's/enableGitInfo: true/# enableGitInfo: true/' exampleSite/config/_default/config.yaml + - run: make npm-ci - run: make docker-build setup: diff --git a/Makefile b/Makefile index b1a43a0f1..3d1a1800a 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,9 @@ -pwd := $(CURDIR) -cmd := "" +cmd := "version" +opt := "" DOCKER_COMPOSE := docker compose GH_USER_ID := peaceiris - +HUGO_VERSION := $(shell cd ./deps && go mod edit -json | jq -r '.Require[] | select(.Path == "github.com/gohugoio/hugo") | .Version | split("v") | .[1]') +GO_VERSION := $(shell cd ./deps && go mod edit -json | jq -r '.Go') .PHONY: bump-node bump-node: @@ -10,60 +11,55 @@ bump-node: .PHONY: npm-ci npm-ci: + cd ./exampleSite && \ npm ci .PHONY: docker-dev -docker-dev: npm-ci - $(eval opt := server --navigateToChanged --bind=0.0.0.0 --buildDrafts) - export HUGO_VERSION=$(shell make get-hugo-version) && \ +docker-dev: + $(eval opt := --bind=0.0.0.0) + export HUGO_VERSION=${HUGO_VERSION} && \ $(DOCKER_COMPOSE) up -d && \ - $(DOCKER_COMPOSE) exec hugo hugo $(opt) + $(DOCKER_COMPOSE) exec hugo make dev opt=$(opt) || \ + $(DOCKER_COMPOSE) down .PHONY: docker-hugo -docker-hugo: npm-ci - # make docker-hugo cmd="version" - export HUGO_VERSION=$(shell make get-hugo-version) && \ +docker-hugo: + @echo 'usage: make docker-hugo cmd="version"' + export HUGO_VERSION=${HUGO_VERSION} && \ $(DOCKER_COMPOSE) run --rm --entrypoint=hugo hugo $(cmd) .PHONY: docker-build -docker-build: npm-ci - $(eval opt := --minify --cleanDestinationDir) - export HUGO_VERSION=$(shell make get-hugo-version) && \ - $(DOCKER_COMPOSE) run --rm --entrypoint=hugo hugo $(opt) +docker-build: + export HUGO_VERSION=${HUGO_VERSION} && \ + $(DOCKER_COMPOSE) run --rm --entrypoint=make hugo build-prod .PHONY: docker-test -docker-test: npm-ci - $(eval opt := --minify --renderToMemory --printPathWarnings --debug \ - --templateMetrics --templateMetricsHints) - export HUGO_VERSION=$(shell make get-hugo-version) && \ - $(DOCKER_COMPOSE) run --rm --entrypoint=hugo hugo $(opt) - -.PHONY: npm-ci -npm-ci: - cd ./exampleSite && \ - npm ci +docker-test: + export HUGO_VERSION=${HUGO_VERSION} && \ + $(DOCKER_COMPOSE) run --rm --entrypoint=make hugo test .PHONY: dev -dev: npm-ci +dev: cd ./exampleSite && \ - hugo server --renderStaticToDisk --navigateToChanged --buildDrafts + hugo server --renderStaticToDisk --navigateToChanged --buildDrafts $(opt) .PHONY: test -test: npm-ci +test: cd ./exampleSite && \ - hugo --minify --renderToMemory --printPathWarnings --debug \ - --templateMetrics --templateMetricsHints + hugo --minify --debug --renderToMemory \ + --templateMetrics --templateMetricsHints \ + --printPathWarnings --printUnusedTemplates .PHONY: build-staging -build-staging: npm-ci +build-staging: cd ./exampleSite && \ - hugo --minify --cleanDestinationDir \ + hugo --minify --debug --cleanDestinationDir \ --environment "staging" \ - --printPathWarnings --debug \ - --templateMetrics --templateMetricsHints + --templateMetrics --templateMetricsHints \ + --printPathWarnings --printUnusedTemplates .PHONY: build-prod -build-prod: npm-ci +build-prod: cd ./exampleSite && \ hugo --minify --cleanDestinationDir --printPathWarnings && \ wget -O ./public/report.html ${BASE_URL}/report.html || true @@ -76,8 +72,8 @@ fetch-data: .PHONY: get-go-version get-go-version: - @cd ./deps && go mod edit -json | jq -r '.Go' + @echo ${GO_VERSION} .PHONY: get-hugo-version get-hugo-version: - @cd ./deps && go mod edit -json | jq -r '.Require[] | select(.Path == "github.com/gohugoio/hugo") | .Version | split("v") | .[1]' + @echo ${HUGO_VERSION} diff --git a/docker-compose.yml b/docker-compose.yml index ff9b13f45..cd6e9a330 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,5 +11,5 @@ services: - ${HUGO_CACHEDIR}:/tmp/hugo_cache stdin_open: true tty: true - working_dir: /src/hugo-theme-iris/exampleSite + working_dir: /src/hugo-theme-iris entrypoint: bash