Skip to content

GitHub Workflowsλ︎

Automate tasks, such as running unit tests or lint code, whenever code is committed to a GitHub repository.

GitHub Actions can run one or more tasks after specific events, such as commits, raising issues or pull requests.

An event triggers a configured workflow which contains one or more jobs. A job contains a one or more steps which defines actions to run.

Practicalli GitHub Workflow Examples Practicalli recommended GitHub Actions

Introduction to GitHub Actions Understanding the workflow file

Anatomy of a workflowλ︎

Term Description
Event Triggers a workflow, e.g. Create pull request, push commit, etc.
Workflow Top level configuration containing one or more jobs, triggered by a specific event
Job Set of steps executed in the same runner, multiple jobs execute in parallel within their own instance of a runner
Step Individual task that runs commands (actions), sharing data with other steps
Action Standalone commands defined within a step, custom commands or GitHub community
Runner A GitHub Actions server, listening for available jobs

Example GitHub Actionλ︎

.github/workflows/workflow-name.yaml is a file that contains the workflow definition.

Setup Java adds an OpenJDK distribution, i.e. Eclipse Temurin, at a specified version (Java 17 recommended).

Setup Clojure provides Clojure via Clojure CLI, Leiningen or Boot. Clojure CLI is recommended.

Cache is used to cache Clojure and Java libraries

  • The example workflow runs on Ubuntu.
  • The project code is checked out from the Git repository.
  • Java and Clojure run-times are added to the environment
  • Unit tests are run using the :test/run alias (this alias should run Kaocha or similar test runner)
  • Source code format and idioms are checked with cljstyle and clj-kondo
  • The Clojure project is packaged into an Uberjar for deployment

Example GitHub workflow for Clojure CLI project

name: Test and Package project
      - main
    runs-on: ubuntu-latest
      - name: Checkout
        uses: actions/checkout@v4

      - name: Cache Clojure Dependencies
        uses: actions/cache@v3
            - ~/.m2
            - ~/.gitlibs
          key: cache-${{ hashFiles('**/deps.edn') }}
          restore-keys: clojure-deps-

      - name: Prepare java
        uses: actions/setup-java@v3
          distribution: 'temurin'
          java-version: '17'

      - name: Install clojure tools
        uses: DeLaGuardo/setup-clojure@9.5
          cli:    # Clojure CLI based on tools.deps
          cljstyle: 0.15.0 # cljstyle
          clj-kondo: 2022.10.05 # Clj-kondo

      - name: Run Unit tests
        run: clojure -X:test/run

      - name: "Lint with clj-kondo"
        run: clj-kondo --lint deps.edn src resources test --config .clj-kondo/config-ci.edn

      - name: "Check Clojure Style"
        run: cljstyle check --report

      - name: Package Clojure project
        run: clojure -X:project/uberjar


Last update: October 2, 2023