Files
chromebrew/.github/workflows/Unit-Test.yml
Satadru Pramanik, DO, MPH, MEng b58b9b6231 Use M143 container based images in workflows as appropriate. (#14135)
Signed-off-by: Satadru Pramanik <satadru@gmail.com>
2026-01-12 01:47:26 +00:00

337 lines
18 KiB
YAML

---
name: Unit Tests
on:
check_run:
types:
- created
merge_group:
pull_request:
types:
- opened
- ready_for_review
- reopened
- synchronize
workflow_dispatch:
workflow_run:
workflows: [Generate PR]
types:
- completed
jobs:
setup:
if: ${{ ( github.repository_owner == 'chromebrew' ) }}
runs-on: ubuntu-24.04
outputs:
timestamp: ${{ steps.set-timestamp.outputs.TIMESTAMP }} # https://stackoverflow.com/a/75142892
current_head: ${{ steps.get-current-head.outputs.CURRENT_HEAD }}
changed_packages: ${{ steps.changed-packages.outputs.CHANGED_PACKAGES }}
glibc_232_compat: ${{ steps.get-compatibility.outputs.GLIBC_232_COMPATIBLE_PACKAGES }}
glibc_237_compat: ${{ steps.get-compatibility.outputs.GLIBC_237_COMPATIBLE_PACKAGES }}
i686_packages: ${{ steps.get-compatibility.outputs.i686_PACKAGES }}
x86_64_packages: ${{ steps.get-compatibility.outputs.x86_64_PACKAGES }}
armv7l_packages: ${{ steps.get-compatibility.outputs.armv7l_PACKAGES }}
matrix: ${{ steps.set-generate-matrix.outputs.matrix }}
steps:
- name: Set Timestamp
id: set-timestamp
run: |
TIMESTAMP="$(date -u +%F-%H%Z)"
export TIMESTAMP
echo "TIMESTAMP=${TIMESTAMP}" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v5
with:
fetch-depth: 0
persist-credentials: true
- name: Get Current HEAD hash
id: get-current-head
run: |
echo "CURRENT_HEAD=$(git ls-remote https://github.com/${{ github.repository }}.git | head -1 | sed 's/HEAD//')" >> "$GITHUB_OUTPUT"
echo "CURRENT_HEAD is $(git ls-remote https://github.com/${{ github.repository }}.git | head -1 | sed 's/HEAD//')"
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v47
with:
base_sha: ${{ steps.get-current-head.outputs.CURRENT_HEAD }}
files_yaml: |
packages:
- packages/*.rb
since_last_remote_commit: true
- name: Export variables to github context
id: changed-packages
run: |
if [[ -z "${{ steps.changed-files.outputs.packages_all_changed_files }}" ]]; then
echo "Branch ${{ github.ref_name }} has no changed package files."
fi
# Convert "packages/foo.rb packages/bar.rb" (from steps.changed-files.outputs.packages_all_changed_files) into "foo bar"
echo "CHANGED_PACKAGES=$(echo "${{ steps.changed-files.outputs.packages_all_changed_files }}" | xargs basename -s .rb | xargs)" >> "$GITHUB_ENV"
echo "CHANGED_PACKAGES=$(echo "${{ steps.changed-files.outputs.packages_all_changed_files }}" | xargs basename -s .rb | xargs)" >> "$GITHUB_OUTPUT"
- name: Determine glibc and architecture package compatibility
id: get-compatibility
run: |
# 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)"
export GLIBC_232_COMPATIBLE_PACKAGES
if [[ -n ${GLIBC_232_COMPATIBLE_PACKAGES} ]]; then
echo "GLIBC_232_COMPATIBLE_PACKAGES=${GLIBC_232_COMPATIBLE_PACKAGES}" >> "$GITHUB_ENV"
echo "GLIBC_232_COMPATIBLE_PACKAGES=${GLIBC_232_COMPATIBLE_PACKAGES}" >> "$GITHUB_OUTPUT"
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)"
export GLIBC_237_COMPATIBLE_PACKAGES
if [[ -n ${GLIBC_237_COMPATIBLE_PACKAGES} ]]; then
echo "GLIBC_237_COMPATIBLE_PACKAGES=${GLIBC_237_COMPATIBLE_PACKAGES}" >> "$GITHUB_ENV"
echo "GLIBC_237_COMPATIBLE_PACKAGES=${GLIBC_237_COMPATIBLE_PACKAGES}" >> "$GITHUB_OUTPUT"
echo "Branch ${{ github.ref_name }} 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)"
export x86_64_PACKAGES
if [[ -n ${x86_64_PACKAGES} ]]; then
echo "x86_64_PACKAGES=${x86_64_PACKAGES}" >> "$GITHUB_ENV"
echo "x86_64_PACKAGES=${x86_64_PACKAGES}" >> "$GITHUB_OUTPUT"
echo "Branch ${{ github.ref_name }} 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)"
export armv7l_PACKAGES
if [[ -n ${armv7l_PACKAGES} ]]; then
echo "armv7l_PACKAGES=${armv7l_PACKAGES}" >> "$GITHUB_ENV"
echo "armv7l_PACKAGES=${armv7l_PACKAGES}" >> "$GITHUB_OUTPUT"
echo "Branch ${{ github.ref_name }} 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)"
export i686_PACKAGES
if [[ -n ${i686_PACKAGES} ]]; then
echo "i686_PACKAGES=${i686_PACKAGES}" >> "$GITHUB_ENV"
echo "i686_PACKAGES=${i686_PACKAGES}" >> "$GITHUB_OUTPUT"
echo "Branch ${{ github.ref_name }} has these i686 compatible packages: ${i686_PACKAGES}"
fi
- name: Generate Creation Matrix
id: set-generate-matrix
env:
i686_PACKAGES: ${{ steps.get-compatibility.outputs.i686_PACKAGES }}
x86_64_PACKAGES: ${{ steps.get-compatibility.outputs.x86_64_PACKAGES }}
armv7l_PACKAGES: ${{ steps.get-compatibility.outputs.armv7l_PACKAGES }}
run: |
function join_by { local IFS="$1"; shift; echo "$*"; }
[[ -n "${i686_PACKAGES}" ]] && export CONTAINER_ARCH+=( "\"i686\"" )
# Always run on x86_64
export CONTAINER_ARCH+=( "\"x86_64\"" )
[[ -n "${armv7l_PACKAGES}" ]] && export CONTAINER_ARCH+=( "\"armv7l\"" )
export ARCHES="$(join_by , "${CONTAINER_ARCH[@]}")"
echo "matrix=[${ARCHES}]" >> $GITHUB_OUTPUT
echo "matrix=[${ARCHES}]"
container_tests:
if: ${{ github.repository_owner == 'chromebrew' }}
needs: setup
strategy:
fail-fast: false
matrix:
arch: ${{ fromJSON(needs.setup.outputs.matrix) }}
runner:
- ubuntu-24.04
- ubuntu-24.04-arm
exclude:
- arch: x86_64
runner: ubuntu-24.04-arm
- arch: i686
runner: ubuntu-24.04-arm
- arch: armv7l
runner: ubuntu-24.04
runs-on: ${{ matrix.runner }}
concurrency:
group: ${{ matrix.arch }}-${{ github.workflow }}-${{ github.ref }}-${{ github.sha }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v5
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@v47
with:
base_sha: ${{ github.event.pull_request.head.sha }}
files_ignore: |
.github/**
manifest/**
packages/*.rb
tools/packages.yaml
tools/repology.json
- name: Get all changed package files
id: changed-ruby-files
uses: tj-actions/changed-files@v47
with:
base_sha: ${{ github.event.pull_request.head.sha }}
files: packages/*.rb
since_last_remote_commit: true
- 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 branch updates packages with appropriate minimum glibc.
if [[ $GLIBC_232_COMPATIBLE_PACKAGES ]]; then
echo "CONTAINER=satmandu/crewbuild:nocturne-x86_64.m97" >> "$GITHUB_ENV"
elif [[ $GLIBC_237_COMPATIBLE_PACKAGES ]]; then
echo "CONTAINER=satmandu/crewbuild:hatch-x86_64.m143" >> "$GITHUB_ENV"
else
echo "CONTAINER=satmandu/crew-pre-glibc-standalone: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 branch updates packages with appropriate minimum glibc.
if [[ $GLIBC_232_COMPATIBLE_PACKAGES ]]; then
echo "CONTAINER=satmandu/crewbuild:fievel-armv7l.m97" >> "$GITHUB_ENV"
elif [[ $GLIBC_237_COMPATIBLE_PACKAGES ]]; then
echo "CONTAINER=satmandu/crewbuild:strongbad-armv7l.m143" >> "$GITHUB_ENV"
else
echo "CONTAINER=satmandu/crew-pre-glibc-standalone: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=satmandu/crew-pre-glibc-standalone: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}" "${CONTAINER}"
# See https://github.com/containerd/containerd/pull/7566#issuecomment-1461134737 for why we set ulimit.
docker run \
--rm \
--platform "${PLATFORM}" \
-e CHANGED_PACKAGES="${CHANGED_PACKAGES}" \
-e NON_PKG_CHANGED_FILES="${NON_PKG_CHANGED_FILES}" \
-e GCONV_PATH="/usr/local/lib${LIB_SUFFIX}/gconv" \
-e CREW_REPO="${CREW_REPO}" \
-e CREW_BRANCH="${CREW_BRANCH}" \
--tmpfs /tmp \
--ulimit "nofile=$(ulimit -Sn):$(ulimit -Hn)" \
"${CONTAINER}" \
/bin/chromebrewstart /usr/local/lib/crew/tests/unit_test_stub.sh
fi
container_test_check:
runs-on: ubuntu-24.04-arm
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"