From 6d59a497e7ae96e8cac95f95897b899bfd18b96f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Fri, 6 Jul 2018 17:12:05 +0200 Subject: [PATCH] CI: add script for importing packages --- .gitlab-ci.yml | 2 +- scripts/opam-check.sh | 15 ++++++- scripts/update_opam_repo.sh | 80 +++++++++++++++++++++++++++++++++++++ scripts/version.sh | 2 +- 4 files changed, 96 insertions(+), 3 deletions(-) create mode 100755 scripts/update_opam_repo.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b2f232755..634ba1a77 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ variables: ## Please update `scripts/version.sh` accordingly - build_deps_image_version: dea9fc16442f36e71caa459f9675928d6b14a800 + build_deps_image_version: 63f06ab145e22aef4cc55b5b9557756d4c868843 build_deps_image_name: registry.gitlab.com/tezos/opam-repository public_docker_image_name: docker.io/${CI_PROJECT_PATH} diff --git a/scripts/opam-check.sh b/scripts/opam-check.sh index 5d7cee14e..bee58a45b 100755 --- a/scripts/opam-check.sh +++ b/scripts/opam-check.sh @@ -11,8 +11,21 @@ echo "## Checking installed dependencies..." echo if ! opam install $packages --deps-only --with-test --show-actions | grep "Nothing to do." > /dev/null 2>&1 ; then - echo "Failure!" + echo + echo 'Failure! Missing actions:' + echo opam install $packages --deps-only --with-test --show-actions + echo + echo 'Running `./scripts/update_opam_repo.sh`' + echo + ./scripts/update_opam_repo.sh + echo + echo 'Result:' + echo + cat opam_repo.patch + echo + echo 'Failed! Please run: `./scripts/update_opam_repo.sh` and follow the instructions.' + echo exit 1 fi diff --git a/scripts/update_opam_repo.sh b/scripts/update_opam_repo.sh new file mode 100755 index 000000000..93f6067e1 --- /dev/null +++ b/scripts/update_opam_repo.sh @@ -0,0 +1,80 @@ +#! /bin/sh + +set -e + +target="$(pwd)"/opam_repo.patch tmp_dir=$(mktemp -dt tezos_deps_opam.XXXXXXXX) + +cleanup () { + set +e + echo Cleaning up... + rm -rf "$tmp_dir" + rm -rf Dockerfile +} +# trap cleanup EXIT INT + +script_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)/")" +src_dir="$(dirname "$script_dir")" + +. "$script_dir"/version.sh + +opams=$(find "$src_dir/vendors" "$src_dir/src" -name \*.opam -print) + +## Full snapshot of the opam repository +git clone "$opam_repository_url" -b full "$tmp_dir" + +## Adding the various tezos packages +packages= +for opam in $opams; do + + dir=$(dirname $opam) + file=$(basename $opam) + package=${file%.opam} + packages=$packages,$package + mkdir -p "$tmp_dir"/packages/$package/$package.dev + + ## HACK: For some reason, `opam admin list/filter` do not follow + ## `--with-test/doc` for 'toplevel' package, only for their + ## 'dependencies. We want the exact opposite (like for `opam + ## install`), so we manually remove the tag the most + ## ugliest-possible way... + + sed -e "s/{ *test *}//" \ + -e "s/test \& //" \ + -e "s/\& test//" \ + -e "s/{ *doc *}//" \ + -e "s/doc \& //" \ + -e "s/\& doc//" \ + $opam > "$tmp_dir"/packages/$package/$package.dev/opam + +done + +## Filtering unrequired packages +cd $tmp_dir +opam admin filter --yes \ + --resolve $packages,ocaml,ocaml-base-compiler,odoc,opam-depext + +## Adding useful compiler variants +for variant in afl flambda fp fp+flambda ; do + git checkout packages/ocaml-variants/ocaml-variants.$ocaml_version+$variant +done + +## Removing the various tezos packages +for opam in $opams; do + file=$(basename $opam) + package=${file%.opam} + rm -r "$tmp_dir"/packages/$package +done + +## Adding safer hashes +opam admin add-hashes sha256 sha512 + +## Generating the diff! +git reset "$opam_repository_tag" +git add packages +git diff HEAD -- packages > "$target" + +echo +echo "Wrote proposed update in: $target." +echo 'Please add this patch to: `https://gitlab.com/tezos/opam-repository`' +echo 'And update accordingly the commit hash in: `.gitlab-ci.yml` and `scripts/version.sh`' +echo diff --git a/scripts/version.sh b/scripts/version.sh index a2c8aa89b..26d90c51b 100644 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -7,6 +7,6 @@ ocaml_version=4.06.1 opam_version=2.0.0~rc3 ## Please update `.gitlab-ci.yml` accordingly -opam_repository_tag=dea9fc16442f36e71caa459f9675928d6b14a800 +opam_repository_tag=63f06ab145e22aef4cc55b5b9557756d4c868843 opam_repository_url=https://gitlab.com/tezos/opam-repository.git opam_repository=$opam_repository_url\#$opam_repository_tag