Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Convert tests to native github CI. #295

Merged
merged 6 commits into from
Jan 15, 2024
Merged
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
111 changes: 107 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,117 @@ jobs:
with:
access_token: ${{ github.token }}

test:
build_details:
runs-on: ubuntu-latest
outputs:
packages: ${{ steps.packages.outputs.packages }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Grab packages to build
id: packages
run: |
PACKAGES_TO_RUN=$(OUTPUT_ONLY=true ./tests/run_tests.sh | while read i; do echo "\\\"$i\\\""; done | xargs | sed -e 's# #,#g' | tr -d '\n')
echo "Packages to run: ${PACKAGES_TO_RUN}"
echo "packages=[${PACKAGES_TO_RUN}]" >> "${GITHUB_OUTPUT}"

build_package:
runs-on: ubuntu-latest
needs: build_details
strategy:
matrix:
package: ${{ fromJson(needs.build_details.outputs.packages) }}
arch: [x64, x86]
ocaml_version: [4.14.1]
container:
image: ocamlcross/windows-${{ matrix.arch }}-base:${{ matrix.ocaml_version }}
options: --user root
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Build package
env:
PKG_CONFIG_PATH: ${{ matrix.arch == 'x64' && '/usr/src/mxe/usr/x86_64-w64-mingw32.static/lib/pkgconfig/' || '/usr/src/mxe/usr/i686-w64-mingw32.static/lib/pkgconfig/' }}
run: |
rm -rf /home/opam/opam-cross-windows/packages /home/opam/opam-cross-windows/repo
mv packages /home/opam/opam-cross-windows
mv repo /home/opam/opam-cross-windows
sudo -u opam opam update
sudo -u opam opam list --short --recursive --external --vars os-distribution=mxe,os-family=mingw --required-by=${{ matrix.package }} > /home/opam/mxe-deps
if [ -s /home/opam/mxe-deps ]; then
cd /usr/src/mxe/ && cat /home/opam/mxe-deps | xargs make
fi
eval $(sudo -u opam opam env)
sudo -u opam opam reinstall --verbose -y ${{ matrix.package }}
- name: Export revdeps
id: revdeps
if: matrix.arch == 'x64'
run: |
eval $(sudo -u opam opam env)
REVDEPS_TO_BUILD=$(sudo -u opam opam list --rec --short --sort --depends-on=${{ matrix.package }} | while read i; do echo "\\\"$i\\\""; done | xargs | sed -e 's# #,#g' | tr -d '\n')
echo "Revdeps to build: ${REVDEPS_TO_BUILD}"
echo "revdeps=[${REVDEPS_TO_BUILD}]" >> "${GITHUB_OUTPUT}"
- name: Write matrix output
if: matrix.arch == 'x64'
id: matrix_output
uses: cloudposse/github-action-matrix-outputs-write@main
with:
matrix-step-name: ${{ github.job }}
matrix-key: ${{ matrix.package }}
outputs: |-
revdeps: ${{ steps.revdeps.outputs.revdeps }}

collect_revdeps:
runs-on: ubuntu-latest
needs: [build_package]
outputs:
revdeps: ${{ steps.revdeps.outputs.revdeps }}
has_revdeps: ${{ steps.revdeps.outputs.has_revdeps }}
steps:
- name: Collect revdeps
uses: cloudposse/github-action-matrix-outputs-read@main
id: collect_revdeps
with:
matrix-step-name: build_package
- name: Export all revdeps
uses: satackey/[email protected]
id: revdeps
with:
script: |
const core = require("@actions/core")
const { revdeps } = JSON.parse('${{ steps.collect_revdeps.outputs.result }}')
const result = Object.keys(revdeps).reduce((result, key) =>
[...result, ...revdeps[key]], []);
console.log(`Collected revdeps: ${result}`);
core.setOutput("revdeps", JSON.stringify(result));
core.setOutput("has_revdeps", result.length !== 0);

build_revdeps:
runs-on: ubuntu-latest
needs: collect_revdeps
if: needs.collect_revdeps.outputs.has_revdeps == 'true'
strategy:
fail-fast: false
matrix:
package: ${{ fromJson(needs.collect_revdeps.outputs.revdeps) }}
arch: [x64, x86]
ocaml_version: [4.14.1]
container:
image: ocamlcross/windows-${{ matrix.arch }}-base:${{ matrix.ocaml_version }}
options: --user root
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run tests
run: VERBOSE=1 SYSTEM_TYPE=${{ matrix.arch }} ./tests/run_tests.sh
- name: Build revdep
env:
PKG_CONFIG_PATH: ${{ matrix.arch == 'x64' && '/usr/src/mxe/usr/x86_64-w64-mingw32.static/lib/pkgconfig/' || '/usr/src/mxe/usr/i686-w64-mingw32.static/lib/pkgconfig/' }}
run: |
rm -rf /home/opam/opam-cross-windows/packages /home/opam/opam-cross-windows/repo
mv packages /home/opam/opam-cross-windows
mv repo /home/opam/opam-cross-windows
sudo -u opam opam update
sudo -u opam opam list --short --recursive --external --vars os-distribution=mxe,os-family=mingw --required-by=${{ matrix.package }} > /home/opam/mxe-deps
if [ -s /home/opam/mxe-deps ]; then
cd /usr/src/mxe/ && cat /home/opam/mxe-deps | xargs make
fi
eval $(sudo -u opam opam env)
sudo -u opam opam reinstall --verbose -y ${{ matrix.package }}
63 changes: 38 additions & 25 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/sh

# Set OUTPUT_ONLY env variable to only output packages to rebuild.

TEST_PWD=$(cd `dirname $0` && pwd)
BASE_PWD=$(cd ${TEST_PWD}/.. && pwd)

Expand Down Expand Up @@ -51,21 +53,23 @@ SKIPPED="${SKIPPED} lwt-zmq-windows.2.1.0 zmq-windows.4.0-7"

PRETEST_IMAGE="ocamlcross/windows-${SYSTEM_TYPE}-pretest:${OCAML_VERSION}"

printf "Building ${PRETEST_IMAGE}.."
DOCKER_CMD="docker build --no-cache -f ${TEST_PWD}/Dockerfile.pretest \
--build-arg \"IMAGE=${BASE_IMAGE}\" -t \"${PRETEST_IMAGE}\" ${BASE_PWD}"
if [ -z "${OUTPUT_ONLY}" ]; then
printf "Building ${PRETEST_IMAGE}.."
DOCKER_CMD="docker build --no-cache -f ${TEST_PWD}/Dockerfile.pretest \
--build-arg \"IMAGE=${BASE_IMAGE}\" -t \"${PRETEST_IMAGE}\" ${BASE_PWD}"

if [ -n "${VERBOSE}" ]; then
echo ""
/bin/sh -c "${DOCKER_CMD}"
else
/bin/sh -c "${DOCKER_CMD} >/dev/null"
fi
if [ -n "${VERBOSE}" ]; then
echo ""
/bin/sh -c "${DOCKER_CMD}"
else
/bin/sh -c "${DOCKER_CMD} >/dev/null"
fi

if [ "$?" -ne "0" ]; then
printf "\033[0;31m[failed]\033[0m🚫🚫 \n"
else
printf "\033[0;32m[ok]\033[0m✅ \n"
if [ "$?" -ne "0" ]; then
printf "\033[0;31m[failed]\033[0m🚫🚫 \n"
else
printf "\033[0;32m[ok]\033[0m✅ \n"
fi
fi

build_package() {
Expand All @@ -74,32 +78,41 @@ build_package() {
echo "${SKIPPED}" | grep "${PACKAGE}" >/dev/null 2>&1

if [ "$?" -eq "0" ]; then
printf "Building ${PACKAGE}.. \033[1;33m[skipped]\033[0m⚠️\n"
if [ -n "${OUTPUT_ONLY}" ]; then
exit 0
else
printf "Building ${PACKAGE}.. \033[1;33m[skipped]\033[0m⚠️\n"
fi
else
SYSTEM_TYPE="${SYSTEM_TYPE}" OCAML_VERSION="${OCAML_VERSION}" ${TEST_PWD}/run_test.sh "${PACKAGE}"

if [ "$?" -ne "0" ]; then
exit 128
if [ -n "${OUTPUT_ONLY}" ]; then
echo "${PACKAGE}"
exit 0
else
SYSTEM_TYPE="${SYSTEM_TYPE}" OCAML_VERSION="${OCAML_VERSION}" ${TEST_PWD}/run_test.sh "${PACKAGE}"

if [ "$?" -ne "0" ]; then
exit 128
fi
fi
fi
}

PACKAGES=$(cd ${BASE_PWD}/packages && find . -maxdepth 2 -mindepth 2 -type d | cut -d '/' -f 3 | sort -u)

echo ""
git remote set-branches origin '*'
git fetch origin main
echo ""
git remote set-branches origin '*' >/dev/null 2>&1
git fetch origin main >/dev/null 2>&1

echo "${PACKAGES}" | while read PACKAGE; do
if [ -n "${WORLD}" ]; then
build_package "${PACKAGE}"
else
PACKAGE_DIR=`echo ${PACKAGE} | cut -d'.' -f 1`
RET=$(cd "${BASE_PWD}/packages/${PACKAGE_DIR}/${PACKAGE}" && git diff --name-only HEAD origin/main .)
if [ -d "${BASE_PWD}/packages/${PACKAGE_DIR}/${PACKAGE}" ]; then
RET=$(cd "${BASE_PWD}/packages/${PACKAGE_DIR}/${PACKAGE}" && git diff --name-only HEAD origin/main .)

if [ -n "${RET}" ]; then
build_package "${PACKAGE}"
if [ -n "${RET}" ]; then
build_package "${PACKAGE}"
fi
fi
fi
done
Expand Down
Loading