From 635857a1fd9c352762d014c18b1ce1c8ba151470 Mon Sep 17 00:00:00 2001 From: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com> Date: Tue, 5 Dec 2023 06:13:24 -0500 Subject: [PATCH] Rewrite GH workflows: (#175) * Build and use up-to-date container image when testing changes to CLP-core's dependencies. * Run unit tests after building CLP-core. * Improve dependency tracking to avoid unnecessary workflow runs. * Reformat workflow-related YAML files. --- .../clp-core-build-containers/action.yaml | 88 ++++++++ .../action.yaml | 45 ++++ .github/actions/clp-core-build/action.yaml | 52 ++--- .../clp-docker-build-push-action/action.yaml | 52 ----- .github/workflows/clp-core-build-macos.yaml | 52 +++-- .github/workflows/clp-core-build.yaml | 209 +++++++++++------- .../workflows/clp-dependency-image-build.yaml | 126 ----------- .../workflows/clp-execution-image-build.yaml | 48 ++-- .../Dockerfile | 0 .../Dockerfile | 0 .../build.sh | 0 .../Dockerfile | 0 .../build.sh | 0 components/core/tools/scripts/utils/README.md | 3 + .../scripts/utils/build-and-run-unit-tests.sh | 26 +++ 15 files changed, 361 insertions(+), 340 deletions(-) create mode 100644 .github/actions/clp-core-build-containers/action.yaml create mode 100644 .github/actions/clp-core-build-deps-and-binaries/action.yaml delete mode 100644 .github/actions/clp-docker-build-push-action/action.yaml delete mode 100644 .github/workflows/clp-dependency-image-build.yaml rename components/core/tools/docker-images/{clp-core-focal => clp-core-ubuntu-focal}/Dockerfile (100%) rename components/core/tools/docker-images/{clp-env-base-bionic => clp-env-base-ubuntu-bionic}/Dockerfile (100%) rename components/core/tools/docker-images/{clp-env-base-bionic => clp-env-base-ubuntu-bionic}/build.sh (100%) mode change 100755 => 100644 rename components/core/tools/docker-images/{clp-env-base-focal => clp-env-base-ubuntu-focal}/Dockerfile (100%) rename components/core/tools/docker-images/{clp-env-base-focal => clp-env-base-ubuntu-focal}/build.sh (100%) mode change 100755 => 100644 create mode 100755 components/core/tools/scripts/utils/build-and-run-unit-tests.sh diff --git a/.github/actions/clp-core-build-containers/action.yaml b/.github/actions/clp-core-build-containers/action.yaml new file mode 100644 index 000000000..4866761dd --- /dev/null +++ b/.github/actions/clp-core-build-containers/action.yaml @@ -0,0 +1,88 @@ +name: "clp-core-build-containers" +description: "Builds and publishes container images for CLP-core's dependencies and binaries" + +inputs: + os_name: + description: "Name of container OS" + required: true + clp_core_dir: + description: "CLP-core's component directory" + required: true + push_deps_image: + description: "Whether to publish a container image containing CLP's dependencies" + required: true + push_binaries_image: + description: "Whether to publish a container image containing CLP's binaries" + required: true + local_registry_port: + description: "Port number for the local registry" + required: true + token: + description: "Registry token" + required: true + +runs: + using: "composite" + steps: + - uses: "docker/setup-buildx-action@v3" + with: + driver-opts: "network=host" + + - if: "inputs.push_deps_image == 'true'" + uses: "docker/login-action@v3" + with: + registry: "ghcr.io" + username: "${{github.actor}}" + password: "${{inputs.token}}" + + - id: "get_deps_image_props" + shell: "bash" + run: | + if [[ "${{inputs.push_deps_image}}" == "true" ]] ; then + echo "REGISTRY=ghcr.io" >> "$GITHUB_OUTPUT" + echo "BRANCH=${{github.ref_name}}" >> "$GITHUB_OUTPUT" + else + echo "REGISTRY=localhost:${{inputs.local_registry_port}}" >> "$GITHUB_OUTPUT" + echo "BRANCH=latest" >> "$GITHUB_OUTPUT" + fi + + - id: "deps_image_meta" + uses: "docker/metadata-action@v5" + with: + images: "${{steps.get_deps_image_props.outputs.REGISTRY}}\ + /${{github.repository}}\ + /clp-core-dependencies-x86-${{inputs.os_name}}" + tags: | + type=raw,value=${{steps.get_deps_image_props.outputs.BRANCH}} + + - uses: "docker/build-push-action@v5" + with: + context: "${{inputs.clp_core_dir}}" + file: "${{inputs.clp_core_dir}}/tools/docker-images/clp-env-base-${{inputs.os_name}}\ + /Dockerfile" + push: true + tags: "${{steps.deps_image_meta.outputs.tags}}" + labels: "${{steps.deps_image_meta.outputs.labels}}" + + - uses: "./.github/actions/clp-core-build" + with: + image_name: "${{steps.deps_image_meta.outputs.tags}}" + + - if: "inputs.push_binaries_image == 'true'" + id: "core_image_meta" + uses: "docker/metadata-action@v5" + with: + images: "${{steps.get_deps_image_props.outputs.REGISTRY}}\ + /${{github.repository}}\ + /clp-core-x86-${{inputs.os_name}}" + tags: | + type=raw,value=${{steps.get_deps_image_props.outputs.BRANCH}} + + - if: "inputs.push_binaries_image == 'true'" + uses: "docker/build-push-action@v5" + with: + context: "${{inputs.clp_core_dir}}/build" + file: "${{inputs.clp_core_dir}}/tools/docker-images/clp-core-${{inputs.os_name}}/Dockerfile" + push: true + tags: "${{steps.core_image_meta.outputs.tags}}" + labels: "${{steps.core_image_meta.outputs.labels}}" diff --git a/.github/actions/clp-core-build-deps-and-binaries/action.yaml b/.github/actions/clp-core-build-deps-and-binaries/action.yaml new file mode 100644 index 000000000..133a1f78c --- /dev/null +++ b/.github/actions/clp-core-build-deps-and-binaries/action.yaml @@ -0,0 +1,45 @@ +name: "clp-core-build-deps-and-binaries" +description: >- + Builds a container image containing CLP-core's dependencies, builds CLP-core, + and runs CLP-core's unit tests. + +inputs: + os_name: + description: "Name of container OS" + required: true + deps_image_changed: + description: "Whether the dependencies Docker image files have changed" + required: true + push_binaries_image: + description: "Whether to publish a Docker image containing CLP's binaries" + required: true + local_registry_port: + description: "Port number for the local registry" + required: true + token: + description: "Container registry token" + required: true + +runs: + using: "composite" + steps: + - if: "inputs.deps_image_changed == 'true'" + uses: "./.github/actions/clp-core-build-containers" + with: + os_name: "${{inputs.os_name}}" + clp_core_dir: "components/core" + push_deps_image: >- + ${{github.event_name != 'pull_request' + && github.ref == 'refs/heads/main'}} + push_binaries_image: >- + ${{inputs.push_binaries_image == 'true' + && github.event_name != 'pull_request' + && github.ref == 'refs/heads/main'}} + local_registry_port: "${{inputs.local_registry_port}}" + token: "${{inputs.token}}" + + - if: "inputs.deps_image_changed == 'false'" + uses: "./.github/actions/clp-core-build" + with: + image_name: >- + ghcr.io/${{github.repository}}/clp-core-dependencies-x86-${{inputs.os_name}}:main diff --git a/.github/actions/clp-core-build/action.yaml b/.github/actions/clp-core-build/action.yaml index 890a34048..28a252146 100644 --- a/.github/actions/clp-core-build/action.yaml +++ b/.github/actions/clp-core-build/action.yaml @@ -1,41 +1,23 @@ -name: "Build CLP Core" -description: "Configures CMake and uses CMake to build CLP Core" +name: "clp-core-build" +description: "Builds CLP-core in the given container" inputs: - build_type: - description: "CLP CMake Build Type: Debug, Release, RelWithDebInfo and MinSizeRel" - required: false - default: Release - cmake_config_extra_args: - description: "Extra args to pass to CMake during configuration" - required: false - default: "" - + image_name: + description: "Container image to use" + required: true + runs: using: "composite" steps: + - shell: "bash" + working-directory: "./components/core" + run: "./tools/scripts/deps-download/download-all.sh" - - name: Download submodules - run: ./tools/scripts/deps-download/download-all.sh - working-directory: ./components/core - shell: bash - - - name: Configure CMake - # Configure CMake in a 'build' subdirectory - run: cmake -B $GITHUB_WORKSPACE/build - -DCMAKE_BUILD_TYPE=${{inputs.build_type}} - ${{inputs.cmake_config_extra_args}} - working-directory: ./components/core - shell: bash - - - name: Build - # Build your program with the given configuration - run: cmake --build $GITHUB_WORKSPACE/build --config ${{inputs.build_type}} - working-directory: ./components/core - shell: bash - - - name: Bundle Built Binaries - run: | - cd $GITHUB_WORKSPACE/build - tar -cf $GITHUB_WORKSPACE/clp-binaries-focal.tar ./clp ./clg ./clo ./make-dictionaries-readable - shell: bash + - shell: "bash" + run: >- + docker run + --user $(id -u):$(id -g) + --volume "$GITHUB_WORKSPACE/components/core":/mnt/clp + --workdir /mnt/clp + ${{inputs.image_name}} + /mnt/clp/tools/scripts/utils/build-and-run-unit-tests.sh . build diff --git a/.github/actions/clp-docker-build-push-action/action.yaml b/.github/actions/clp-docker-build-push-action/action.yaml deleted file mode 100644 index f36a19067..000000000 --- a/.github/actions/clp-docker-build-push-action/action.yaml +++ /dev/null @@ -1,52 +0,0 @@ -name: "Build and Push Docker Image" -description: "Pushes built Docker image to Github Packages" - -env: - REGISTRY: ghcr.io - -inputs: - image_name: - description: "Name of Docker image to be pushed" - required: true - context: - description: "Docker build context" - required: false - default: ./ - file: - description: "Dockerfile path" - required: false - default: ./Dockerfile - push_image: - description: "Whether to publish the Docker image" - required: true - default: "false" - - token: - description: "Registry token" - required: true - -runs: - using: "composite" - steps: - - - name: Log in to the Github Packages Container registry - uses: docker/login-action@v1 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ inputs.token }} - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v2 - with: - images: ${{ env.REGISTRY }}/${{ inputs.image_name }} - - - name: Build and push Docker image - uses: docker/build-push-action@v2 - with: - context: ${{inputs.context}} - file: ${{inputs.file}} - push: ${{inputs.push_image}} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/clp-core-build-macos.yaml b/.github/workflows/clp-core-build-macos.yaml index 2f759e8a6..e7f9f57b6 100644 --- a/.github/workflows/clp-core-build-macos.yaml +++ b/.github/workflows/clp-core-build-macos.yaml @@ -1,43 +1,49 @@ -name: build-clp-core-macos +name: "clp-core-build-macos" on: push: paths: - # NOTE: The order of these paths is important since we're using exclusions - - '.github/workflows/clp-core-build-macos.yaml' - - 'components/core/**' - - '!components/core/tools/docker-images/**' - - '!components/core/tools/scripts/lib_install/**' - - 'components/core/tools/scripts/lib_install/macos-12/**' - pull_request: - paths: - # NOTE: The order of these paths is important since we're using exclusions - - '.github/workflows/clp-core-build-macos.yaml' - - 'components/core/**' - - '!components/core/tools/docker-images/**' - - '!components/core/tools/scripts/lib_install/**' - - 'components/core/tools/scripts/lib_install/macos-12/**' + - ".github/workflows/clp-core-build-macos.yaml" + - "components/core/cmake/**" + - "components/core/CMakeLists.txt" + - "components/core/src/**" + - "components/core/tests/**" + - "components/core/tools/scripts/lib_install/macos-12/**" + - "components/core/tools/scripts/deps-download/**" + - "components/core/tools/scripts/utils/build-and-run-unit-tests.sh" workflow_dispatch: +concurrency: + group: "${{github.workflow}}-${{github.ref}}" + # Cancel in-progress jobs for efficiency + cancel-in-progress: true + jobs: build-macos: - runs-on: macos-12 + runs-on: "macos-12" steps: - - name: Checkout - uses: actions/checkout@v3 + - uses: "actions/checkout@v3" with: - submodules: recursive + submodules: "recursive" # See https://github.com/actions/setup-python/issues/577 - - name: Remove preinstalled binaries which conflict with brew's installs + - name: "Remove preinstalled binaries which conflict with brew's installs" run: | rm -f /usr/local/bin/2to3* rm -f /usr/local/bin/idle3* rm -f /usr/local/bin/pydoc3* rm -f /usr/local/bin/python3* - - name: Install dependencies + - name: "Install dependencies" run: ./components/core/tools/scripts/lib_install/macos-12/install-all.sh - - name: Build CLP Core - uses: ./.github/actions/clp-core-build + - name: "Download source dependencies" + shell: "bash" + working-directory: "./components/core" + run: "./tools/scripts/deps-download/download-all.sh" + + - name: "Build CLP-core and run unit tests" + shell: "bash" + working-directory: "./components/core" + # NOTE: We omit the Stopwatch tests since GH's macOS runner is too slow + run: "./tools/scripts/utils/build-and-run-unit-tests.sh . build ~[Stopwatch]" diff --git a/.github/workflows/clp-core-build.yaml b/.github/workflows/clp-core-build.yaml index a38b27578..75c254951 100644 --- a/.github/workflows/clp-core-build.yaml +++ b/.github/workflows/clp-core-build.yaml @@ -1,113 +1,152 @@ -name: build-clp-core +name: clp-core-build on: push: paths: - - '.github/workflows/clp-core-build.yaml' - - 'components/core/**' - - '!components/core/tools/scripts/lib_install/macos-12/**' - pull_request: - paths: - - '.github/workflows/clp-core-build.yaml' - - 'components/core/**' - - '!components/core/tools/scripts/lib_install/macos-12/**' + - ".github/actions/**" + - ".github/workflows/clp-core-build.yaml" + - "components/core/**" + - "!components/core/tools/scripts/lib_install/macos-12/**" workflow_dispatch: - workflow_run: - workflows: ["generate-build-dependency-image"] - branches: [main] - types: - - completed env: - REGISTRY: ghcr.io - IMAGE_NAME_BASE: ${{github.repository}}/clp-core-x86 + # Consider changes between the current commit and `main` + # NOTE: If a pull request changes the image, then we need to build the image and then build + # CLP using the changed image; otherwise we can build CLP using the published image. So when + # determining what files have changed, we use `main` rather than the previous commit to ensure + # that on every push to the PR, we can detect if the image was changed and use it to build + # and test CLP. + PATHS_FILTER_BASE: "main" + PATHS_FILTER_LIB_INSTALL_GLOB: "components/core/tools/scripts/lib_install/*.sh" + PATHS_FILTER_CLP_FILTER: | + clp: + - ".github/actions/**" + - ".github/workflows/clp-core-build.yaml" + - ".gitmodules" + - "components/core/cmake/**" + - "components/core/CMakeLists.txt" + - "components/core/src/**" + - "components/core/tests/**" + - "components/core/tools/scripts/deps-download/**" + - "components/core/tools/scripts/utils/build-and-run-unit-tests.sh" -concurrency: build-${{github.ref}} +# Currency group to prevent multiple workflow instances from trying to publish container images +concurrency: "${{github.workflow}}-${{github.ref}}" jobs: - build-focal: - runs-on: ubuntu-latest - container: - image: ghcr.io/y-scope/clp/clp-core-dependencies-x86-ubuntu-focal:main - volumes: - - ${{github.workspace}}/build:/output + centos74: + runs-on: "ubuntu-latest" + services: + registry: + image: "registry:2" + ports: [ "5000:5000" ] + env: + OS_NAME: "centos7.4" steps: - - name: Checkout - uses: actions/checkout@v3 + - uses: "actions/checkout@v3" with: - submodules: recursive + submodules: "recursive" + + - name: "Work around actions/runner-images/issues/6775" + run: "chown $(id -u):$(id -g) -R ." + shell: "bash" - - name: Workaround actions/runner-images/issues/6775 - run: chown $(id -u):$(id -g) -R . + - name: "Filter relevant changes" + uses: "dorny/paths-filter@v2" + id: "filter" + with: + base: "${{env.PATHS_FILTER_BASE}}" + filters: | + image: + - ".github/actions/**" + - ".github/workflows/clp-core-build.yaml" + - ${{env.PATHS_FILTER_LIB_INSTALL_GLOB}} + - "components/core/tools/docker-images/clp-env-base-${{env.OS_NAME}}/**" + - "components/core/tools/scripts/lib_install/${{env.OS_NAME}}/**" + ${{inputs.PATHS_FILTER_CLP_FILTER}} - - name: Build CLP Core - id: build - uses: ./.github/actions/clp-core-build - - - name: Upload CLP Binary artifact - uses: actions/upload-artifact@main + - uses: "./.github/actions/clp-core-build-deps-and-binaries" with: - name: clp-binaries-focal - path: ${{github.workspace}}/clp-binaries-focal.tar - if-no-files-found: error - - build-clp-core-image: - needs: build-focal - runs-on: ubuntu-latest + os_name: "${{env.OS_NAME}}" + deps_image_changed: "${{steps.filter.outputs.image}}" + push_binaries_image: false + local_registry_port: "5000" + token: "${{secrets.GITHUB_TOKEN}}" + + ubuntu-bionic: + runs-on: "ubuntu-latest" + services: + registry: + image: "registry:2" + ports: [ "5000:5000" ] + env: + OS_NAME: "ubuntu-bionic" steps: - - name: Checkout - uses: actions/checkout@v3 + - uses: "actions/checkout@v3" with: - submodules: recursive + submodules: "recursive" - - name: Workaround actions/runner-images/issues/6775 - run: chown $(id -u):$(id -g) -R . + - name: "Work around actions/runner-images/issues/6775" + run: "chown $(id -u):$(id -g) -R ." + shell: "bash" - - name: Download built CLP Binaries - uses: actions/download-artifact@v2 + - name: "Filter relevant changes" + uses: "dorny/paths-filter@v2" + id: "filter" with: - name: clp-binaries-focal - path: ${{github.workspace}}/binaries - - - name: Extract Binaries Bundle - run: tar -xvf clp-binaries-focal.tar - working-directory: ${{github.workspace}}/binaries - - - name: Build and Push Ubuntu Focal Docker Image - uses: ./.github/actions/clp-docker-build-push-action + base: "${{env.PATHS_FILTER_BASE}}" + filters: | + image: + - ".github/actions/**" + - ".github/workflows/clp-core-build.yaml" + - ${{env.PATHS_FILTER_LIB_INSTALL_GLOB}} + - "components/core/tools/docker-images/clp-env-base-${{env.OS_NAME}}/**" + - "components/core/tools/scripts/lib_install/${{env.OS_NAME}}/**" + ${{inputs.PATHS_FILTER_CLP_FILTER}} + + - uses: "./.github/actions/clp-core-build-deps-and-binaries" with: - image_name: ${{env.IMAGE_NAME_BASE}}-ubuntu-focal - context: ${{github.workspace}}/binaries - file: components/core/tools/docker-images/clp-core-focal/Dockerfile - token: ${{secrets.GITHUB_TOKEN}} - push_image: ${{'pull_request' != github.event_name && 'refs/heads/main' == github.ref}} + os_name: "${{env.OS_NAME}}" + deps_image_changed: "${{steps.filter.outputs.image}}" + push_binaries_image: false + local_registry_port: "5000" + token: "${{secrets.GITHUB_TOKEN}}" - build-bionic: - runs-on: ubuntu-latest - container: ghcr.io/y-scope/clp/clp-core-dependencies-x86-ubuntu-bionic:main + ubuntu-focal: + runs-on: "ubuntu-latest" + services: + registry: + image: "registry:2" + ports: [ "5000:5000" ] + env: + OS_NAME: "ubuntu-focal" steps: - - name: Checkout - uses: actions/checkout@v3 + - uses: "actions/checkout@v3" with: - submodules: recursive + submodules: "recursive" - - name: Workaround actions/runner-images/issues/6775 - run: chown $(id -u):$(id -g) -R . + - name: "Work around actions/runner-images/issues/6775" + run: "chown $(id -u):$(id -g) -R ." + shell: "bash" - - name: Build CLP Core - uses: ./.github/actions/clp-core-build - - build-centos: - runs-on: ubuntu-latest - container: ghcr.io/y-scope/clp/clp-core-dependencies-x86-centos7.4:main - steps: - - name: Checkout - uses: actions/checkout@v3 + - name: "Filter relevant changes" + uses: "dorny/paths-filter@v2" + id: "filter" with: - submodules: recursive + base: "${{env.PATHS_FILTER_BASE}}" + filters: | + image: + - ".github/actions/**" + - ".github/workflows/clp-core-build.yaml" + - ${{env.PATHS_FILTER_LIB_INSTALL_GLOB}} + - "components/core/tools/docker-images/clp-env-base-${{env.OS_NAME}}/**" + - "components/core/tools/scripts/lib_install/${{env.OS_NAME}}/**" + ${{inputs.PATHS_FILTER_CLP_FILTER}} - - name: Workaround actions/runner-images/issues/6775 - run: chown $(id -u):$(id -g) -R . - - - name: Build CLP Core - uses: ./.github/actions/clp-core-build + - uses: "./.github/actions/clp-core-build-deps-and-binaries" + with: + os_name: "${{env.OS_NAME}}" + deps_image_changed: "${{steps.filter.outputs.image}}" + push_binaries_image: true + local_registry_port: "5000" + token: "${{secrets.GITHUB_TOKEN}}" diff --git a/.github/workflows/clp-dependency-image-build.yaml b/.github/workflows/clp-dependency-image-build.yaml deleted file mode 100644 index 32365b7b8..000000000 --- a/.github/workflows/clp-dependency-image-build.yaml +++ /dev/null @@ -1,126 +0,0 @@ -name: generate-build-dependency-image - -on: - push: - paths: - - '.github/workflows/clp-dependency-image-build.yaml' - - 'components/core/tools/docker-images/**' - - 'components/core/tools/scripts/lib_install/**' - workflow_dispatch: - -env: - REGISTRY: ghcr.io - IMAGE_NAME_BASE: ${{github.repository}}/clp-core-dependencies-x86 - - CORE_COMPONENT_DIR: 'components/core' - CORE_COMPONENT_DOCKER_IMGS_DIR: 'components/core/tools/docker-images' - CORE_COMPONENT_LIB_INSTALL_DIR: 'components/core/tools/scripts/lib_install' - WORKFLOWS_DIR: '.github/workflows' - -concurrency: build-${{github.ref}} - -jobs: - build-ubuntu-focal: - runs-on: ubuntu-20.04 - name: Build Image - Ubuntu Focal - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - submodules: recursive - - - name: Workaround actions/runner-images/issues/6775 - run: chown $(id -u):$(id -g) -R . - - - name: Filter relevant changes - uses: dorny/paths-filter@v2 - id: filter - with: - # Consider changes between the previous commit and this one - base: ${{ github.ref_name }} - filters: | - src: - - '${{env.CORE_COMPONENT_DOCKER_IMGS_DIR}}/clp-env-base-focal/**' - - '${{env.CORE_COMPONENT_LIB_INSTALL_DIR}}/*.sh' - - '${{env.CORE_COMPONENT_LIB_INSTALL_DIR}}/ubuntu-focal/**' - - '${{env.WORKFLOWS_DIR}}/clp-dependency-image-build.yaml' - - - name: Build and Push Ubuntu Focal Docker Image - uses: ./.github/actions/clp-docker-build-push-action - if: steps.filter.outputs.src == 'true' - with: - image_name: ${{env.IMAGE_NAME_BASE}}-ubuntu-focal - context: ${{env.CORE_COMPONENT_DIR}} - file: ${{env.CORE_COMPONENT_DOCKER_IMGS_DIR}}/clp-env-base-focal/Dockerfile - token: ${{secrets.GITHUB_TOKEN}} - push_image: ${{'pull_request' != github.event_name && 'refs/heads/main' == github.ref}} - - build-ubuntu-bionic: - runs-on: ubuntu-20.04 - name: Build Image - Ubuntu Bionic - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - submodules: recursive - - - name: Workaround actions/runner-images/issues/6775 - run: chown $(id -u):$(id -g) -R . - - - name: Filter relevant changes - uses: dorny/paths-filter@v2 - id: filter - with: - # Consider changes between the previous commit and this one - base: ${{ github.ref_name }} - filters: | - src: - - '${{env.CORE_COMPONENT_DOCKER_IMGS_DIR}}/clp-env-base-bionic/**' - - '${{env.CORE_COMPONENT_LIB_INSTALL_DIR}}/*.sh' - - '${{env.CORE_COMPONENT_LIB_INSTALL_DIR}}/ubuntu-bionic/**' - - '${{env.WORKFLOWS_DIR}}/clp-dependency-image-build.yaml' - - - name: Build and Push Ubuntu Bionic Docker Image - uses: ./.github/actions/clp-docker-build-push-action - if: steps.filter.outputs.src == 'true' - with: - image_name: ${{env.IMAGE_NAME_BASE}}-ubuntu-bionic - context: ${{env.CORE_COMPONENT_DIR}} - file: ${{env.CORE_COMPONENT_DOCKER_IMGS_DIR}}/clp-env-base-bionic/Dockerfile - token: ${{secrets.GITHUB_TOKEN}} - push_image: ${{'pull_request' != github.event_name && 'refs/heads/main' == github.ref}} - - build-centos: - runs-on: ubuntu-20.04 - name: Build Image - CentOS 7.4 - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - submodules: recursive - - - name: Workaround actions/runner-images/issues/6775 - run: chown $(id -u):$(id -g) -R . - - - name: Filter relevant changes - uses: dorny/paths-filter@v2 - id: filter - with: - # Consider changes between the previous commit and this one - base: ${{ github.ref_name }} - filters: | - src: - - '${{env.CORE_COMPONENT_DOCKER_IMGS_DIR}}/clp-env-base-centos7.4/**' - - '${{env.CORE_COMPONENT_LIB_INSTALL_DIR}}/*.sh' - - '${{env.CORE_COMPONENT_LIB_INSTALL_DIR}}/centos7.4/**' - - '${{env.WORKFLOWS_DIR}}/clp-dependency-image-build.yaml' - - - name: Build and Push Centos7.4 Docker Image - uses: ./.github/actions/clp-docker-build-push-action - if: steps.filter.outputs.src == 'true' - with: - image_name: ${{env.IMAGE_NAME_BASE}}-centos7.4 - context: ${{env.CORE_COMPONENT_DIR}} - file: ${{env.CORE_COMPONENT_DOCKER_IMGS_DIR}}/clp-env-base-centos7.4/Dockerfile - token: ${{secrets.GITHUB_TOKEN}} - push_image: ${{'pull_request' != github.event_name && 'refs/heads/main' == github.ref}} diff --git a/.github/workflows/clp-execution-image-build.yaml b/.github/workflows/clp-execution-image-build.yaml index f31f11724..44b7f6c1e 100644 --- a/.github/workflows/clp-execution-image-build.yaml +++ b/.github/workflows/clp-execution-image-build.yaml @@ -1,34 +1,44 @@ -name: generate-execution-dependency-image +name: "clp-execution-image-build" on: push: paths: - - 'tools/docker-images/clp-execution-base-focal/**' - - 'components/core/tools/scripts/lib_install/**' - - '.github/workflows/clp-execution-image-build.yaml' + - ".github/workflows/clp-execution-image-build.yaml" + - "components/core/tools/scripts/lib_install/*" + - "tools/docker-images/clp-execution-base-focal/**" workflow_dispatch: env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{github.repository}}/clp-execution-x86-ubuntu-focal + CONTAINER_IMAGE_REGISTRY: ghcr.io jobs: build: - runs-on: ubuntu-20.04 - name: Build Image + runs-on: "ubuntu-latest" steps: - - name: Checkout - uses: actions/checkout@v3 + - uses: "actions/checkout@v3" with: - submodules: recursive + submodules: "recursive" - - name: Workaround actions/runner-images/issues/6775 - run: chown $(id -u):$(id -g) -R . + - name: "Workaround actions/runner-images/issues/6775" + run: "chown $(id -u):$(id -g) -R ." - - name: Build and push Docker image - uses: ./.github/actions/clp-docker-build-push-action + - uses: "docker/login-action@v3" with: - image_name: ${{env.IMAGE_NAME}} - file: ./tools/docker-images/clp-execution-base-focal/Dockerfile - token: ${{secrets.GITHUB_TOKEN}} - push_image: ${{'pull_request' != github.event_name && 'refs/heads/main' == github.ref}} + registry: "${{env.CONTAINER_IMAGE_REGISTRY}}" + username: "${{github.actor}}" + password: "${{secrets.GITHUB_TOKEN}}" + + - id: "meta" + uses: "docker/metadata-action@v5" + with: + images: >- + ${{env.CONTAINER_IMAGE_REGISTRY}}/${{github.repository}}/clp-execution-x86-ubuntu-focal + + - if: "github.event_name != 'pull_request' && github.ref == 'refs/heads/main'" + uses: "docker/build-push-action@v5" + with: + context: "./" + file: "./tools/docker-images/clp-execution-base-focal/Dockerfile" + push: true + tags: "${{steps.meta.outputs.tags}}" + labels: "${{steps.meta.outputs.labels}}" diff --git a/components/core/tools/docker-images/clp-core-focal/Dockerfile b/components/core/tools/docker-images/clp-core-ubuntu-focal/Dockerfile similarity index 100% rename from components/core/tools/docker-images/clp-core-focal/Dockerfile rename to components/core/tools/docker-images/clp-core-ubuntu-focal/Dockerfile diff --git a/components/core/tools/docker-images/clp-env-base-bionic/Dockerfile b/components/core/tools/docker-images/clp-env-base-ubuntu-bionic/Dockerfile similarity index 100% rename from components/core/tools/docker-images/clp-env-base-bionic/Dockerfile rename to components/core/tools/docker-images/clp-env-base-ubuntu-bionic/Dockerfile diff --git a/components/core/tools/docker-images/clp-env-base-bionic/build.sh b/components/core/tools/docker-images/clp-env-base-ubuntu-bionic/build.sh old mode 100755 new mode 100644 similarity index 100% rename from components/core/tools/docker-images/clp-env-base-bionic/build.sh rename to components/core/tools/docker-images/clp-env-base-ubuntu-bionic/build.sh diff --git a/components/core/tools/docker-images/clp-env-base-focal/Dockerfile b/components/core/tools/docker-images/clp-env-base-ubuntu-focal/Dockerfile similarity index 100% rename from components/core/tools/docker-images/clp-env-base-focal/Dockerfile rename to components/core/tools/docker-images/clp-env-base-ubuntu-focal/Dockerfile diff --git a/components/core/tools/docker-images/clp-env-base-focal/build.sh b/components/core/tools/docker-images/clp-env-base-ubuntu-focal/build.sh old mode 100755 new mode 100644 similarity index 100% rename from components/core/tools/docker-images/clp-env-base-focal/build.sh rename to components/core/tools/docker-images/clp-env-base-ubuntu-focal/build.sh diff --git a/components/core/tools/scripts/utils/README.md b/components/core/tools/scripts/utils/README.md index cc025dd03..a7008e7e8 100644 --- a/components/core/tools/scripts/utils/README.md +++ b/components/core/tools/scripts/utils/README.md @@ -1,5 +1,8 @@ This directory contains uncategorized utility scripts. + +* `build-and-run-unit-tests.sh` can be used to build all executables and run + the unit tests. * `run-in-container.sh` can be used to run a command (e.g., `make`), in a container containing the core component's dependencies. * All commands are run from the root of the core component. diff --git a/components/core/tools/scripts/utils/build-and-run-unit-tests.sh b/components/core/tools/scripts/utils/build-and-run-unit-tests.sh new file mode 100755 index 000000000..3d0ed7b50 --- /dev/null +++ b/components/core/tools/scripts/utils/build-and-run-unit-tests.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +# Exit on any error +set -e +# Error on undefined variable +set -u + +cUsage="Usage: ${BASH_SOURCE[0]} [ ]" +if [ "$#" -lt 2 ]; then + echo "$cUsage" + exit 1 +fi +src_dir="$1" +build_dir="$2" +if [ "$#" -gt 2 ]; then + unit_tests_filter="$3" +fi + +cmake -S "$src_dir" -B "$build_dir" +cmake --build "$build_dir" +cd "$build_dir" +if [ -z "${unit_tests_filter+x}" ]; then + ./unitTest +else + ./unitTest "$unit_tests_filter" +fi