--- name: Run Unit Tests on PR on: workflow_call jobs: container_tests: strategy: matrix: arch: [x86_64, armv7l, i686] runner: [self-hosted, ubuntu-latest] runs-on: ${{ matrix.runner }} steps: - name: Exit quickly if on wrong runner. id: runner_check run: | arch="${{ matrix.arch }}" runner="${{ matrix.runner }}" echo "matrix arch is $arch" echo "matrix runner is $runner" [[ $arch == 'armv7l' ]] && [[ $runner == 'ubuntu-latest' ]] && export exitquick=1 [[ $arch != 'armv7l' ]] && [[ $runner == 'self-hosted' ]] && export exitquick=1 if [[ -n $exitquick ]]; then echo "exiting" echo "skipnext=true" >> $GITHUB_OUTPUT else echo "not exiting" fi - uses: actions/checkout@v4 if: ( steps.runner_check.outputs.skipnext != 'true' ) - name: Dump github context if: ( steps.runner_check.outputs.skipnext != 'true' ) run: echo "$GITHUB_CONTEXT" - name: Get non-pkg changed files id: non-pkg-changed-files if: ( steps.runner_check.outputs.skipnext != 'true' ) uses: tj-actions/changed-files@v45 with: files_ignore: packages/*.rb - name: Get all changed package files id: changed-ruby-files if: ( steps.runner_check.outputs.skipnext != 'true' ) uses: tj-actions/changed-files@v45 with: files: packages/*.rb - name: Export variables to github context if: ( steps.runner_check.outputs.skipnext != 'true' ) 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 if: ( steps.runner_check.outputs.skipnext != 'true' ) 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 if: ( steps.runner_check.outputs.skipnext != 'true' ) 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.m128" >> $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.m128" >> $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 if: ( steps.runner_check.outputs.skipnext != 'true' ) 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 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="${{ github.event.pull_request.head.repo.clone_url }}" \ -e CREW_BRANCH="${{ github.head_ref }}" \ "satmandu/crewbuild:$CONTAINER" \ /bin/chromebrewstart /usr/local/lib/crew/tests/unit_test.sh