Files
chromebrew/.github/workflows/Unit-Test.yml
Satadru Pramanik, DO, MPH, MEng b48a54d193 Adjust workflows to use M132 based containers instead of M131 based containers. (#11238)
* Adjust workflows to use M132 based containers when newer containers are needed.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* lint

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* lint

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* lint

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* lint

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

---------

Signed-off-by: Satadru Pramanik <satadru@gmail.com>
2025-02-03 21:18:41 +00:00

218 lines
10 KiB
YAML

---
name: Unit Tests
on:
check_run:
types:
- created
merge_group:
pull_request:
# push:
workflow_dispatch:
# workflow_run:
# workflows: [Build]
# types:
# - completed
jobs:
container_tests:
if: ${{ github.repository_owner == 'chromebrew' }}
strategy:
matrix:
arch: [x86_64, armv7l, i686]
runner:
- ubuntu-24.04
- [self-hosted, ARM]
exclude:
- arch: x86_64
runner: [self-hosted, ARM]
- arch: i686
runner: [self-hosted, ARM]
- arch: armv7l
runner: ubuntu-24.04
runs-on: ${{ matrix.runner }}
concurrency:
group: ${{ matrix.arch }}-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v4
with:
persist-credentials: true
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Dump job context
env:
JOB_CONTEXT: ${{ toJson(job) }}
run: echo "$JOB_CONTEXT"
- name: Dump steps context
env:
STEPS_CONTEXT: ${{ toJson(steps) }}
run: echo "$STEPS_CONTEXT"
- name: Dump runner context
env:
RUNNER_CONTEXT: ${{ toJson(runner) }}
run: echo "$RUNNER_CONTEXT"
- name: Dump strategy context
env:
STRATEGY_CONTEXT: ${{ toJson(strategy) }}
run: echo "$STRATEGY_CONTEXT"
- name: Dump matrix context
env:
MATRIX_CONTEXT: ${{ toJson(matrix) }}
run: echo "$MATRIX_CONTEXT"
- name: Get non-pkg changed files
id: non-pkg-changed-files
uses: tj-actions/changed-files@v45
with:
files_ignore: |
.github/**
manifest/**
packages/*.rb
tools/packages.yaml
tools/*.json
- 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.
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 it is below 2.32, add it to GLIBC_232_COMPATIBLE_PACKAGES.
GLIBC_232_COMPATIBLE_PACKAGES="$(for i in ${CHANGED_PACKAGES} ; do grep min_glibc packages/"${i}".rb | tr -d \' | awk '{exit $2 <= 2.32}' || echo "${i}" ; done | xargs)"
if [[ -n ${GLIBC_232_COMPATIBLE_PACKAGES} ]]; then
echo "GLIBC_232_COMPATIBLE_PACKAGES=${GLIBC_232_COMPATIBLE_PACKAGES}" >> "$GITHUB_ENV"
echo "Branch ${{ github.ref_name }} has these possibly Glibc 2.32 compatible packages: ${GLIBC_232_COMPATIBLE_PACKAGES}"
fi
# If a package doesnt have a min_glibc value, or if it is below 2.37, add it to GLIBC_237_COMPATIBLE_PACKAGES.
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.
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.
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.
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 appropriate minimum glibc.
if [[ $GLIBC_232_COMPATIBLE_PACKAGES ]]; then
echo "CONTAINER=nocturne-x86_64.m97" >> "$GITHUB_ENV"
elif [[ $GLIBC_237_COMPATIBLE_PACKAGES ]]; then
echo "CONTAINER=hatch-x86_64.m132" >> "$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 appropriate minimum glibc.
if [[ $GLIBC_232_COMPATIBLE_PACKAGES ]]; then
echo "CONTAINER=fievel-armv7l.m97" >> "$GITHUB_ENV"
elif [[ $GLIBC_237_COMPATIBLE_PACKAGES ]]; then
echo "CONTAINER=strongbad-armv7l.m132" >> "$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
env:
GITHUB_EVENT: ${{ github.event_name }}
HEAD_REF: ${{ github.head_ref }}
run: |
case $GITHUB_EVENT in
check_run | merge_group | push | workflow_run | workflow_dispatch)
CREW_REPO="${{ github.event.repository.clone_url }}"
export CREW_REPO
CREW_BRANCH="${{ github.ref_name }}"
export CREW_BRANCH
;;
pull_request)
CREW_REPO="${{ github.event.pull_request.head.repo.clone_url }}"
export CREW_REPO
CREW_BRANCH="${HEAD_REF}"
export CREW_BRANCH
;;
esac
if [ -z "${NON_PKG_CHANGED_FILES}" ] && { [ "$PLATFORM" == 'linux/arm/v7' ] && [ -z "${armv7l_PACKAGES}" ]; }; then
# Exit the arm container if there are neither non-package changed files nor armv7l compatible packages.
echo "Skipping armv7l container unit tests."
exit 0
elif [ -z "${NON_PKG_CHANGED_FILES}" ] && { [ "$PLATFORM" == 'linux/amd64' ] && [ -z "${x86_64_PACKAGES}" ]; }; then
# Exit the x86_64 container if there are neither non-package changed files nor x86_64 compatible packages.
echo "Skipping x86_64 container unit tests."
exit 0
elif [ -z "${NON_PKG_CHANGED_FILES}" ] && { [ "$PLATFORM" == 'linux/386' ] && [ -z "${i686_PACKAGES}" ]; }; then
# Exit the i686 container if there are neither non-package changed files nor i686 compatible packages.
echo "Skipping i686 container unit tests."
exit 0
else
docker pull --platform "${PLATFORM}" "satmandu/crewbuild:${CONTAINER}"
docker run \
--rm \
--platform "${PLATFORM}" \
--privileged \
-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="${CREW_REPO}" \
-e CREW_BRANCH="${CREW_BRANCH}" \
"satmandu/crewbuild:${CONTAINER}" \
/bin/chromebrewstart /usr/local/lib/crew/tests/unit_test_stub.sh
fi
container_test_check:
runs-on: ubuntu-24.04
needs:
- container_tests
if: ${{ !cancelled() }}
steps:
- name: fail if container_test jobs failed
if: ${{ contains(needs.*.result, 'failure') }}
run: exit 1
- run: echo "Container test jobs succeeded"