Skip to content

ci(github): Refactor clp-core-build action into an action that can run an arbitrary command on a container image. - #748

Merged
davidlion merged 18 commits into
y-scope:mainfrom
davidlion:workflow-refactor
Mar 6, 2025
Merged

ci(github): Refactor clp-core-build action into an action that can run an arbitrary command on a container image.#748
davidlion merged 18 commits into
y-scope:mainfrom
davidlion:workflow-refactor

Conversation

@davidlion

@davidlion davidlion commented Mar 5, 2025

Copy link
Copy Markdown
Member

Description

This PR refactors the github action actions/clp-core-build that built clp-core to the action actions/clp-core-image-run that instead runs arbitrary bash script. This will allow the core image to be used to execute other commands/scripts that require an enviornment with all core dependencies (e.g. linters such as clang-tidy).

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

CI builds passing.

Summary by CodeRabbit

  • New Features
    • Implemented a container-based automation process that executes tests within secure environments.
  • Chores
    • Refined the build and deployment workflows to streamline dependency checks and artifact management.

These improvements enhance our build reliability and testing performance, ensuring a smoother overall experience.

@davidlion
davidlion requested a review from kirkrodrigues March 5, 2025 22:08
@davidlion
davidlion requested a review from a team as a code owner March 5, 2025 22:08
@coderabbitai

coderabbitai Bot commented Mar 5, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request updates the GitHub workflow configuration by switching from the legacy clp-core-build action to the new run-on-image action for both CentOS Stream 9 and Ubuntu Jammy jobs. The update removes the upload_binaries parameter and introduces the run_command parameter to execute unit tests. Additionally, it adds steps to conditionally copy and archive binaries for upload. A new composite GitHub Action is added to handle image downloading, loading, dependency initialisation, and command execution inside a Docker container.

Changes

File Path Change Summary
.github/workflows/clp-core-build.yaml Updated workflow to use run-on-image action for CentOS Stream 9 and Ubuntu Jammy jobs; removed upload_binaries parameter; added run_command parameter and conditional binary upload steps.
.github/actions/run-on-image/action.yaml Introduced a new composite GitHub Action that executes a specified command inside a Docker container. It handles image retrieval (via downloading or published image use), dependency initialisation, and mounting the repository.

Sequence Diagram(s)

sequenceDiagram
    participant W as Workflow Job
    participant A as run-on-image Action
    participant D as Docker Container
    participant R as Repository

    W->>A: Start action with inputs (image_name, use_published_image, run_command)
    alt use_published_image is false
        A->>A: Download image artifact
        A->>D: Load image into Docker from tar file
    else use_published_image is true
        A->>A: Generate qualified image name
    end
    A->>A: Initialise dependencies
    A->>D: Mount repository (R)
    A->>D: Execute run_command inside container
    D-->>W: Return execution result
Loading

Suggested reviewers

  • kirkrodrigues

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
.github/workflows/clp-core-build.yaml (1)

225-241: Artifact Upload Step for Ubuntu Jammy Binaries
This step conditionally copies and archives the binaries for artifact uploading. The tar command and directory handling appear correct; however, consider adding error handling in case the tar operation fails. This could help with debugging any potential issues during the upload process.

.github/actions/clp-core-image-run/action.yaml (1)

45-52: Docker Run Execution with Custom Command
The final step executes a docker run command that appends the custom bash script (${{inputs.run_command}}). While this simplification is welcomed, please verify that the command string is properly quoted to avoid shell interpretation issues. It might also be beneficial to log the executed command for debugging purposes in future iterations.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f7efaa2 and 2e522ba.

📒 Files selected for processing (2)
  • .github/actions/clp-core-image-run/action.yaml (3 hunks)
  • .github/workflows/clp-core-build.yaml (5 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/clp-core-build.yaml

214-214: property "ubuntu_focal_image_changed" is not defined in object type {centos_stream_9_image_changed: string; clp_changed: string; ubuntu_jammy_image_changed: string}

(expression)

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: centos-stream-9-deps-image
  • GitHub Check: ubuntu-jammy-deps-image
  • GitHub Check: lint-check (ubuntu-latest)
  • GitHub Check: build (macos-latest)
  • GitHub Check: lint-check (macos-latest)
🔇 Additional comments (5)
.github/workflows/clp-core-build.yaml (3)

7-7: New Action File Reference Added (Pull Request Paths)
A new file reference for the action (.github/actions/clp-core-image-run/action.yaml) has been added to the pull_request paths. Please ensure this new reference is maintained consistently across all triggers.


18-18: New Action File Reference Added (Push Paths)
The push paths now include the new action file (.github/actions/clp-core-image-run/action.yaml). Verify that the file path is correct and that no unintended files are being watched.


166-181: Refactored Action for CentOS-Stream-9 Binaries
The job now leverages the new clp-core-image-run action along with a custom run_command parameter. The command appears to combine tasks correctly. Please double-check that the updated command syntax meets your intended behaviour and that the environment variables are properly resolved during runtime.

.github/actions/clp-core-image-run/action.yaml (2)

1-1: Renamed Action
The action’s name has been updated to "clp-core-image-run". This is in line with the new functionality for running arbitrary bash scripts.


11-13: New Input Parameter: run_command
The addition of the run_command input parameter enables the action to execute a custom Bash script. Ensure that this input is validated in usage and that any complex commands are appropriately escaped when passed into the docker run environment.

Comment thread .github/workflows/clp-core-build.yaml Outdated
Comment on lines +211 to +224
- uses: "./.github/actions/clp-core-image-run"
with:
image_name: "${{env.DEPS_IMAGE_NAME_PREFIX}}${{env.OS_NAME}}"
use_shared_libs: "${{matrix.use_shared_libs}}"
use_published_image: >-
${{needs.filter-relevant-changes.outputs.ubuntu_jammy_image_changed == 'false'
${{needs.filter-relevant-changes.outputs.ubuntu_focal_image_changed == 'false'
|| (github.event_name != 'pull_request' && github.ref == 'refs/heads/main')}}
upload_binaries: "${{matrix.upload_binaries}}"
binaries_artifact_name: "${{env.BINARIES_ARTIFACT_NAME_PREFIX}}${{env.OS_NAME}}"
run_command: >-
task deps:core &&
python3 /mnt/clp/components/core/tools/scripts/utils/build-and-run-unit-tests.py
${{matrix.use_shared_libs == 'true' && '--use-shared-libs' || ''}}
--source-dir /mnt/clp/components/core
--build-dir /mnt/clp/components/core/build
--num-jobs $(getconf _NPROCESSORS_ONLN)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Incorrect Output Variable Reference in Ubuntu Jammy Job
The use_published_image input is currently comparing against needs.filter-relevant-changes.outputs.ubuntu_focal_image_changed, which does not exist. The correct output variable appears to be ubuntu_jammy_image_changed. Please update the reference as shown below:

-            ${{needs.filter-relevant-changes.outputs.ubuntu_focal_image_changed == 'false'
-            || (github.event_name != 'pull_request' && github.ref == 'refs/heads/main')}}
+            ${{needs.filter-relevant-changes.outputs.ubuntu_jammy_image_changed == 'false'
+            || (github.event_name != 'pull_request' && github.ref == 'refs/heads/main')}}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- uses: "./.github/actions/clp-core-image-run"
with:
image_name: "${{env.DEPS_IMAGE_NAME_PREFIX}}${{env.OS_NAME}}"
use_shared_libs: "${{matrix.use_shared_libs}}"
use_published_image: >-
${{needs.filter-relevant-changes.outputs.ubuntu_jammy_image_changed == 'false'
${{needs.filter-relevant-changes.outputs.ubuntu_focal_image_changed == 'false'
|| (github.event_name != 'pull_request' && github.ref == 'refs/heads/main')}}
upload_binaries: "${{matrix.upload_binaries}}"
binaries_artifact_name: "${{env.BINARIES_ARTIFACT_NAME_PREFIX}}${{env.OS_NAME}}"
run_command: >-
task deps:core &&
python3 /mnt/clp/components/core/tools/scripts/utils/build-and-run-unit-tests.py
${{matrix.use_shared_libs == 'true' && '--use-shared-libs' || ''}}
--source-dir /mnt/clp/components/core
--build-dir /mnt/clp/components/core/build
--num-jobs $(getconf _NPROCESSORS_ONLN)
- uses: "./.github/actions/clp-core-image-run"
with:
image_name: "${{env.DEPS_IMAGE_NAME_PREFIX}}${{env.OS_NAME}}"
use_published_image: >-
${{needs.filter-relevant-changes.outputs.ubuntu_jammy_image_changed == 'false'
|| (github.event_name != 'pull_request' && github.ref == 'refs/heads/main')}}
run_command: >-
task deps:core &&
python3 /mnt/clp/components/core/tools/scripts/utils/build-and-run-unit-tests.py
${{matrix.use_shared_libs == 'true' && '--use-shared-libs' || ''}}
--source-dir /mnt/clp/components/core
--build-dir /mnt/clp/components/core/build
--num-jobs $(getconf _NPROCESSORS_ONLN)
🧰 Tools
🪛 actionlint (1.7.4)

214-214: property "ubuntu_focal_image_changed" is not defined in object type {centos_stream_9_image_changed: string; clp_changed: string; ubuntu_jammy_image_changed: string}

(expression)

@kirkrodrigues kirkrodrigues left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the PR title, how about:

ci(github): Refactor clp-core-build action into an action that can run an arbitrary command on a container image.

Comment thread .github/actions/clp-core-image-run/action.yaml Outdated
Comment thread .github/actions/clp-core-image-run/action.yaml Outdated
@@ -1,4 +1,4 @@
name: "clp-core-build"
name: "clp-core-image-run"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about run-on-image?

Comment thread .github/workflows/clp-core-build.yaml Outdated
Comment thread .github/workflows/clp-core-build.yaml Outdated
Comment thread .github/workflows/clp-core-build.yaml Outdated
Comment thread .github/workflows/clp-core-build.yaml Outdated
davidlion and others added 2 commits March 5, 2025 22:43
Co-authored-by: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com>
@davidlion davidlion changed the title ci(github): Refactor core build to use an action that will run arbitrary bash script. ci(github): Refactor clp-core-build action into an action that can run an arbitrary command on a container image. Mar 6, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
.github/actions/clp-core-image-run/action.yaml (1)

11-13: Introduction of the run_command Input Parameter

Adding the run_command input is a valuable enhancement that provides flexibility for executing user-defined commands. Ensure that users receive clear documentation or examples to prevent ambiguity in its usage.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 44cbc0b and 9e1dfa2.

📒 Files selected for processing (2)
  • .github/actions/clp-core-image-run/action.yaml (3 hunks)
  • .github/workflows/clp-core-build.yaml (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: ubuntu-jammy-deps-image
  • GitHub Check: centos-stream-9-deps-image
  • GitHub Check: lint-check (ubuntu-latest)
  • GitHub Check: build (macos-latest)
  • GitHub Check: lint-check (macos-latest)
🔇 Additional comments (8)
.github/workflows/clp-core-build.yaml (5)

7-7: New Action File Path Added in Pull Request Trigger

The addition of the new path for .github/actions/clp-core-image-run/action.yaml in the pull_request trigger is appropriate. It ensures that changes to the new action are correctly monitored.


18-18: Updated Push Trigger to Include New Action File

Including .github/actions/clp-core-image-run/action.yaml in the push trigger paths is a good update. This change ensures that pushes affecting the new action file correctly trigger the workflow.


166-180: Refactor to Use the New Image-Run Action in CentOS Job

The job now leverages the new clp-core-image-run action instead of the previous build action. The new run_command parameter is correctly constructed to chain the tasks (running task deps:core followed by the unit test script) and conditionally include the --use-shared-libs flag.
Please ensure that the inline conditional and the command concatenation maintain the correct spacing and quoting when passed to bash -c.


211-224: Consistent Application of New Action in Ubuntu Job

The Ubuntu job step has been updated to utilise the new clp-core-image-run action with a similarly structured run_command. Confirm that the dynamic parameter (i.e. the conditional shared library flag) is handled consistently with the CentOS job.


225-232: Well-Defined Conditional for Binary Upload

The conditional step for handling binary artifacts (triggered when matrix.upload_binaries == 'true') is clear and aligns with expected practices. Please verify that the output directory and tarball creation do not conflict with earlier steps in the pipeline.

.github/actions/clp-core-image-run/action.yaml (3)

1-2: Action Renaming and Updated Description

Renaming the action to clp-core-image-run with the new description accurately reflects its updated responsibility—executing arbitrary commands within a container image. This improvement enhances clarity and should help users understand its purpose.


29-40: Image Properties Extraction Step

The block that determines the qualified image name based on whether a published image is being used is well implemented. Confirm that the conditional supports both lowercase conversion and appropriate tagging for the image.


45-53: Docker Run Command Execution

The docker run step is constructed to mount the repository with the correct user and working directory, and it properly incorporates the run_command input via bash -c. It would be beneficial to test this command with various input scenarios to ensure that argument splitting or spacing issues do not occur.

@davidlion
davidlion requested a review from kirkrodrigues March 6, 2025 03:48
@@ -1,5 +1,5 @@
name: "clp-core-build"
description: "Builds CLP-core in the specified container"
name: "clp-core-run-on-image"

@kirkrodrigues kirkrodrigues Mar 6, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I meant run-on-image by itself, without the prefix, for two reasons:

  1. This seems like more of a general action, not specific to clp-core.
  2. The "clp-core-" prefix was only ever added since we wanted "core-" as the prefix but that sounds ambiguous by itself.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
.github/actions/run-on-image/action.yaml (2)

4-13: Clarify Input Types for Consistency
The inputs are well defined; however, note that the use_published_image input is expected to hold a string value of either "true" or "false". It may be beneficial to add documentation or default values to ensure consistent use.


29-40: Image Properties Extraction is Effective
The script correctly handles the lowercase conversion for repository names when using a published image and sets the output accordingly.
Consider adding error handling in case the image name is not set or if the conversion fails, although it may not be required in this context.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f65aede and 6400a02.

📒 Files selected for processing (2)
  • .github/actions/run-on-image/action.yaml (1 hunks)
  • .github/workflows/clp-core-build.yaml (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: lint-check (ubuntu-latest)
  • GitHub Check: build (macos-latest)
  • GitHub Check: lint-check (macos-latest)
🔇 Additional comments (11)
.github/actions/run-on-image/action.yaml (6)

1-3: Metadata and Description are Clear
The name and description clearly convey the action’s purpose. No changes are necessary here.


15-17: Composite Action Setup Looks Good
The structure under runs with the composite action and step definitions is set up correctly.


18-23: Artifact Download Condition is Correct
The conditional step for downloading the image artifact when use_published_image is set to "false" is implemented correctly.


24-28: Image Loading Step is Appropriately Configured
The step that loads the downloaded image using Docker is clear and leverages the correct input filename.


42-44: Dependency Initialisation Step is Straightforward
The call to ./tools/scripts/deps-download/init.sh is simple and clear. Ensure that this script exists and has the proper execution permissions in the repository.


45-52: Docker Run Command Executes as Intended
The final step to run the specified command inside the Docker container is well composed. The use of the current user’s permissions and workspace volume mounting is correctly implemented.

.github/workflows/clp-core-build.yaml (5)

7-8: Include New Action File in the Trigger Paths
The added path for .github/actions/run-on-image/action.yaml in the pull_request trigger ensures that changes to the new action are tracked. This update is correct and aligns with the refactoring.


18-19: Update Trigger Paths for Push Events
Including .github/actions/run-on-image/action.yaml in the push trigger paths is appropriate so that pushes affecting the new action trigger a workflow run.


166-180: Refactored Job Step Using the New Action is Well Implemented
The centos-stream-9-binaries job now leverages the new run-on-image action appropriately. The input parameters, including image_name, use_published_image, and the multiline run_command, are correctly defined.
Make sure that the conditional expression for use_published_image evaluates correctly as intended under all circumstances.


211-223: Ubuntu Job Step Mirrors the Centre Logic Correctly
The ubuntu-jammy-binaries job’s use of the run-on-image action is consistent with the centos-stream-9-binaries job. Both the image name and the command execution are correctly set up, with the proper condition to determine if a published image should be used.


225-234: Binary Copy and Upload Steps Are Appropriately Conditioned
The steps for copying binaries and subsequently uploading them as artifacts are in line with the workflow’s new structure. Verify that the defined paths and output names match the expectations in downstream steps.

@davidlion
davidlion requested a review from kirkrodrigues March 6, 2025 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants