From c78f350d1c75a293308fba5a8340e919b77c4e38 Mon Sep 17 00:00:00 2001 From: Darren Gibson Date: Thu, 17 Oct 2024 11:24:55 -0500 Subject: [PATCH 1/2] Fix sbt/setup-sbt to work on self hosted runners. - Downloads the sbt tar file to `$RUNNER_TEMP/_sbt` - Extracts the sbt files to `$RUNNER_TOOL_CACHE/sbt/version` - Check the tool cache for sbt before bothering to pull it from the cache or download it. - Check the actions/cache if its not in the tool cache. --- action.yml | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/action.yml b/action.yml index 6358c90..8844b6f 100644 --- a/action.yml +++ b/action.yml @@ -7,36 +7,57 @@ inputs: default: 1.10.2 runs: using: "composite" + steps: - name: Set up cache paths id: cache-paths shell: bash run: | - echo "setupsbt_path=$HOME/work/_setupsbt" >> $GITHUB_OUTPUT + echo "sbt_toolpath=$RUNNER_TOOL_CACHE/sbt/${{ inputs.sbt-runner-version }}" >> "$GITHUB_OUTPUT" + echo "sbt_downloadpath=$RUNNER_TEMP/_sbt" >> "$GITHUB_OUTPUT" + + - name: Check Tool Cache + id: cache-tool-dir + shell: bash + run: | + mkdir -p "${{ steps.cache-paths.outputs.sbt_downloadpath }}" + if [ -f "${{ steps.cache-paths.outputs.sbt_toolpath }}/sbt/bin/sbt" ]; then + echo "cache-hit=true" >> "$GITHUB_OUTPUT" + else + echo "cache-hit=false" >> "$GITHUB_OUTPUT" + fi - name: Cache sbt distribution id: cache-dir + if: steps.cache-tool-dir.outputs.cache-hit != 'true' uses: actions/cache@v4 with: - path: ${{ steps.cache-paths.outputs.setupsbt_path }} - key: ${{ runner.os }}-sbt-${{ inputs.sbt-runner-version }}-1.1.1 + path: ${{ steps.cache-paths.outputs.sbt_downloadpath }} + key: ${{ runner.os }}-sbt-${{ inputs.sbt-runner-version }}-1.1.3 + + - name: "Download sbt" + shell: bash + env: + SBT_RUNNER_VERSION: ${{ inputs.sbt-runner-version }} + if: steps.cache-tool-dir.outputs.cache-hit != 'true' && steps.cache-dir.outputs.cache-hit != 'true' + run: | + curl -sL "https://github.com/sbt/sbt/releases/download/v$SBT_RUNNER_VERSION/sbt-$SBT_RUNNER_VERSION.zip" > \ + "${{ steps.cache-paths.outputs.sbt_downloadpath }}/sbt-$SBT_RUNNER_VERSION.zip" - name: "Install sbt" shell: bash - if: steps.cache-dir.outputs.cache-hit != 'true' + if: steps.cache-tool-dir.outputs.cache-hit != 'true' && steps.cache-tool-dir.outputs.cache-hit != 'true' run: | - mkdir -p "${{ steps.cache-paths.outputs.setupsbt_path }}" - curl -sL https://github.com/sbt/sbt/releases/download/v$SBT_RUNNER_VERSION/sbt-$SBT_RUNNER_VERSION.zip > "${{ steps.cache-paths.outputs.setupsbt_path }}/sbt-$SBT_RUNNER_VERSION.zip" - pushd "${{ steps.cache-paths.outputs.setupsbt_path }}" - unzip -o "sbt-$SBT_RUNNER_VERSION.zip" + mkdir -p "${{ steps.cache-paths.outputs.sbt_toolpath }}" + + pushd "${{ steps.cache-paths.outputs.sbt_downloadpath }}" + unzip -o "sbt-${{ inputs.sbt-runner-version }}.zip" -d "${{ steps.cache-paths.outputs.sbt_toolpath }}" popd - env: - SBT_RUNNER_VERSION: ${{ inputs.sbt-runner-version }} - name: "Setup PATH" shell: bash run: | - pushd "${{ steps.cache-paths.outputs.setupsbt_path }}" + pushd "${{ steps.cache-paths.outputs.sbt_toolpath }}" ls sbt/bin/sbt echo "$PWD/sbt/bin" >> "$GITHUB_PATH" popd From 7caf3b53c73e41bee8f18844346d2e5b5638a20d Mon Sep 17 00:00:00 2001 From: Darren Gibson Date: Thu, 17 Oct 2024 11:24:55 -0500 Subject: [PATCH 2/2] Caches directly from the sbt_toolpath Instead of caching the download path, we cache directly the toolpath. We continue first checking that the sbt installation is not already on the toolpath where we would expect it to be. Additionally, this combines the install and download phases since we don't cache the download sbt dir, but the tooldir anymore anyways. --- action.yml | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/action.yml b/action.yml index 8844b6f..586d5ad 100644 --- a/action.yml +++ b/action.yml @@ -20,7 +20,7 @@ runs: id: cache-tool-dir shell: bash run: | - mkdir -p "${{ steps.cache-paths.outputs.sbt_downloadpath }}" + mkdir -p "${{ steps.cache-paths.outputs.sbt_toolpath }}" if [ -f "${{ steps.cache-paths.outputs.sbt_toolpath }}/sbt/bin/sbt" ]; then echo "cache-hit=true" >> "$GITHUB_OUTPUT" else @@ -32,24 +32,19 @@ runs: if: steps.cache-tool-dir.outputs.cache-hit != 'true' uses: actions/cache@v4 with: - path: ${{ steps.cache-paths.outputs.sbt_downloadpath }} - key: ${{ runner.os }}-sbt-${{ inputs.sbt-runner-version }}-1.1.3 + path: ${{ steps.cache-paths.outputs.sbt_toolpath }} + key: ${{ runner.os }}-sbt-${{ inputs.sbt-runner-version }}-1.1.4 - - name: "Download sbt" + - name: "Download and Install sbt" shell: bash env: SBT_RUNNER_VERSION: ${{ inputs.sbt-runner-version }} if: steps.cache-tool-dir.outputs.cache-hit != 'true' && steps.cache-dir.outputs.cache-hit != 'true' run: | + mkdir -p "${{ steps.cache-paths.outputs.sbt_downloadpath }}" curl -sL "https://github.com/sbt/sbt/releases/download/v$SBT_RUNNER_VERSION/sbt-$SBT_RUNNER_VERSION.zip" > \ "${{ steps.cache-paths.outputs.sbt_downloadpath }}/sbt-$SBT_RUNNER_VERSION.zip" - - name: "Install sbt" - shell: bash - if: steps.cache-tool-dir.outputs.cache-hit != 'true' && steps.cache-tool-dir.outputs.cache-hit != 'true' - run: | - mkdir -p "${{ steps.cache-paths.outputs.sbt_toolpath }}" - pushd "${{ steps.cache-paths.outputs.sbt_downloadpath }}" unzip -o "sbt-${{ inputs.sbt-runner-version }}.zip" -d "${{ steps.cache-paths.outputs.sbt_toolpath }}" popd