From 187b4f63fcffd91265dcb8ad51f6eee4067002e8 Mon Sep 17 00:00:00 2001
From: Julien Girard <julien.girard2@cea.fr>
Date: Fri, 28 Jun 2024 15:56:43 +0200
Subject: [PATCH] [release] Automatize changing versions in manual and src

---
 .gitlab-ci.yml    |  2 +-
 Makefile          |  2 ++
 doc/conf.py       |  4 ++--
 src/main.ml       |  2 +-
 update_headers.sh |  5 -----
 update_version.sh | 16 ++++++++++++++++
 6 files changed, 22 insertions(+), 9 deletions(-)
 delete mode 100755 update_headers.sh
 create mode 100755 update_version.sh

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 892fcde..239321d 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,6 +1,6 @@
 variables:
   CAISAR_VERSION: "2.0.0"
-  TAG: "2.0"
+  TAG: "2.0.0"
 
 default:
   interruptible: true
diff --git a/Makefile b/Makefile
index 578e218..3b986d5 100644
--- a/Makefile
+++ b/Makefile
@@ -45,6 +45,8 @@ release:
 	@echo -n $(DESCRIPTION)
 	@echo "Is the CHANGES.md correct for $(TAG) (y/n)?"
 	@read yesno; test "$$yesno" = y
+	echo $(TAG) > VERSION
+	./update_version.sh
 	dune-release tag $(TAG)
 	dune-release distrib --skip-build --skip-lint
 	curl --header "PRIVATE-TOKEN: $(GITLAB_TOKEN)" \
diff --git a/doc/conf.py b/doc/conf.py
index e7f85be..44356ae 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -29,9 +29,9 @@ author = 'The CAISAR Development Team'
 # built documents.
 #
 # The short X.Y version.
-version = '2.0'
+version = '2.0.0'
 # The full version, including alpha/beta/rc tags.
-release = '2.0'
+release = '2.0.0'
 
 
 # -- General configuration ---------------------------------------------------
diff --git a/src/main.ml b/src/main.ml
index 9407ee1..c9f5e0d 100644
--- a/src/main.ml
+++ b/src/main.ml
@@ -433,7 +433,7 @@ let default_info =
       `P "Submit bug reports to https://git.frama-c.com/pub/caisar/issues";
     ]
   in
-  let version = "1.0" in
+  let version = "2.0.0" in
   let exits = Cmd.Exit.defaults in
   Cmd.info caisar ~version ~doc ~sdocs ~exits ~man
 
diff --git a/update_headers.sh b/update_headers.sh
deleted file mode 100755
index 9bd23b9..0000000
--- a/update_headers.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/usr/bin/env bash
-set -xe
-NEW_DATE=$(date "+%Y")
-OLD_DATE=$(date -d '1 year ago' "+%Y")
-find . \( -type d -name .git -prune \) \( -type d -name ._build -prune \) -o -type f -print0 | xargs -0 sed -i 's/(C) '${OLD_DATE}'/(C) '${NEW_DATE}'/g'
diff --git a/update_version.sh b/update_version.sh
new file mode 100755
index 0000000..96e69bc
--- /dev/null
+++ b/update_version.sh
@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+
+set -xe
+
+# Update headers in source files to match current year
+NEW_DATE=$(date "+%Y")
+OLD_DATE=$(date -d '1 year ago' "+%Y")
+find . \( -type d -name .git -prune \) \( -type d -name ._build -prune \) -o -type f -print0 | xargs -0 sed -i 's/(C) '${OLD_DATE}'/(C) '${NEW_DATE}'/g'
+
+# Update version in manual, ci and main.ml according to the VERSION file
+VERSION=$(cat VERSION)
+sed -E -i 's/let version = "([0-9]\.)+[0-9]" in/let version = "2.0.0" in/g' src/main.ml
+sed -E -i 's/version = \x27([0-9]\.)+[0-9]\x27/version = \x27'${VERSION}'\x27/g' doc/conf.py
+sed -E -i 's/release = \x27([0-9]\.)+[0-9]\x27/release = \x27'${VERSION}'\x27/g' doc/conf.py
+sed -E -i 's/CAISAR_VERSION: "([0-9]\.)+[0-9]"/CAISAR_VERSION: "'${VERSION}'"/g' .gitlab-ci.yml
+sed -E -i 's/TAG: "([0-9]\.)+[0-9]"/TAG: "'${VERSION}'"/g' .gitlab-ci.yml
-- 
GitLab