Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install SBT on self-hosted gha runners V2 #11

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,52 @@ 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_toolpath }}"
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_toolpath }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: because the $RUNNER_TOOL_CACHE path can be different between self-hosted and hosted runners, they may not be able to share this cache (actions/cache uses the paths in the cache key), but have separate caches. In practice I don't think this matters because of how fast the curl is, and how few different versions of sbt will need to be cached (its not like the cache between the build and test and publish on the typical sbt-typelevel project where its important to not rebuild the project).

key: ${{ runner.os }}-sbt-${{ inputs.sbt-runner-version }}-1.1.4

- name: "Install sbt"
- name: "Download and Install sbt"
shell: bash
if: steps.cache-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"
popd
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"

pushd "${{ steps.cache-paths.outputs.sbt_downloadpath }}"
unzip -o "sbt-${{ inputs.sbt-runner-version }}.zip" -d "${{ steps.cache-paths.outputs.sbt_toolpath }}"
popd

- 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
Loading