#!/bin/bash

VERSION="$1"

if [[ ! -n ${VERSION}} ]]; then
	echo 'Please specify version number'
	exit 1
fi

cd ${MESA_DIR} || exit 1

# Do the work in a sperate branch
git checkout -b release/${VERSION}

# Add version_number file
echo ${VERSION} > data/version_number
git add -f data/version_number

# Update dox
sed -i "s/PROJECT_NUMBER\ \ \ .*/PROJECT_NUMBER\ \ \ \ \ \ \ \ \ =\ ${VERSION}/" Doxyfile
git add Doxyfile

# Update docs/source/conf.py
sed -i 's/release\ =.*/release\ =\ '"'${VERSION}'"'/' docs/source/conf.py
sed -i 's/version\ =.*/version\ =\ '"'${VERSION}'"'/' docs/source/conf.py

git add docs/source/conf.py

git commit -a -m "Release: ${VERSION}"
git tag ${VERSION}

# Make the archive
git archive --prefix=mesa-${VERSION}/ --format=zip ${VERSION} > mesa-${VERSION}.zip

echo "Now check the archive builds before pushing the changes"

exit 0

# Cleanup when testing
git checkout main
git tag -d ${VERSION}
git branch -D release/${VERSION}