Files
chromebrew/.github/workflows/Unit-Test.yml
2024-09-05 19:53:26 -04:00

128 lines
7.3 KiB
YAML

---
name: Run Unit Tests on PR
on: workflow_call
jobs:
container_tests:
strategy:
matrix:
arch: [x86_64, armv7l, i686]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Dump github context
run: echo "$GITHUB_CONTEXT"
- name: Set up QEMU
if: matrix.arch == 'armv7l'
uses: docker/setup-qemu-action@v3.2.0
- name: Get non-pkg changed files
id: non-pkg-changed-files
uses: tj-actions/changed-files@v45
with:
files_ignore: packages/*.rb
- name: Get all changed package files
id: changed-ruby-files
uses: tj-actions/changed-files@v45
with:
files: packages/*.rb
- name: Export variables to github context
run: |
# Convert "packages/foo.rb packages/bar.rb" (from steps.changed-ruby-files.outputs.all_changed_files) into "foo bar"
echo "CHANGED_PACKAGES=$(echo "${{ steps.changed-ruby-files.outputs.all_changed_files }}" | xargs basename -s .rb | xargs)" >> $GITHUB_ENV
echo "NON_PKG_CHANGED_FILES=$(echo "${{ steps.non-pkg-changed-files.outputs.all_changed_files }}" | xargs)" >> $GITHUB_ENV
- name: Determine glibc and architecture package compatibility
run: |
# If a package doesnt have a min_glibc value, or if its below 2.27, add it to GLIBC_227_COMPATIBLE_PACKAGES.
export GLIBC_227_COMPATIBLE_PACKAGES="$(for i in ${CHANGED_PACKAGES} ; do if grep -q min_glibc packages/${i}.rb; then grep min_glibc packages/${i}.rb | tr -d \' | awk '{exit $2 <= 2.27}' || echo ${i} ; else echo ${i} ; fi ; done | xargs -r)"
if [[ -n ${GLIBC_227_COMPATIBLE_PACKAGES} ]]; then
echo "GLIBC_227_COMPATIBLE_PACKAGES=${GLIBC_227_COMPATIBLE_PACKAGES}" >> $GITHUB_ENV
echo "PR #${{ github.event.pull_request.number }} has these possibly Glibc 2.27 compatible packages: ${GLIBC_227_COMPATIBLE_PACKAGES}"
fi
# If a package doesnt have a min_glibc value, or if its below 2.37, add it to GLIBC_237_COMPATIBLE_PACKAGES.
export GLIBC_237_COMPATIBLE_PACKAGES="$(for i in ${CHANGED_PACKAGES} ; do grep min_glibc packages/${i}.rb | tr -d \' | awk '{exit $2 <= 2.37}' || echo ${i} ; done | xargs)"
if [[ -n ${GLIBC_237_COMPATIBLE_PACKAGES} ]]; then
echo "GLIBC_237_COMPATIBLE_PACKAGES=${GLIBC_237_COMPATIBLE_PACKAGES}" >> $GITHUB_ENV
echo "PR #${{ github.event.pull_request.number }} has these possibly Glibc 2.37 compatible packages: ${GLIBC_237_COMPATIBLE_PACKAGES}"
fi
# If a package has a compatibility of 'all' or one that includes 'x86_64', add it to x86_64_PACKAGES.
export x86_64_PACKAGES="$(for i in ${CHANGED_PACKAGES}; do grep -q "[[:space:]]compatibility.*all\|[[:space:]]compatibility.*x86_64" packages/${i}.rb && echo ${i}; done | xargs)"
if [[ -n ${x86_64_PACKAGES} ]]; then
echo "x86_64_PACKAGES=${x86_64_PACKAGES}" >> $GITHUB_ENV
echo "PR #${{ github.event.pull_request.number }} has these x86_64 compatible packages: ${x86_64_PACKAGES}"
fi
## If a package has a compatibility of 'all' or one that includes 'armv7l', add it to ARMV7L_PACKAGES.
export ARMV7L_PACKAGES="$(for i in ${CHANGED_PACKAGES}; do grep -q "[[:space:]]compatibility.*all\|[[:space:]]compatibility.*armv7l" packages/${i}.rb && echo ${i}; done | xargs)"
if [[ -n ${ARMV7L_PACKAGES} ]]; then
echo "ARMV7L_PACKAGES=${ARMV7L_PACKAGES}" >> $GITHUB_ENV
echo "PR #${{ github.event.pull_request.number }} has these armv7l compatible packages: ${ARMV7L_PACKAGES}"
fi
## If a package has a compatibility of 'all' or one that includes 'i686', add it to i686_PACKAGES.
export i686_PACKAGES="$(for i in ${CHANGED_PACKAGES}; do grep -q "[[:space:]]compatibility.*all\|[[:space:]]compatibility.*i686" packages/${i}.rb && echo ${i}; done | xargs)"
if [[ -n ${i686_PACKAGES} ]]; then
echo "i686_PACKAGES=${i686_PACKAGES}" >> $GITHUB_ENV
echo "PR #${{ github.event.pull_request.number }} has these i686 compatible packages: ${i686_PACKAGES}"
fi
- name: Export target docker container to github context
env:
TARGET_ARCH: ${{ matrix.arch }}
run: |
case $TARGET_ARCH in
x86_64)
# Export the x86_64 container depending on whether this PR updates packages with a minimum glibc greater than or equal to 2.37.
if [[ $GLIBC_237_COMPATIBLE_PACKAGES ]]; then
echo "CONTAINER=hatch-x86_64.m126" >> $GITHUB_ENV
else
echo "CONTAINER=nocturne-x86_64.m90" >> $GITHUB_ENV
fi
echo "PLATFORM=linux/amd64" >> $GITHUB_ENV
echo "LIB_SUFFIX=64" >> $GITHUB_ENV
;;
armv7l)
# Export the armv7l container depending on whether this PR updates packages with a minimum glibc greater than or equal to 2.37.
if [[ $GLIBC_237_COMPATIBLE_PACKAGES ]]; then
echo "CONTAINER=strongbad-armv7l.m126" >> $GITHUB_ENV
else
echo "CONTAINER=fievel-armv7l.m91" >> $GITHUB_ENV
fi
echo "PLATFORM=linux/arm/v7" >> $GITHUB_ENV
echo "LIB_SUFFIX=" >> $GITHUB_ENV
;;
i686)
# There is only one i686 container based upon M58 with glibc 2.23.
echo "CONTAINER=alex-i686.m58" >> $GITHUB_ENV
echo "PLATFORM=linux/386" >> $GITHUB_ENV
echo "LIB_SUFFIX=" >> $GITHUB_ENV
;;
esac
- name: Run unit tests
run: |
if [[ -z ${NON_PKG_CHANGED_FILES} ]] && [[ $PLATFORM == 'linux/arm/v7' ]] && [[ -z ${ARMV7L_PACKAGES} ]]; then
# Run the arm container if there are non-package changed files,
# but otherwise do not run the arm container if there are no packages compatible with armv7l.
exit 0
fi
if [[ -z ${NON_PKG_CHANGED_FILES} ]] && [[ $PLATFORM == 'linux/amd64' ]] && [[ -z ${x86_64_PACKAGES} ]]; then
# Run the x86_64 container if there are non-package changed files,
# but otherwise do not run the x86_64 container if there are no packages compatible with x86_64.
exit 0
fi
if [[ -z ${NON_PKG_CHANGED_FILES} ]] && [[ $PLATFORM == 'linux/386' ]] && [[ -z ${i686_PACKAGES} ]]; then
# Run the i686 container if there are non-package changed files,
# but otherwise do not run the i686 container if there are no packages compatible with i686.
exit 0
fi
sudo docker run \
--platform $PLATFORM \
-v "${{ github.workspace }}/tests/unit_test.sh:/unit_test.sh" \
-u chronos \
-e CHANGED_PACKAGES="$CHANGED_PACKAGES" \
-e LD_LIBRARY_PATH="/usr/local/lib$LIB_SUFFIX" \
-e GCONV_PATH="/usr/local/lib$LIB_SUFFIX/gconv" \
-e CREW_REPO="${{ github.event.pull_request.head.repo.clone_url }}" \
-e CREW_BRANCH="${{ github.head_ref }}" \
"satmandu/crewbuild:$CONTAINER" \
/usr/local/bin/bash /unit_test.sh