Chad Taylor
BlogProjects

Using Clojure in GitHub Actions without the setup-clojure action

Posted on July 9, 2021

GitHub Actions is a great CI tool, and there are many great actions developed by third parties. I use Clojure in many of my personal and professional projects, and I frequently use setup-clojure in my workflows. However, some organizations have security rules configured that disallow actions that are not internal to the organization or verified on the GitHub Marketplace.

There are no verified Clojure setup actions at the time of writing, so you must take on the installation of Clojure yourself if you work in an organization with these security rules in place. Thankfully, it is a fairly straightforward process to install and cache the Clojure installation.

Following is a simple CI process that runs on pull requests. It caches a Clojure installation based on the version (defined as CLOJURE_VERSION) and will download and install Clojure only if necessary.

The cache action cannot create files and directories under /usr/local/, which is where Clojure is installed by default. The workflow will install Clojure in $HOME/bin/clojure which can be accessed by the cache action. The workflow will then make the action available on the path so that normal clojure commands may be used in subsequent steps.

name: CI
on:
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest
    env:
      CLOJURE_VERSION: 1.10.3.855

    steps:
      - name: Checkout
        uses: actions/[email protected]

      - name: Set up Java
        uses: actions/setup-[email protected]
        with:
          distribution: adopt
          java-version: 11

      - name: Cache Clojure install
        id: cache-clojure
        uses: actions/[email protected]
        with:
          path: ~/bin/clojure
          key: ${{ env.CLOJURE_VERSION }}

      - name: Set up Clojure
        if: steps.cache-clojure.outputs.cache-hit != 'true'
        run: |
          curl -O https://download.clojure.org/install/linux-install-${CLOJURE_VERSION}.sh
          chmod +x linux-install-${CLOJURE_VERSION}.sh
          sudo ./linux-install-${CLOJURE_VERSION}.sh --prefix ~/bin/clojure

      - name: Add Clojure to path
        run: echo "$HOME/bin/clojure/bin" >> $GITHUB_PATH

      - name: Cache maven artifacts
        id: cache-maven
        uses: actions/[email protected]
        with:
          path: ~/.m2
          key: ${{ runner.os }}-${{ hashFiles('deps.edn') }}

      - name: Download dependencies
        if: steps.cache-maven.outputs.cache-hit != 'true'
        run: clojure -A:test -Stree

      - name: Run tests
        run: ./scripts/kaocha

clojureci

© Chad Taylor 2019-2022