Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

GHA: add a job that test plugins compilation #6394

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 78 additions & 27 deletions .github/scripts/main/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"

Comment on lines +197 to +200
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also suggest adding dune-release, odep, odig, odoc-driver, opam-check-npm-deps, opam-build, opam-test, opam-dune-lint, opam-graph, opam-package-upgrade, orb, opam-0install and topkg-care

Copy link
Collaborator Author

@rjbou rjbou Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was package to test (some are failing on purpose as they have a dependency on opam < 2.2, see commits message). We'll need to select what package to add here : they are blocking for the PR merge.
Ideally we would have another more light mechanism, one that sends the information as a comment in the PR for ex., like that we are aware without blocking the PR (for packages that we don't maintain).

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
3 changes: 2 additions & 1 deletion .github/scripts/main/preamble.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/ci.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 () =
Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading