mirror of
https://github.com/CatalaLang/catala.git
synced 2024-10-07 09:17:31 +03:00
Better version handling
Always generate the version through git when possible, and encode that within the binaries so that `catala --version` does'nt give misleading information. Previously we used dune's builtin functionality, but that resorts to a hack at install time which is unpleasant and doesn't work with our use of `opam install`. The cost is a re-linking of catala_utils and the binaries upon git commit, which is hardly noticeable.
This commit is contained in:
parent
45a2aec1c9
commit
7b25a42970
28
.github/workflows/harness.yml
vendored
28
.github/workflows/harness.yml
vendored
@ -15,7 +15,17 @@ jobs:
|
||||
packages: write
|
||||
outputs:
|
||||
image: ghcr.io/catalalang/catala@${{ steps.image.outputs.digest }}
|
||||
version: ${{ steps.describe.outputs.version }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
# This is *only* needed to extract the git version...
|
||||
# Approaches like proudust/gh-describe@v1 don't work
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0 # Need full commit history
|
||||
- name: Get git-describe version
|
||||
id: describe
|
||||
run: echo "version=$(git describe --tags)" >> "$GITHUB_OUTPUT"
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
- name: Login to GHCR
|
||||
@ -37,7 +47,8 @@ jobs:
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
push: true
|
||||
tags: ghcr.io/catalalang/catala:${{ github.run_id }}
|
||||
tags: ghcr.io/catalalang/catala:${{ steps.describe.outputs.version }}
|
||||
build-args: "CATALA_VERSION=${{ steps.describe.outputs.version }}"
|
||||
labels: org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
|
||||
cache-from: type=registry,ref=ghcr.io/catalalang/catala:build-cache
|
||||
cache-to: type=registry,ref=ghcr.io/catalalang/catala:build-cache,mode=max
|
||||
@ -120,20 +131,19 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Get git-describe version
|
||||
id: ghd
|
||||
uses: proudust/gh-describe@v1
|
||||
- name: Build release binaries
|
||||
run: mkdir -p artifacts && ./build_release.sh -C artifacts
|
||||
run: |
|
||||
mkdir -p artifacts
|
||||
export CATALA_VERSION="${{ steps.ghd.outputs.describe }}"
|
||||
./build_release.sh -C artifacts
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: Catala binaries
|
||||
path: artifacts/*
|
||||
- name: Extract Catala version
|
||||
id: version
|
||||
run: echo "catala_version=$(git describe --tags)" >> "$GITHUB_OUTPUT"
|
||||
outputs:
|
||||
version: ${{ steps.version.outputs.catala_version }}
|
||||
|
||||
pages:
|
||||
name: Publish static content to github-pages
|
||||
|
@ -45,6 +45,8 @@ ENV OCAMLRUNPARAM=b
|
||||
# defined in ./dune)
|
||||
ENV DUNE_PROFILE=check
|
||||
|
||||
ARG CATALA_VERSION
|
||||
|
||||
# Check the build
|
||||
RUN opam exec -- make build js_build
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
set -ue
|
||||
|
||||
RELEASE_TAG=${RELEASE_TAG:-$(git describe --tags 2>/dev/null || echo dev)}
|
||||
CATALA_VERSION=${CATALA_VERSION:-$(git describe --tags 2>/dev/null || echo dev)}
|
||||
|
||||
BIN_TAG=${BIN_TAG:-$(uname -s)-$(uname -m)}
|
||||
|
||||
@ -30,6 +30,7 @@ docker run --rm -i registry.gitlab.inria.fr/verifisc/docker-catala:ocaml.4.14-z3
|
||||
sh -uexc \
|
||||
'{ tar x &&
|
||||
cd catala &&
|
||||
export CATALA_VERSION='"${CATALA_VERSION}"' &&
|
||||
echo "'"${CUSTOM_LINKING_CATALA_Z3}"'" >compiler/custom_linking.sexp &&
|
||||
echo "'"${CUSTOM_LINKING_CLERK}"'" >build_system/custom_linking.sexp &&
|
||||
opam --cli=2.1 install ./catala.opam --destdir ../release.out/ &&
|
||||
@ -38,8 +39,8 @@ docker run --rm -i registry.gitlab.inria.fr/verifisc/docker-catala:ocaml.4.14-z3
|
||||
echo "'"${CUSTOM_LINKING_CATALA_NOZ3}"'" >compiler/custom_linking.sexp &&
|
||||
opam --cli=2.1 install ./catala.opam --destdir ../release.out/ &&
|
||||
for f in ../release.out/bin/*; do case ${f} in
|
||||
*.js) mv ${f} ${f%.js}-'"${RELEASE_TAG}"'.js;;
|
||||
*) strip ${f}; mv ${f} ${f}-'"${RELEASE_TAG}"'-'"${BIN_TAG}"';;
|
||||
*.js) mv ${f} ${f%.js}-'"${CATALA_VERSION}"'.js;;
|
||||
*) strip ${f}; mv ${f} ${f}-'"${CATALA_VERSION}"'-'"${BIN_TAG}"';;
|
||||
esac; done;
|
||||
} >&2 && tar c -hC ../release.out/bin .' |
|
||||
tar vx "$@"
|
||||
|
@ -25,7 +25,6 @@ depends: [
|
||||
"cppo" {>= "1"}
|
||||
"dates_calc" {>= "0.0.4"}
|
||||
"dune" {>= "3.11"}
|
||||
"dune-build-info" {>= "3.0"}
|
||||
"js_of_ocaml-ppx" {= "4.1.0"}
|
||||
"menhir" {>= "20200211"}
|
||||
"menhirLib" {>= "20200211"}
|
||||
|
@ -415,10 +415,7 @@ module Flags = struct
|
||||
end
|
||||
|
||||
(* Retrieve current version from dune *)
|
||||
let version =
|
||||
Option.value ~default:"dev"
|
||||
Build_info.V1.(Option.map Version.to_string (version ()))
|
||||
|
||||
let version = Version.v
|
||||
let s_plugins = "INSTALLED PLUGINS"
|
||||
|
||||
let info =
|
||||
|
@ -1,16 +1,24 @@
|
||||
(library
|
||||
(name catala_utils)
|
||||
(public_name catala.catala_utils)
|
||||
(libraries
|
||||
unix
|
||||
cmdliner
|
||||
ubase
|
||||
ocolor
|
||||
re
|
||||
bindlib
|
||||
catala.runtime_ocaml
|
||||
dune-build-info))
|
||||
(modules
|
||||
(:standard \ get_version))
|
||||
(libraries unix cmdliner ubase ocolor re bindlib catala.runtime_ocaml))
|
||||
|
||||
(executable
|
||||
(name get_version)
|
||||
(modules get_version)
|
||||
(libraries unix))
|
||||
|
||||
(documentation
|
||||
(package catala)
|
||||
(mld_files catala_utils))
|
||||
|
||||
(rule
|
||||
(deps
|
||||
(universe)
|
||||
(env_var CATALA_VERSION))
|
||||
(action
|
||||
(with-stdout-to
|
||||
version.ml
|
||||
(run %{exe:get_version.exe}))))
|
||||
|
17
compiler/catala_utils/get_version.ml
Normal file
17
compiler/catala_utils/get_version.ml
Normal file
@ -0,0 +1,17 @@
|
||||
(** This trivial binary is run at build-time to get the correct version from the
|
||||
build environment (either the CATALA_VERSION) environment variable if
|
||||
defined, or `git describe`, or resorting to just "dev" if none of these can
|
||||
be found *)
|
||||
|
||||
let v =
|
||||
match Sys.getenv_opt "CATALA_VERSION" with
|
||||
| None | Some "" -> (
|
||||
let ic = Unix.open_process_in "git describe --tags --dirty 2>/dev/null" in
|
||||
let v = try input_line ic with _ -> "dev" in
|
||||
match Unix.close_process_in ic with Unix.WEXITED 0 -> v | _ -> "dev")
|
||||
| Some v -> v
|
||||
|
||||
let () =
|
||||
print_string "let v = \"";
|
||||
print_string (String.escaped v);
|
||||
print_endline "\""
|
4
compiler/catala_utils/version.mli
Normal file
4
compiler/catala_utils/version.mli
Normal file
@ -0,0 +1,4 @@
|
||||
(** The implementation of this module is generated by the build system (through
|
||||
[get_version.ml]), and should only contain a static string *)
|
||||
|
||||
val v : string
|
Loading…
Reference in New Issue
Block a user