Skip to content

Commit

Permalink
build: improve make tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
peaceiris committed May 14, 2022
1 parent b39a497 commit 973d938
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 37 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ jobs:
with:
deno-version: "v1.x"

- run: make npm-ci

- run: make fetch-data
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
Expand Down Expand Up @@ -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:
Expand Down
68 changes: 32 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,69 +1,65 @@
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:
bash scripts/bump_node.sh

.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
Expand All @@ -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}
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 973d938

Please sign in to comment.