Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .circleci/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/configuration-reference
version: 2.1

# Define a job to be invoked later in a workflow.
# See: https://circleci.com/docs/jobs-steps/#jobs-overview & https://circleci.com/docs/configuration-reference/#jobs
jobs:
say-hello:
# Specify the execution environment. You can specify an image from Docker Hub or use one of our convenience images from CircleCI's Developer Hub.
# See: https://circleci.com/docs/executor-intro/ & https://circleci.com/docs/configuration-reference/#executor-job
docker:
# Specify the version you desire here
# See: https://circleci.com/developer/images/image/cimg/base
- image: cimg/base:current

# Add steps to the job
# See: https://circleci.com/docs/jobs-steps/#steps-overview & https://circleci.com/docs/configuration-reference/#steps
steps:
# Checkout the code as the first step.
- checkout
- run:
name: "Say hello"
command: "echo Hello, World!"

# Orchestrate jobs using workflows
# See: https://circleci.com/docs/workflows/ & https://circleci.com/docs/configuration-reference/#workflows
workflows:
say-hello-workflow: # This is the name of the workflow, feel free to change it to better match your workflow.
# Inside the workflow, you define the jobs you want to run.
jobs:
- say-hello
Comment on lines +1 to +31
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

This initial CI configuration is a good start. However, it can be significantly improved to be more robust and useful for a Rust project. I've provided a suggestion that incorporates several best practices:

  • Use Rust-specific Docker Image: Instead of a generic cimg/base image, it's better to use a cimg/rust image which comes with the Rust toolchain pre-installed. This simplifies the setup.
  • Pin Docker Image Version: It's a best practice to pin the Docker image to a specific version (e.g., 1.78.0) instead of using a floating tag like current. This ensures your builds are reproducible and don't break unexpectedly when the base image is updated. 1
  • Add Meaningful CI Steps: The current job only prints "Hello, World!". I've added steps to check code formatting with cargo fmt and run tests with cargo test, which are common for Rust projects.
  • Descriptive Naming: The job and workflow names have been changed from placeholders (say-hello, say-hello-workflow) to more descriptive names (build-and-test, ci).
  • Remove Template Comments: The verbose template comments have been removed for better readability.

The suggested code implements these improvements to provide a more effective starting point for your CI pipeline.

version: 2.1

jobs:
  build-and-test:
    docker:
      - image: cimg/rust:1.78.0
    steps:
      - checkout
      - run:
          name: "Check formatting"
          command: cargo fmt -- --check
      - run:
          name: "Run tests"
          command: cargo test

workflows:
  ci:
    jobs:
      - build-and-test

Style Guide References

Footnotes

  1. CircleCI best practices recommend pinning Docker images to a specific version to ensure build reproducibility and avoid unexpected failures caused by updates to floating tags like 'current' or 'latest'.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

version: 2.1

jobs:
build-and-test:
docker:
- image: cimg/rust:1.78.0
steps:
- checkout
- run:
name: "Check formatting"
command: cargo fmt -- --check
- run:
name: "Run tests"
command: cargo test

workflows:
ci:
jobs:
- build-and-test

Loading