Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbou committed Feb 21, 2025
1 parent 959ac2d commit 1a503f3
Showing 1 changed file with 55 additions and 52 deletions.
107 changes: 55 additions & 52 deletions .github/scripts/main/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,40 @@ if [[ "$OPAM_DOC" -eq 1 ]]; then
echo '::endgroup::checking generated files'
fi

prepare_project () {
# warning, perform a cd
gh_project=$1
url="https://github.com/$gh_project"
project=${gh_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"'
eval $(opam env)
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,32 +155,8 @@ 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
fetch_branch "opam-rt" "ocaml-opam"

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
Expand All @@ -155,36 +165,29 @@ if [ "$OPAM_TEST" = "1" ]; then
fi

if [ "$OPAM_DEPENDS" = "1" ]; then
(set +x; echo -en "::group::depends\r") 2>/dev/null
opam_admin_url="https://github.com/ocaml-opam/opam-publish"
if [ ! -d $CACHE/opam-admin ]; then
git clone $opam_admin_url $CACHE/opam-admin
fi
cd $CACHE/opam-admin
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_ADMIN_BRANCH=$BRANCH
elif [ "$GITHUB_EVENT_NAME" = pull_request ] && git ls-remote --exit-code origin "$GITHUB_BASE_REF"; then
OPAM_ADMIN_BRANCH=$GITHUB_BASE_REF
else
OPAM_ADMIN_BRANCH=master
fi
if git branch | grep -q "$OPAM_ADMIN_BRANCH"; then
git checkout "$OPAM_ADMIN_BRANCH"
git reset --hard "origin/$OPAM_ADMIN_BRANCH"
else
git checkout -b "$OPAM_ADMIN_BRANCH" "origin/$OPAM_ADMIN_BRANCH"
fi

test -d _opam || opam switch create . --no-install --formula '"ocaml-system"'
eval $(opam env)
opam pin $GITHUB_WORKSPACE -yn --with-version to-test
# opam-publish
(set +x; echo -en "::group::depends-opam-publish\r") 2>/dev/null
fetch_branch "ocaml-opam/opam-publish"
opam pin . -yn
opam install opam-publish --deps-only opam-client.to-test
make || { opam reinstall opam-client -y; make; }
(set +x ; echo -en "::endgroup::opam-admin\r") 2>/dev/null
(set +x ; echo -en "::endgroup::depends-opam-publish\r") 2>/dev/null

# opam-bundle
(set +x; echo -en "::group::depends-opam-bundle\r") 2>/dev/null
fetch_branch "AltGr/opam-bundle"
opam pin . -yn
opam install opam-bundle --deps-only opam-client.to-test
make || { opam reinstall opam-client -y; make; }
(set +x ; echo -en "::endgroup::depends-opam-bundle\r") 2>/dev/null

# opam-custom-install
(set +x; echo -en "::group::depends-opam-custom-install\r") 2>/dev/null
fetch_branch "AltGr/opam-custom-install"
opam pin . -yn --ignore-pin-depends
opam install opam-custom-install --deps-only opam-client.to-test
dune build || { opam reinstall opam-client -y; dune build; }
(set +x ; echo -en "::endgroup::depends-opam-custom-install\r") 2>/dev/null

fi

0 comments on commit 1a503f3

Please sign in to comment.