Random Clojure Functionλ︎
A Clojure command line application that shows a random function from the namespaces available in the Clojure Standard library, or a specific namespace from that library.
Random Clojure Function repository
This guide shows how to develop this project alongside CircleCI as the continuous integration service.
- Create a new project - using the Random Clojure Function guide
- Create a repository on GitHub
- Commit the project early and push changes to GitHub
- Add a .circleci/config.yml file and push to GitHub, choosing the relevant image
- Login to CircleCI dashboard and add project, choosing manual configuration
- Continue developing the random clojure function project, including tests
- After each push to GitHub, check the build status
- Add a CircleCI badge to the project readme
Video uses an older command to create projects
:project/create
alias from Practicalli Clojure CLI Config creates a new project
Arguments are key value pairs and can specify the :template
, project :name
and outpug directory :output-dir
.
Create a new projectλ︎
Start following the guide to create the random clojure function project, using a deps.edn for the Clojure project configuration
Version control the Clojure project using Git (or magit in Spacemacs)
Add a test run aliasλ︎
Edit the deps.edn
file in the root of the project and add a :test/run
alias, to run the kaocha test runner which will stop if a failing test is detected. Stopping on a failed test saves running the full test suite and make the CI workflow more effective.
:test/run
{:extra-paths ["test"]
:extra-deps {lambdaisland/kaocha {:mvn/version "1.60.977"}}
:exec-fn kaocha.runner/exec-fn
:exec-args {:randomize? false
:fail-fast? true}}
Create a remote repositoryλ︎
Add the remote repository URL to the local Git repository.
Add CircleCI configurationλ︎
Adding CircleCI early in the project development cycle ensures testing from the saved source code is successful and testing is consistently repeatable.
Create a new file called .circleci/config.yaml
in the root of the project.
Edit the file and add the following configuration.
Circe CI configuration for Clojure project
``yaml title=".circleci/config.yaml"
version: 2.1
jobs: # basic units of work in a run
build: # runs without Workflows must have a
buildjob as entry point
working_directory: ~/random-clojure-function # directory where steps will run
docker: # run the steps with Docker
- image: cimg/clojure:1.10 # image is primary container where
stepsare run
environment: # environment variables for primary container
JVM_OPTS: -Xmx3200m # limit maximum JVM heap size to prevent out of memory errors
steps: # commands that comprise the
build` job
- checkout # check out source code to working directory
- restore_cache: # restores cache if checksum unchanged from last run
key: random-clojure-function-{{ checksum "deps.edn" }}
- run: clojure -P
- save_cache: # generate / update cache in the .m2 directory using a key template
paths:
- ~/.m2
- ~/.gitlibs
key: random-clojure-function-{{ checksum "deps.edn" }}
- run: clojure -X:test/run
```
run: clojure -P
step downloads dependencies for the project, including the :extra-deps
if aliases are also included.
run: clojure -X:test/run
adds the test directory to the class path and runs the Kaocha runner defined in the alias.
Connect Circle CI to the projectλ︎
Commit and push the .circleci/config.yml
file to the GitHub repository.
Open the CircleCI dashboard and select Add Project. If your GitHub account has multiple organizations, choose the appropriate organization first.
Search the repository list for the GitHub repository and select ,,,
Select the Manual configuration as a .circleci/config.yml
file has already been added to the Git repository.
Press Start Building button to confirm that a config.yml
file has already been added and the build should start.
Now the first build runs with the config.yml
file.
Its failed. Okay lets investigate...
Thats okay, we have failing tests locally, so we know that the CircleCI build is working the same as on our local development environment.
The continuous integration is now working and tests are automatically run as soon as you push changes to the remote repository.
So the development of the project can continue with greater confidence
Adding a Build Status badgeλ︎
Generating a status badge documentation describes how to add a build status badge for your project, usually at the top of the README.md file in the project
[![CircleCI](https://circleci.com/gh/circleci/circleci-docs.svg?style=svg)](https://circleci.com/gh/practicalli/random-clojure-function)
Add this markdown to the top of the README.md file, underneath the title. Then commit and push the change to the GitHub repository.
NOTE: you might want to fix the unit tests first :)