mirror of
https://github.com/chromebrew/chromebrew.git
synced 2026-05-01 03:00:26 -04:00
226 lines
9.6 KiB
YAML
226 lines
9.6 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 }}
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
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"
|
|
|
|
get-compatibility:
|
|
needs: setup
|
|
uses: ./.github/workflows/Determine-Compatibility.yml
|
|
with:
|
|
changed_packages: ${{ needs.setup.outputs.changed_packages }}
|
|
|
|
gen-matrix:
|
|
needs: get-compatibility
|
|
runs-on: ubuntu-24.04
|
|
outputs:
|
|
matrix: ${{ steps.set-generate-matrix.outputs.matrix }}
|
|
steps:
|
|
- name: Generate Creation Matrix
|
|
id: set-generate-matrix
|
|
env:
|
|
i686_PACKAGES: ${{ needs.get-compatibility.outputs.i686_PACKAGES }}
|
|
x86_64_PACKAGES: ${{ needs.get-compatibility.outputs.x86_64_PACKAGES }}
|
|
armv7l_PACKAGES: ${{ needs.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:
|
|
- gen-matrix
|
|
- get-compatibility
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
arch: ${{ fromJSON(needs.gen-matrix.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@v6
|
|
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: Export target docker container to github context
|
|
run: |
|
|
case ${{ matrix.arch }} in
|
|
x86_64)
|
|
# Export the x86_64 container depending on whether this branch updates packages with appropriate minimum glibc.
|
|
if [[ -n "${{ needs.get-compatibility.outputs.glibc_232_compat }}" ]]; then
|
|
echo "CONTAINER=satmandu/crewbuild:nocturne-x86_64.m97" >> "$GITHUB_ENV"
|
|
elif [[ -n "${{ needs.get-compatibility.outputs.glibc_237_compat }}" ]]; then
|
|
echo "CONTAINER=satmandu/crewbuild:hatch-x86_64.m145" >> "$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 [[ -n "${{ needs.get-compatibility.outputs.glibc_232_compat }}" ]]; then
|
|
echo "CONTAINER=satmandu/crewbuild:fievel-armv7l.m97" >> "$GITHUB_ENV"
|
|
elif [[ -n "${{ needs.get-compatibility.outputs.glibc_237_compat }}" ]]; then
|
|
echo "CONTAINER=satmandu/crewbuild:strongbad-armv7l.m145" >> "$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 "${{ needs.get-compatibility.outputs.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 "${{ needs.get-compatibility.outputs.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 "${{ needs.get-compatibility.outputs.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"
|