Blame Makefile

Packit Service eebd6f
# Extract the version from package.json
Packit Service eebd6f
VERSION=$(shell $(CURDIR)/rpmversion.sh | cut -d - -f 1)
Packit Service eebd6f
RELEASE=$(shell $(CURDIR)/rpmversion.sh | cut -d - -f 2)
Packit Service eebd6f
PACKAGE_NAME := $(shell awk '/"name":/ {gsub(/[",]/, "", $$2); print $$2}' package.json)
Packit Service eebd6f
TEST_OS ?= fedora-31
Packit Service eebd6f
export TEST_OS
Packit Service eebd6f
VM_IMAGE=$(CURDIR)/test/images/$(TEST_OS)
Packit Service eebd6f
ifneq (,$(wildcard ~/.config/codecov-token))
Packit Service eebd6f
BUILD_RUN = npm run build -- --with-coverage
Packit Service eebd6f
else
Packit Service eebd6f
BUILD_RUN = npm run build
Packit Service eebd6f
endif
Packit Service eebd6f
TARFILE=$(PACKAGE_NAME)-$(VERSION).tar.gz
Packit Service eebd6f
# stamp file to check if/when npm install ran
Packit Service eebd6f
NODE_MODULES_TEST=package-lock.json
Packit Service eebd6f
# one example file in dist/ from webpack to check if that already ran
Packit Service eebd6f
WEBPACK_TEST=public/dist/index.html
Packit Service eebd6f
Packit Service eebd6f
WEBLATE_REPO=tmp/weblate-repo
Packit Service eebd6f
WEBLATE_REPO_URL=https://github.com/osbuild/cockpit-composer-weblate.git
Packit Service eebd6f
WEBLATE_REPO_BRANCH=rhel8
Packit Service eebd6f
Packit Service eebd6f
all: $(WEBPACK_TEST)
Packit Service eebd6f
Packit Service eebd6f
$(WEBPACK_TEST): $(NODE_MODULES_TEST) $(shell find {core,components,data,pages,utils} -type f) package.json webpack.config.js $(patsubst %,dist/po.%.js,$(LINGUAS))
Packit Service eebd6f
	NODE_ENV=$(NODE_ENV) $(BUILD_RUN)
Packit Service eebd6f
Packit Service eebd6f
$(WEBLATE_REPO):
Packit Service eebd6f
	git clone --depth=1 -b $(WEBLATE_REPO_BRANCH) $(WEBLATE_REPO_URL) $(WEBLATE_REPO)
Packit Service eebd6f
Packit Service eebd6f
po-pull: $(WEBLATE_REPO)
Packit Service eebd6f
	cp $(WEBLATE_REPO)/*.po ./po/
Packit Service eebd6f
	NODE_ENV=$(NODE_ENV) npm run translations:po2json
Packit Service eebd6f
Packit Service eebd6f
po-push: po/cockpit-composer.pot $(WEBLATE_REPO)
Packit Service eebd6f
	cp ./po/cockpit-composer.pot $(WEBLATE_REPO)
Packit Service eebd6f
	git -C $(WEBLATE_REPO) commit -m "Update source file" -- cockpit-composer.pot
Packit Service eebd6f
	git -C $(WEBLATE_REPO) push
Packit Service eebd6f
Packit Service eebd6f
po/cockpit-composer.pot: $(WEBPACK_TEST)
Packit Service eebd6f
	NODE_ENV=$(NODE_ENV) npm run translations:extract
Packit Service eebd6f
	NODE_ENV=$(NODE_ENV) npm run translations:json2pot
Packit Service eebd6f
Packit Service eebd6f
install: all
Packit Service eebd6f
	mkdir -p /usr/share/cockpit/composer
Packit Service eebd6f
	cp -r public/* /usr/share/cockpit/composer
Packit Service eebd6f
	mkdir -p /usr/share/metainfo/
Packit Service eebd6f
	cp io.weldr.cockpit-composer.metainfo.xml /usr/share/metainfo/
Packit Service eebd6f
Packit Service eebd6f
# this requires a built source tree and avoids having to install anything system-wide
Packit Service eebd6f
devel-install: $(WEBPACK_TEST)
Packit Service eebd6f
	mkdir -p ~/.local/share/cockpit
Packit Service eebd6f
	ln -s `pwd`/public/dist ~/.local/share/cockpit/composer
Packit Service eebd6f
Packit Service eebd6f
Packit Service eebd6f
dist-gzip: $(TARFILE)
Packit Service eebd6f
Packit Service eebd6f
# when building a distribution tarball, call webpack with a 'production' environment
Packit Service eebd6f
# we don't ship node_modules for license and compactness reasons; we ship a
Packit Service eebd6f
# pre-built dist/ (so it's not necessary) and ship packge-lock.json (so that
Packit Service eebd6f
# node_modules/ can be reconstructed if necessary)
Packit Service eebd6f
$(TARFILE): NODE_ENV=production
Packit Service eebd6f
$(TARFILE): $(WEBPACK_TEST) $(PACKAGE_NAME).spec
Packit Service eebd6f
	if type appstream-util >/dev/null 2>&1; then appstream-util validate-relax --nonet *.metainfo.xml; fi
Packit Service eebd6f
	mv node_modules node_modules.release
Packit Service eebd6f
	touch -r package.json $(NODE_MODULES_TEST)
Packit Service eebd6f
	touch public/dist/*
Packit Service eebd6f
	tar czf $(PACKAGE_NAME)-$(VERSION).tar.gz --transform 's,^,$(PACKAGE_NAME)/,' \
Packit Service eebd6f
		--exclude $(PACKAGE_NAME).spec.in \
Packit Service eebd6f
		$$(git ls-files) package-lock.json $(PACKAGE_NAME).spec public/dist/
Packit Service eebd6f
	mv node_modules.release node_modules
Packit Service eebd6f
Packit Service eebd6f
$(PACKAGE_NAME).spec: $(PACKAGE_NAME).spec.in
Packit Service eebd6f
	sed -e 's|@VERSION@|$(VERSION)|' \
Packit Service eebd6f
	    -e 's|@RELEASE@|$(RELEASE)|' \
Packit Service eebd6f
	    < $(PACKAGE_NAME).spec.in > $(PACKAGE_NAME).spec
Packit Service eebd6f
Packit Service eebd6f
srpm: dist-gzip $(PACKAGE_NAME).spec
Packit Service eebd6f
	/usr/bin/rpmbuild -bs \
Packit Service eebd6f
	  --define "_sourcedir $(CURDIR)" \
Packit Service eebd6f
	  --define "_srcrpmdir $(CURDIR)" \
Packit Service eebd6f
	  $(PACKAGE_NAME).spec
Packit Service eebd6f
Packit Service eebd6f
rpm: dist-gzip $(PACKAGE_NAME).spec
Packit Service eebd6f
	mkdir -p "`pwd`/output"
Packit Service eebd6f
	mkdir -p "`pwd`/rpmbuild"
Packit Service eebd6f
	/usr/bin/rpmbuild -bb \
Packit Service eebd6f
	  --define "_sourcedir `pwd`" \
Packit Service eebd6f
	  --define "_specdir `pwd`" \
Packit Service eebd6f
	  --define "_builddir `pwd`/rpmbuild" \
Packit Service eebd6f
	  --define "_srcrpmdir `pwd`" \
Packit Service eebd6f
	  --define "_rpmdir `pwd`/output" \
Packit Service eebd6f
	  --define "_buildrootdir `pwd`/build" \
Packit Service eebd6f
	  $(PACKAGE_NAME).spec
Packit Service eebd6f
	find `pwd`/output -name '*.rpm' -printf '%f\n' -exec mv {} . \;
Packit Service eebd6f
	rm -r "`pwd`/rpmbuild"
Packit Service eebd6f
Packit Service eebd6f
tag:
Packit Service eebd6f
	@[ -n "$(NEWTAG)" ] || (echo "Run 'make NEWTAG=X.Y.Z tag' to tag a new release"; exit 1)
Packit Service eebd6f
	@git log --no-merges --pretty="format:- %s (%ae)" $(VERSION).. |sed -e 's/@.*)/)/' > clog.tmp
Packit Service eebd6f
	git tag -s -e -F clog.tmp $(NEWTAG); rm -f clog.tmp
Packit Service eebd6f
Packit Service eebd6f
eslint:
Packit Service eebd6f
	npm run eslint
Packit Service eebd6f
Packit Service eebd6f
stylelint:
Packit Service eebd6f
	npm run stylelint
Packit Service eebd6f
Packit Service eebd6f
buildrpm_image:
Packit Service eebd6f
	sudo docker build -f Dockerfile.buildrpm --cache-from welder/buildrpm:latest -t welder/buildrpm:latest .
Packit Service eebd6f
Packit Service eebd6f
test_rpmbuild: buildrpm_image
Packit Service eebd6f
	sudo docker run --rm --name buildrpm -v `pwd`:/composer welder/buildrpm:latest make rpm srpm
Packit Service eebd6f
Packit Service eebd6f
# build VMs
Packit Service eebd6f
$(VM_IMAGE): rpm bots
Packit Service eebd6f
	rm -f $(VM_IMAGE) $(VM_IMAGE).qcow2
Packit Service eebd6f
	bots/image-customize -v \
Packit Service eebd6f
		--resize 20G \
Packit Service eebd6f
		-i `pwd`/$(PACKAGE_NAME)-*.noarch.rpm \
Packit Service eebd6f
		-i composer-cli \
Packit Service eebd6f
		-u $(CURDIR)/test/files:/home/admin \
Packit Service eebd6f
		-u $(CURDIR)/test/osbuild-mock.repo:/etc/yum.repos.d \
Packit Service eebd6f
		-s $(CURDIR)/test/vm.install \
Packit Service eebd6f
		$(TEST_OS)
Packit Service eebd6f
Packit Service eebd6f
# convenience target for the above
Packit Service eebd6f
vm: $(VM_IMAGE)
Packit Service eebd6f
	echo $(VM_IMAGE)
Packit Service eebd6f
Packit Service eebd6f
# run the CDP integration test
Packit Service eebd6f
check: $(VM_IMAGE) test/common machine
Packit Service eebd6f
	test/common/run-tests --test-dir=test/verify --enable-network
Packit Service eebd6f
Packit Service eebd6f
# run test with browser interactively
Packit Service eebd6f
debug-check:
Packit Service eebd6f
	TEST_SHOW_BROWSER=true $(MAKE) check
Packit Service eebd6f
Packit Service eebd6f
# run flake8 on files inside test/verify
Packit Service eebd6f
flake8:
Packit Service eebd6f
	flake8 test/verify/*
Packit Service eebd6f
Packit Service eebd6f
# checkout Cockpit's bots for standard test VM images and API to launch them
Packit Service eebd6f
# must be from master, as only that has current and existing images; but testvm.py API is stable
Packit Service eebd6f
# support CI testing against a bots change
Packit Service eebd6f
bots:
Packit Service eebd6f
	git clone --quiet --reference-if-able $${XDG_CACHE_HOME:-$$HOME/.cache}/cockpit-project/bots https://github.com/cockpit-project/bots.git
Packit Service eebd6f
	if [ -n "$$COCKPIT_BOTS_REF" ]; then git -C bots fetch --quiet --depth=1 origin "$$COCKPIT_BOTS_REF"; git -C bots checkout --quiet FETCH_HEAD; fi
Packit Service eebd6f
	@echo "checked out bots/ ref $$(git -C bots rev-parse HEAD)"
Packit Service eebd6f
Packit Service eebd6f
machine: bots
Packit Service eebd6f
	rsync -avR --exclude="bots/machine/machine_core/__pycache__/" bots/machine/testvm.py bots/machine/identity bots/machine/cloud-init.iso bots/machine/machine_core bots/task/testmap.py test
Packit Service eebd6f
Packit Service eebd6f
# checkout Cockpit's test API; this has no API stability guarantee, so check out a stable tag
Packit Service eebd6f
# this needs a recent adjustment for firefox 77 and working with
Packit Service eebd6f
# network-enabled tests, so checkout a SHA until cockpit 221 releases
Packit Service eebd6f
test/common:
Packit Service eebd6f
	#git fetch --depth=1 https://github.com/cockpit-project/cockpit.git 221
Packit Service eebd6f
	#git checkout --force FETCH_HEAD -- test/common
Packit Service eebd6f
	git fetch https://github.com/cockpit-project/cockpit.git
Packit Service eebd6f
	git checkout --force 48c716de7ebd -- test/common
Packit Service eebd6f
	git reset test/common
Packit Service eebd6f
Packit Service eebd6f
Packit Service eebd6f
$(NODE_MODULES_TEST): package.json
Packit Service eebd6f
	# if it exists already, npm install won't update it; force that so that we always get up-to-date packages
Packit Service eebd6f
	rm -f package-lock.json
Packit Service eebd6f
	# unset NODE_ENV, skips devDependencies otherwise
Packit Service eebd6f
	env -u NODE_ENV npm install
Packit Service eebd6f
	env -u NODE_ENV npm prune
Packit Service eebd6f
Packit Service eebd6f
# The po-refresh bot expects these specific Makefile targets
Packit Service eebd6f
update-po:
Packit Service eebd6f
upload-pot: po-push
Packit Service eebd6f
download-po: po-pull
Packit Service eebd6f
clean-po:
Packit Service eebd6f
	rm po/*.po
Packit Service eebd6f
Packit Service eebd6f
.PHONY: tag vm check debug-check flake8 devel-install
Packit Service eebd6f
Packit Service eebd6f
#
Packit Service eebd6f
# Coverity
Packit Service eebd6f
#
Packit Service eebd6f
# Download the coverity analysis tool and run it on the repository,
Packit Service eebd6f
# archive the analysis result and upload it to coverity. The target
Packit Service eebd6f
# to do all of that is `coverity-submit`.
Packit Service eebd6f
#
Packit Service eebd6f
# Individual targets exists for the respective steps.
Packit Service eebd6f
#
Packit Service eebd6f
# Needs COVERITY_TOKEN and COVERITY_EMAIL to be set for downloading
Packit Service eebd6f
# the analysis tool and submitting the final results
Packit Service eebd6f
Packit Service eebd6f
BUILDDIR ?= .
Packit Service eebd6f
Packit Service eebd6f
$(BUILDDIR)/:
Packit Service eebd6f
	mkdir -p "$@"
Packit Service eebd6f
Packit Service eebd6f
$(BUILDDIR)/%/:
Packit Service eebd6f
	mkdir -p "$@"
Packit Service eebd6f
Packit Service eebd6f
COVERITY_URL=https://scan.coverity.com/download/linux64
Packit Service eebd6f
COVERITY_TARFILE=coverity-tool.tar.gz
Packit Service eebd6f
Packit Service eebd6f
COVERITY_BUILDDIR = $(BUILDDIR)/coverity
Packit Service eebd6f
COVERITY_TOOLTAR = $(COVERITY_BUILDDIR)/$(COVERITY_TARFILE)
Packit Service eebd6f
COVERITY_TOOLDIR = $(COVERITY_BUILDDIR)/cov-analysis-linux64
Packit Service eebd6f
COVERITY_ANALYSIS = $(COVERITY_BUILDDIR)/cov-analysis-cockpit-composer.xz
Packit Service eebd6f
Packit Service eebd6f
.PHONY: coverity-token
Packit Service eebd6f
coverity-token:
Packit Service eebd6f
	$(if $(COVERITY_TOKEN),,$(error COVERITY_TOKEN must be set))
Packit Service eebd6f
Packit Service eebd6f
.PHONY: coverity-email
Packit Service eebd6f
coverity-email:
Packit Service eebd6f
	$(if $(COVERITY_EMAIL),,$(error COVERITY_EMAIL must be set))
Packit Service eebd6f
Packit Service eebd6f
Packit Service eebd6f
.PHONY: coverity-download
Packit Service eebd6f
coverity-download: | coverity-token $(COVERITY_BUILDDIR)/
Packit Service eebd6f
	@$(RM) -rf "$(COVERITY_TOOLDIR)" "$(COVERITY_TOOLTAR)"
Packit Service eebd6f
	@echo "Downloading $(COVERITY_TARFILE) from $(COVERITY_URL)..."
Packit Service eebd6f
	@wget -q "$(COVERITY_URL)" --post-data "project=cockpit-composer-coverity&token=$(COVERITY_TOKEN)" -O "$(COVERITY_TOOLTAR)"
Packit Service eebd6f
	@echo "Extracting $(COVERITY_TARFILE)..."
Packit Service eebd6f
	@mkdir -p "$(COVERITY_TOOLDIR)"
Packit Service eebd6f
	@tar -xzf "$(COVERITY_TOOLTAR)" --strip 1 -C "$(COVERITY_TOOLDIR)"
Packit Service eebd6f
Packit Service eebd6f
$(COVERITY_TOOLTAR): | $(COVERITY_BUILDDIR)/
Packit Service eebd6f
	@$(MAKE) --no-print-directory coverity-download
Packit Service eebd6f
Packit Service eebd6f
.PHONY: coverity-check
Packit Service eebd6f
coverity-check: $(COVERITY_TOOLTAR)
Packit Service eebd6f
	@echo "Running coverity suite..."
Packit Service eebd6f
	@$(COVERITY_TOOLDIR)/bin/cov-build \
Packit Service eebd6f
		--dir "$(COVERITY_BUILDDIR)/cov-int" \
Packit Service eebd6f
		--no-command \
Packit Service eebd6f
		--fs-capture-search "$(BUILDDIR)" \
Packit Service eebd6f
		--fs-capture-search-exclude-regex "$(COVERITY_BUILDDIR)"
Packit Service eebd6f
	@echo "Compressing analysis results..."
Packit Service eebd6f
	@tar -caf "$(COVERITY_ANALYSIS)" -C "$(COVERITY_BUILDDIR)" "cov-int"
Packit Service eebd6f
Packit Service eebd6f
$(COVERITY_ANALYSIS): | $(COVERITY_BUILDDIR)/
Packit Service eebd6f
	@$(MAKE) --no-print-directory coverity-check
Packit Service eebd6f
Packit Service eebd6f
.PHONY: coverity-submit
Packit Service eebd6f
coverity-submit: $(COVERITY_ANALYSIS) | coverity-email coverity-token
Packit Service eebd6f
	@echo "Submitting $(COVERITY_ANALYSIS)..."
Packit Service eebd6f
	@curl --form "token=$(COVERITY_TOKEN)" \
Packit Service eebd6f
		--form "email=$(COVERITY_EMAIL)" \
Packit Service eebd6f
		--form "file=@$(COVERITY_ANALYSIS)" \
Packit Service eebd6f
		--form "version=main" \
Packit Service eebd6f
		--form "description=$$(git describe)" \
Packit Service eebd6f
		https://scan.coverity.com/builds?project=cockpit-composer-coverity
Packit Service eebd6f
Packit Service eebd6f
.PHONY: coverity-clean
Packit Service eebd6f
coverity-clean:
Packit Service eebd6f
	@$(RM) -rfv "$(COVERITY_BUILDDIR)/cov-int" "$(COVERITY_ANALYSIS)"
Packit Service eebd6f
Packit Service eebd6f
.PHONY: coverity-clean-all
Packit Service eebd6f
coverity-clean-all: coverity-clean
Packit Service eebd6f
	@$(RM) -rfv "$(COVERITY_BUILDDIR)"