Skip to content

Commit

Permalink
Rewrite GH workflows: (#175)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
kirkrodrigues authored Dec 5, 2023
1 parent 3dcac07 commit 635857a
Show file tree
Hide file tree
Showing 15 changed files with 361 additions and 340 deletions.
88 changes: 88 additions & 0 deletions .github/actions/clp-core-build-containers/action.yaml
Original file line number Diff line number Diff line change
@@ -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}}"
45 changes: 45 additions & 0 deletions .github/actions/clp-core-build-deps-and-binaries/action.yaml
Original file line number Diff line number Diff line change
@@ -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
52 changes: 17 additions & 35 deletions .github/actions/clp-core-build/action.yaml
Original file line number Diff line number Diff line change
@@ -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
52 changes: 0 additions & 52 deletions .github/actions/clp-docker-build-push-action/action.yaml

This file was deleted.

52 changes: 29 additions & 23 deletions .github/workflows/clp-core-build-macos.yaml
Original file line number Diff line number Diff line change
@@ -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]"
Loading

0 comments on commit 635857a

Please sign in to comment.