name: Prepare back-end environment
inputs:
  java-version:
    required: true
    default: '11'
  clojure-version:
    required: true
    default: '1.11.1.1208'
  m2-cache-key:
    description: 'Key to cache M2 packages from Maven Central'
    required: true
    default: 'm2'

runs:
  using: "composite"
  steps:
    - name: Prepare JDK ${{ inputs.java-version }}
      uses: actions/setup-java@v3
      with:
        java-version: ${{ inputs.java-version }}
        distribution: 'temurin'
    - name: Install Clojure CLI
      shell: bash
      run: |
        curl -O https://download.clojure.org/install/linux-install-${{ inputs.clojure-version }}.sh &&
        sudo bash ./linux-install-${{ inputs.clojure-version }}.sh
    - name: Check to see if dependencies should be cached
      if: ${{ contains(github.event.head_commit.message, '[ci nocache]') }}
      run: echo "Commit message includes [ci nocache]; dependencies will NOT be cached"
      shell: bash
    - name: Get M2 cache
      uses: actions/cache@v3
      if: ${{ !contains(github.event.head_commit.message, '[ci nocache]') }}
      with:
        path: |
          ~/.m2
          ~/.gitlibs
        key: ${{ runner.os }}-${{ inputs.m2-cache-key }}-${{ hashFiles('**/deps.edn') }}
        restore-keys: |
          ${{ runner.os }}-${{ inputs.m2-cache-key }}-
