Chad Taylor

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

    runs-on: ubuntu-latest

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

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

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

      - name: Set up Clojure
        if: steps.cache-clojure.outputs.cache-hit != 'true'
        run: |
          curl -O${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]
          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


© Chad Taylor 2019-2022