RELEASE ?= "v1.1.2-redhat"
VERSION ?= "3.3.4"
TARBALL ?= quay-operator.tar.gz
SRC ?= "src/quay-operator"

# Performs all steps required to prepare the opreator for release.
prerelease: clean fetch-upstream deps upload

# Grab the operator's source code from the upstream repository
# without its .git history.
fetch-upstream:
	rm -rf src
	mkdir -p src
	git clone --branch $(RELEASE) https://github.com/quay/quay-operator.git src/quay-operator
	cd src/quay-operator && rm -rf .git

# Fetch all requirements to compile the operator's binary.
deps:
	cd src/quay-operator && go mod vendor

# Bundle the source code and everything needed to compile it into a tarball. Upload that
# file so that it can be used for performing builds.
upload:
	cd src && tar cf ../$(TARBALL) quay-operator
	sed -i '/$(TARBALL)/d' sources # Clear previous checksum each time the source is packaged
	brew hello
	rhpkg upload $(TARBALL)

commit:
	-git commit -a -m "Automated release $(VERSION) by $(USER)"
	rhpkg push

# Starts the build process in OSBS.
release: commit
	rhpkg container-build

# Starts a scratch/test build in OSBS
scratch-release: commit
	rhpkg container-build --scratch

clean:
	rm -rf src && rm -f $(TARBALL)
