Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
galaxyproject
GitHub Repository: galaxyproject/training-material
Path: blob/main/Makefile
1669 views
# Settings
UNAME := $(shell uname)
JEKYLL=jekyll
PORT?=4000
HOST?=0.0.0.0
FLAGS?=""
ENV?="development"
CHROME=google-chrome-stable
PDF_HOST?=127.0.0.1
SITE_URL=http://${PDF_HOST}:${PORT}/training-material
PDF_DIR=_pdf
REPO=$(shell echo "$${ORIGIN_REPO:-galaxyproject/training-material}")
BRANCH=$(shell echo "$${ORIGIN_BRANCH:-main}")
MINICONDA_URL=https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
SHELL=bash
RUBY_VERSION=2.4.4
CONDA_ENV=galaxy_training_material

ifeq ($(shell uname -s),Darwin)
	CHROME=/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
	MINICONDA_URL=https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
endif

ifeq ($(UNAME),Darwin)
	ENV_FILE=environment-osx.yml
else
	ENV_FILE=environment.yml
endif

CONDA=$(shell which mamba)
ifeq ($(CONDA),)
    CONDA=$(shell which conda)
    ifeq ($(CONDA),)
    	CONDA=${HOME}/miniconda3/bin/mamba
    endif
endif

default: help

install-conda: ## install Miniconda
	curl -L $(MINICONDA_URL) -o miniconda.sh
	bash miniconda.sh -b
.PHONY: install-conda

create-env: ## create conda environment
	if ${CONDA} env list | grep '^\s*${CONDA_ENV}'; then \
	    ${CONDA} env update -f ${ENV_FILE}; \
	else \
	    ${CONDA} env create -f ${ENV_FILE}; \
	fi
.PHONY: create-env

ACTIVATE_ENV = source $(shell dirname $(dir $(CONDA)))/bin/activate $(CONDA_ENV)
COND_ENV_DIR=$(shell dirname $(dir $(CONDA)))

install: clean create-env ## install dependencies
	$(ACTIVATE_ENV) && \
		gem update --no-document --system && \
		ICONV_LIBS="-L${CONDA_PREFIX}/lib/ -liconv" gem install --no-document addressable:'2.5.2' jekyll jekyll-feed jekyll-redirect-from csl-styles awesome_bot html-proofer pkg-config kwalify bibtex-ruby citeproc-ruby fastimage rubyzip && \
		pushd ${COND_ENV_DIR}/envs/${CONDA_ENV}/share/rubygems/bin && \
		ln -sf ../../../bin/ruby ruby
.PHONY: install

bundle-install: clean  ## install gems if Ruby is already present (e.g. on gitpod.io)
	bundle install
.PHONE: bundle-install

bundle-update: bundle-install  ## install gems if Ruby is already present (e.g. on gitpod.io)
	bundle update
.PHONE: bundle-update

serve: ## run a local server (You can specify PORT=, HOST=, and FLAGS= to set the port, host or to pass additional flags)
	@echo "Tip: Want faster builds? Use 'serve-quick' in place of 'serve'."
	@echo "Tip: to serve in incremental mode (faster rebuilds), use the command: make serve FLAGS=--incremental" && echo "" && \
	$(ACTIVATE_ENV) && \
		mv Gemfile Gemfile.backup || true && \
		mv Gemfile.lock Gemfile.lock.backup || true && \
		${JEKYLL} serve --trace --strict_front_matter -d _site/training-material -P ${PORT} -H ${HOST} ${FLAGS}
.PHONY: serve

serve-quick: ## run a local server (faster, some plugins disabled for speed)
	@echo "This will build the website with citations and other content disabled, and incremental on by default. To run the full preview (slower), use make serve" && echo "" && \
	$(ACTIVATE_ENV) && \
		mv Gemfile Gemfile.backup || true && \
		mv Gemfile.lock Gemfile.lock.backup || true && \
		${JEKYLL} serve --strict_front_matter -d _site/training-material --incremental --config _config.yml,_config-dev.yml -P ${PORT} -H ${HOST} ${FLAGS}
.PHONY: serve-quick

preview: serve-codespaces
.PHONY: serve-codespaces

serve-codespaces: codespace-clean bundle-install bundle-update
	bundle exec jekyll serve --config _config.yml,_config-dev.yml --incremental
.PHONY: serve-codespaces

codespace-clean:
	rm -rf /workspaces/.codespaces/shared/editors/jetbrains;
	rm -f /workspaces/training-material/.git/objects/pack/tmp_pack*
.PHONY: codespace-clean

serve-gitpod: bundle-install  ## run a server on a gitpod.io environment
	bundle exec jekyll serve --config _config.yml --incremental
.PHONY: serve-gitpod

serve-gitpod-quick: bundle-install  ## run a server on a gitpod.io environment
	bundle exec jekyll serve --config _config.yml,_config-dev.yml --incremental
.PHONY: serve-gitpod-quick

build-gitpod: bundle-install  ## run a build on a gitpod.io environment
	bundle exec jekyll build --config _config.yml
.PHONY: build-gitpod

build: clean ## build files but do not run a server (You can specify FLAGS= to pass additional flags to Jekyll)
	$(ACTIVATE_ENV) && \
		mv Gemfile Gemfile.backup || true && \
		mv Gemfile.lock Gemfile.lock.backup || true && \
		JEKYLL_ENV=${ENV} ${JEKYLL} build --strict_front_matter -d _site/training-material ${FLAGS}
.PHONY: build

check-frontmatter: ## Validate the frontmatter
	$(ACTIVATE_ENV) && \
		bundle exec ruby bin/validate-frontmatter.rb
		bundle exec ruby bin/validate-other.rb
.PHONY: check-frontmatter

check-contributors: ## Validate the contributors.yaml file
	$(ACTIVATE_ENV) && \
		bundle exec ruby bin/validate-contributors.rb
.PHONY: check-contributors

_check-html: # Internal
	$(ACTIVATE_ENV) && \
	  	htmlproofer \
	      	--assume-extension \
	      	--http-status-ignore 405,503,999 \
	      	--url-ignore "/.*localhost.*/","/.*vimeo\.com.*/","/.*gitter\.im.*/","/.*drmaa\.org.*/" \
	      	--url-swap "github.com/galaxyproject/training-material/tree/main:github.com/${REPO}/tree/${BRANCH}" \
	      	--file-ignore "/.*\/files\/.*/","/.*\/node_modules\/.*/","/\/tutorials\/.*\/docker\//" \
	      	--allow-hash-href \
	      	./_site
.PHONY: _check-html

check-html: build ## validate HTML
	$(MAKE) _check-html
.PHONY: check-html

_check-html-internal: # Internal
	$(ACTIVATE_ENV) && \
		htmlproofer \
	      	--assume-extension \
	      	--http-status-ignore 405,503,999 \
	      	--url-ignore "/.*localhost.*/","/.*vimeo\.com.*/","/.*gitter\.im.*/","/.*drmaa\.org.*/","/.*slides.html#/","/#embedded_jbrowse/","/.*videos.*.mp4.png/" \
	      	--url-swap "github.com/galaxyproject/training-material/tree/main:github.com/${REPO}/tree/${BRANCH}" \
	      	--file-ignore "/.*\/files\/.*/","/.*\/node_modules\/.*/","/\/tutorials\/.*\/docker\//" \
	      	--disable-external \
	      	--allow-hash-href \
	      	./_site
.PHONY: _check-html-internal

check-html-internal: build ## validate HTML (internal links only)
	$(MAKE) _check-html-internal
.PHONY: check-html-internal

check-slides: build  ## check the markdown-formatted links in slides
	$(ACTIVATE_ENV) && \
		find _site -path "**/slides*.html" \
	      	| xargs -L 1 -I '{}' sh -c "awesome_bot \
				--allow 405 \
				--allow-redirect \
				--white-list localhost,127.0.0.1,fqdn,vimeo.com,drmaa.com \
				--allow-ssl \
				--allow-dupe \
				--skip-save-results \
				-f {}"
.PHONY: check-slides

check-diffs: ## lint diffs in tutorials
	find ./topics/admin/ -name '*.md' -type f -print0 | xargs -n 1 -0 python3 bin/lint-diffs.py
.PHONY: check-diffs

check-yaml: ## lint yaml files
	find . -name '*.yaml' | grep -v .github | xargs -L 1 -I '{}' sh -c "yamllint -c .yamllint {}"
.PHONY: check-yaml

check-framework:
	$(ACTIVATE_ENV) && \
		ruby _plugins/jekyll-notranslate.rb
.PHONY: check-framework

check-broken-boxes: build ## List tutorials containing broken boxes
	./bin/check-broken-boxes
.PHONY: check-broken-boxes

check: check-html-internal check-html check-broken-boxes check-slides ## run checks which require compiled HTML
.PHONY: check

lint: check-frontmatter check-contributors ## run linting checks which do not require a built site
.PHONY: lint

check-links-gh-pages:  ## validate HTML on gh-pages branch (for daily cron job)
	$(ACTIVATE_ENV) && \
	  	htmlproofer \
			--assume-extension \
			--http-status-ignore 405,503,999 \
			--url-ignore "/.*localhost.*/","/.*vimeo\.com.*/","/.*gitter\.im.*/","/.*drmaa\.org.*/" \
			--file-ignore "/.*\/files\/.*/","/\/tutorials\/.*\/docker\//" \
			--allow-hash-href \
			. && \
		find . -path "**/slides*.html" \
			| xargs -L 1 -I '{}' sh -c "awesome_bot \
				--allow 405 \
				--allow-redirect \
				--white-list localhost,127.0.0.1,fqdn,vimeo.com,drmaa.com \
				--allow-ssl \
				--allow-dupe \
				--skip-save-results \
				-f {}"
.PHONY: check-links-gh-pages

TUTORIAL_PDFS=$(shell find _site/training-material -name 'tutorial.html' | sed 's/html$$/pdf/g')
SLIDE_PDFS=$(shell find _site/training-material -name 'slides.html' | sed 's/html$$/pdf/g')
SLIDE_PDFS+=$(shell find _site/training-material/*/*/slides/* | sed 's/html$$/pdf/g')

pdf: $(SLIDE_PDFS) $(TUTORIAL_PDFS) ## generate the PDF of the tutorials and slides
.PHONY: pdf

_site/%/tutorial.pdf: _site/%/tutorial.html
	if ! grep 'http-equiv="refresh"' $< --quiet; then \
		$(ACTIVATE_ENV) && \
		sed "s|/training-material/|$(shell pwd)/_site/training-material/|g" $< | \
		sed "s|<head>|<head><base href=\"file://$(shell pwd)/$(<:_site/training/material%=%)\">|" | \
		wkhtmltopdf \
		    --enable-javascript --javascript-delay 1000 \
			- $@; \
	fi


_site/%/slides.pdf: _site/%/slides.html
	$(ACTIVATE_ENV) && \
	./node_modules/.bin/http-server _site -p 9876 & \
	docker run --rm --network host -v $(shell pwd):/slides astefanutti/decktape:3.9  automatic -s 1920x1080 http://127.0.0.1:9876/$(<:_site/%=%) /slides/$@

_site/%/slides_ES.pdf: _site/%/slides_ES.html
	$(ACTIVATE_ENV) && \
	./node_modules/.bin/http-server _site -p 9876 & \
	docker run --rm --network host -v $(shell pwd):/slides astefanutti/decktape:3.9  automatic -s 1920x1080 http://127.0.0.1:9876/$(<:_site/%=%) /slides/$@

_site/%/slides_CAT_ES.pdf: _site/%/slides_CAT_ES.html
	$(ACTIVATE_ENV) && \
	./node_modules/.bin/http-server _site -p 9876 & \
	docker run --rm --network host -v $(shell pwd):/slides astefanutti/decktape:3.9  automatic -s 1920x1080 http://127.0.0.1:9876/$(<:_site/%=%) /slides/$@

video: ## Build all videos
	bash bin/ari-make.sh

metadata/public-server-tools.json:
	python ./bin/supported-fetch.py

annotate: ## annotate the tutorials with usable Galaxy instances
	${ACTIVATE_ENV} && \
	wget https://github.com/hexylena/toolshed-version-database/raw/main/guid-rev.json -O metadata/toolshed-revisions.json && \
	python bin/supported-fetch.py
	bin/workflows-fetch.rb
	bin/fetch-categories.rb
.PHONY: annotate

rebuild-search-index: ## Rebuild search index
	node bin/lunr-index.js > search.json

clean: ## clean up junk files
	@rm -rf _site
	@rm -rf .sass-cache
	@rm -rf .bundle
	@rm -rf vendor
	@rm -rf node_modules
	@rm -rf .jekyll-metadata
	@rm -rf .jekyll-cache
	@find . -name .DS_Store -exec rm {} \;
	@find . -name '*~' -exec rm {} \;
.PHONY: clean

help:
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: help