diff --git a/.github/scripts/main/main.sh b/.github/scripts/main/main.sh index 8b0d031a1a8..41256c996f2 100644 --- a/.github/scripts/main/main.sh +++ b/.github/scripts/main/main.sh @@ -12,7 +12,7 @@ unset-dev-version () { export OCAMLRUNPARAM=b (set +x ; echo -en "::group::build opam\r") 2>/dev/null -if [[ "$OPAM_TEST" -eq 1 ]] || [[ "$OPAM_DOC" -eq 1 ]] ; then +if [[ "$OPAM_TEST" -eq 1 ]] || [[ "$OPAM_DOC" -eq 1 ]] || [[ "$OPAM_DEPENDS" -eq 1 ]] ; then export OPAMROOT=$OPAMBSROOT # If the cached root is newer, regenerate a binary compatible root opam env || { rm -rf $OPAMBSROOT; init-bootstrap; } @@ -91,6 +91,40 @@ if [[ "$OPAM_DOC" -eq 1 ]]; then echo '::endgroup::checking generated files' fi +prepare_project () { + # warning, perform a cd + org=$1 + project=$2 + + url="https://github.com/$org/$project" + dir="$CACHE/$project" + + if [ ! -d "$CACHE/$project" ]; then + git clone "$url" "$dir" + fi + cd "$dir" + git fetch origin + if [ "$GITHUB_EVENT_NAME" = "pull_request" ] && git ls-remote --exit-code origin "$GITHUB_PR_USER/$BRANCH" ; then + BRANCH=$GITHUB_PR_USER/$BRANCH + fi + if git ls-remote --exit-code origin "$BRANCH"; then + PR_BRANCH=$BRANCH + elif [ "$GITHUB_EVENT_NAME" = pull_request ] && git ls-remote --exit-code origin "$GITHUB_BASE_REF"; then + PR_BRANCH=$GITHUB_BASE_REF + else + PR_BRANCH=master + fi + if git branch | grep -q "$PR_BRANCH"; then + git checkout "$PR_BRANCH" + git reset --hard "origin/$PR_BRANCH" + else + git checkout -b "$PR_BRANCH" "origin/$PR_BRANCH" + fi + + test -d _opam || opam switch create . --no-install --formula '"ocaml-system"' + opam pin "$GITHUB_WORKSPACE" -yn --with-version to-test +} + if [ "$OPAM_TEST" = "1" ]; then # test if an upgrade is needed set +e @@ -121,35 +155,52 @@ if [ "$OPAM_TEST" = "1" ]; then # Compile and run opam-rt (set +x ; echo -en "::group::opam-rt\r") 2>/dev/null - opamrt_url="https://github.com/ocaml-opam/opam-rt" - if [ ! -d $CACHE/opam-rt ]; then - git clone $opamrt_url $CACHE/opam-rt - fi - cd $CACHE/opam-rt - git fetch origin - if [ "$GITHUB_EVENT_NAME" = "pull_request" ] && git ls-remote --exit-code origin "$GITHUB_PR_USER/$BRANCH" ; then - BRANCH=$GITHUB_PR_USER/$BRANCH - fi - if git ls-remote --exit-code origin "$BRANCH"; then - OPAM_RT_BRANCH=$BRANCH - elif [ "$GITHUB_EVENT_NAME" = pull_request ] && git ls-remote --exit-code origin "$GITHUB_BASE_REF"; then - OPAM_RT_BRANCH=$GITHUB_BASE_REF - else - OPAM_RT_BRANCH=master - fi - if git branch | grep -q "$OPAM_RT_BRANCH"; then - git checkout "$OPAM_RT_BRANCH" - git reset --hard "origin/$OPAM_RT_BRANCH" - else - git checkout -b "$OPAM_RT_BRANCH" "origin/$OPAM_RT_BRANCH" - fi + prepare_project "ocaml-opam" "opam-rt" - test -d _opam || opam switch create . --no-install --formula '"ocaml-system"' - eval $(opam env) - opam pin $GITHUB_WORKSPACE -yn --with-version to-test # opam lib pins defined in opam-rt are ignored as there is a local pin opam pin . -yn --ignore-pin-depends opam install opam-rt --deps-only opam-devel.to-test - make || { opam reinstall opam-client -y; make; } + opam exec -- make || { opam reinstall opam-client -y; opam exec -- make; } (set +x ; echo -en "::endgroup::opam-rt\r") 2>/dev/null fi + +test_project () { + org=$1 + project=$2 + ignore_depends=$3 + make_cmd=$4 + + ignore="" + if [ $ignore_depends -eq 1 ]; then + ignore="--ignore-pin-depends" + fi + + (set +x; echo -en "::group::depends-$project\r") 2>/dev/null + prepare_project "$org" "$project" + set +e + opam pin . -yn $ignore + opam install "$project" --deps-only opam-client.to-test + opam exec -- $make_cmd || { opam reinstall opam-client -y; opam exec -- $make_cmd; } + code=$? + if [ $code -ne 0 ]; then + DEPENDS_ERRORS="$DEPENDS_ERRORS $project" + fi + set -e + (set +x ; echo -en "::endgroup::depends-$project\r") 2>/dev/null +} + +if [ "$OPAM_DEPENDS" = "1" ]; then + + DEPENDS_ERRORS="" + (set +x; echo -en "::group::depends\r") 2>/dev/null + + test_project "ocaml-opam" "opam-publish" 0 "make" + test_project "AltGr" "opam-bundle" 0 "make" + test_project "ocamlpro" "opam-custom-install" 1 "dune build" + + if [ -n "$DEPENDS_ERRORS" ]; then + echo -e "\e[31mErrors detected in plugins $DEPENDS_ERRORS\e[0m"; + exit 1 + fi + (set +x ; echo -en "::endgroup::depends\r") 2>/dev/null +fi diff --git a/.github/scripts/main/preamble.sh b/.github/scripts/main/preamble.sh index e15bd61422f..bf6597b4994 100644 --- a/.github/scripts/main/preamble.sh +++ b/.github/scripts/main/preamble.sh @@ -19,6 +19,7 @@ PATH=$OPAM_LOCAL/bin:$OCAML_LOCAL/bin:$PATH; export PATH OPAM_COLD=${OPAM_COLD:-0} OPAM_TEST=${OPAM_TEST:-0} OPAM_DOC=${OPAM_DOC:-0} +OPAM_DEPENDS=${OPAM_DEPENDS:-0} OPAM_UPGRADE=${OPAM_UPGRADE:-0} OPAM_REPO_MAIN=https://github.com/ocaml/opam-repository.git @@ -44,7 +45,7 @@ fi # used only for TEST jobs init-bootstrap () { - if [ "$OPAM_TEST" = "1" ] || [ "$OPAM_DOC" = "1" ] || [ -n "$SOLVER" ]; then + if [ "$OPAM_TEST" = "1" ] || [ "$OPAM_DOC" = "1" ] || [ "$OPAM_DEPENDS" = "1" ] || [ -n "$SOLVER" ]; then set -e export OPAMROOT=$OPAMBSROOT # The system compiler will be picked up diff --git a/.github/workflows/ci.ml b/.github/workflows/ci.ml index 2fc71589177..cd2d81a253a 100644 --- a/.github/workflows/ci.ml +++ b/.github/workflows/ci.ml @@ -480,6 +480,26 @@ let upgrade_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_jo ++ run "Test (upgrade)" ["bash -exu .github/scripts/main/upgrade.sh"] ++ end_job f +let depends_job ~analyse_job ~build_linux_job ?section runner ~oc ~workflow f = + let platform = os_of_platform runner in + let host = host_of_platform platform in + let only_on target = only_on platform target in + let needs = [analyse_job; build_linux_job ] in + let env = [("OPAM_DEPENDS", "1")] in + let matrix = platform_ocaml_matrix ~fail_fast:false start_latests_ocaml in + let ocamlv = "${{ matrix.ocamlv }}" in + job ~oc ~workflow ?section ~runs_on:(Runner [platform]) ~env ~needs ~matrix ("Depends-" ^ name_of_platform platform) + ++ only_on Linux (run "Install bubblewrap" ["sudo apt install bubblewrap"]) + ++ only_on Linux (run "Disable AppArmor" ["echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns"]) + ++ checkout () + ++ cache Archives + ++ cache OCaml platform ocamlv host + ++ build_cache OCaml platform ocamlv host + ++ cache OpamBS ocamlv "depends" + ++ build_cache OpamBS ocamlv "depends" + ++ run "Compile" ~env:[("BASE_REF_SHA", "${{ github.event.pull_request.base.sha }}"); ("PR_REF_SHA", "${{ github.event.pull_request.head.sha }}"); ("GITHUB_PR_USER", "${{ github.event.pull_request.user.login }}")] ["bash -exu .github/scripts/main/main.sh " ^ host] + ++ end_job f + let hygiene_job (type a) ~analyse_job (platform : a platform) ~oc ~workflow f = job ~oc ~workflow ~section:"Around opam tests" ~runs_on:(Runner [platform]) ~needs:[analyse_job] "Hygiene" ++ install_sys_dune [os_of_platform platform] @@ -557,6 +577,7 @@ let main oc : unit = @@ fun _ -> upgrade_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_job ~section:"Upgrade from 1.2 to current" Linux @@ fun _ -> upgrade_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_job MacOS @@ fun _ -> hygiene_job ~analyse_job (Specific (Linux, "22.04")) + @@ fun build_linux_job -> depends_job ~analyse_job ~build_linux_job Linux @@ fun _ -> end_workflow let () = diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4b4631d2d2a..4673f511976 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -692,3 +692,55 @@ jobs: PR_REF_SHA: ${{ github.event.pull_request.head.sha }} if: contains(steps.files.outputs.modified, 'configure.ac') || contains(steps.files.outputs.modified, 'shell/install.sh') || contains(steps.files.outputs.all, 'src_ext') || contains(steps.files.outputs.all, '.github/workflows') run: bash -exu .github/scripts/main/hygiene.sh + + Depends-Linux: + runs-on: ubuntu-latest + needs: [ Analyse, Hygiene ] + strategy: + matrix: + ocamlv: [ 4.14.2, 5.3.0 ] + fail-fast: false + env: + OPAM_DEPENDS: 1 + steps: + - name: Install bubblewrap + run: sudo apt install bubblewrap + - name: Disable AppArmor + run: echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns + - name: Checkout tree + uses: actions/checkout@v4 + - name: src_ext/archives and opam-repository Cache + id: archives + uses: actions/cache@v4 + with: + path: | + src_ext/archives + ~/opam-repository + key: ${{ needs.Analyse.outputs.archives }} + enableCrossOsArchive: true + - name: OCaml ${{ matrix.ocamlv }} Cache + id: ocaml-cache + uses: actions/cache@v4 + with: + path: ~/.cache/ocaml-local/** + key: ${{ runner.os }}-ocaml-${{ matrix.ocamlv }}-${{ needs.Analyse.outputs.ocaml-cache }} + - name: Create OCaml ${{ matrix.ocamlv }} cache + if: steps.ocaml-cache.outputs.cache-hit != 'true' + run: bash -exu .github/scripts/main/ocaml-cache.sh ${{ runner.os }} ${{ matrix.ocamlv }} + - name: opam bootstrap Cache + id: opam-bootstrap + uses: actions/cache@v4 + with: + path: | + ${{ env.OPAMBSROOT }}/** + ~/.cache/opam-local/bin/** + key: opamdepends-${{ runner.os }}-${{ env.OPAMBSVERSION }}-${{ matrix.ocamlv }}-${{ env.OPAM_REPO_SHA }}-${{ needs.Analyse.outputs.opam-bs-cache }} + - name: Create opam bootstrap cache + if: steps.opam-bootstrap.outputs.cache-hit != 'true' + run: bash -exu .github/scripts/main/opam-bs-cache.sh + - name: Compile + env: + BASE_REF_SHA: ${{ github.event.pull_request.base.sha }} + PR_REF_SHA: ${{ github.event.pull_request.head.sha }} + GITHUB_PR_USER: ${{ github.event.pull_request.user.login }} + run: bash -exu .github/scripts/main/main.sh x86_64-pc-linux-gnu diff --git a/master_changes.md b/master_changes.md index 836232e95c4..d585e1eda2b 100644 --- a/master_changes.md +++ b/master_changes.md @@ -189,6 +189,7 @@ users) * Add OCaml 5.3/MSVC to the build matrix [#6192 @kit-ty-kate] * Add a test making sure `opam init` works in the absence of `OPAMROOT` [#5663 @kit-ty-kate] * Show Cygwin version info after loading it from the cache [#6383 @kit-ty-kate] + * Add a job that test plugins compilation in order to keep them synchroniser [#6394 @rjbou] ## Doc * Update the command to install opam to point to the new simplified url on opam.ocaml.org [#6226 @kit-ty-kate]