Skip to content

Commit cd9c4da

Browse files
committed
Cleanup action
* Add outputs * Consistently use environment variables for ${{ steps }} * Skip needless `pushd`/`popd` * Name the `SBT_CACHE_KEY_VERSION` field to make it avoid magic numbers * Provide outputs for the various publicly observable details of the action
1 parent 20811ef commit cd9c4da

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

action.yml

+29-11
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,39 @@ inputs:
55
description: "The runner version (The actual version is controlled via project/build.properties)"
66
required: true
77
default: 1.10.6
8+
outputs:
9+
sbt-toolpath:
10+
description: "Where sbt tools live"
11+
value: ${{ steps.cache-paths.outputs.sbt_toolpath }}
12+
cache-hit:
13+
description: "If sbt was found in the tool cache or the action/cache"
14+
value: ${{ steps.cache-tool-dir.outputs.cache-hit == 'true' || steps.cache-dir.outputs.cache-hit == 'true' }}
15+
cache-key:
16+
description: "The cache-key for the sbt version (unless sbt was found in the tool cache)"
17+
value: ${{ steps.cache-tool-dir.outputs.cache-hit != 'true' && steps.cache-paths.outputs.sbt_cachekey || '' }}
818
runs:
919
using: "composite"
1020
steps:
1121
- name: Set up cache paths
1222
id: cache-paths
1323
shell: bash
24+
env:
25+
SBT_RUNNER_VERSION: ${{ inputs.sbt-runner-version }}
26+
SBT_CACHE_KEY_VERSION: 1.1.4
1427
run: |
15-
echo "sbt_toolpath=$RUNNER_TOOL_CACHE/sbt/${{ inputs.sbt-runner-version }}" >> "$GITHUB_OUTPUT"
28+
echo "sbt_toolpath=$RUNNER_TOOL_CACHE/sbt/$SBT_RUNNER_VERSION" >> "$GITHUB_OUTPUT"
1629
echo "sbt_downloadpath=$RUNNER_TEMP/_sbt" >> "$GITHUB_OUTPUT"
30+
echo "sbt_cachekey=$RUNNER_OS-sbt-$SBT_RUNNER_VERSION-$SBT_CACHE_KEY_VERSION" >> "$GITHUB_OUTPUT"
1731
- name: Check Tool Cache
1832
id: cache-tool-dir
1933
shell: bash
34+
env:
35+
SBT_TOOLPATH: "${{ steps.cache-paths.outputs.sbt_toolpath }}"
2036
run: |
21-
mkdir -p "${{ steps.cache-paths.outputs.sbt_toolpath }}"
22-
if [ -f "${{ steps.cache-paths.outputs.sbt_toolpath }}/sbt/bin/sbt" ]; then
37+
if [ -f "$SBT_TOOLPATH/sbt/bin/sbt" ]; then
2338
echo "cache-hit=true" >> "$GITHUB_OUTPUT"
2439
else
40+
mkdir -p "$SBT_TOOLPATH"
2541
echo "cache-hit=false" >> "$GITHUB_OUTPUT"
2642
fi
2743
- name: Cache sbt distribution
@@ -30,24 +46,26 @@ runs:
3046
uses: actions/cache@v4
3147
with:
3248
path: ${{ steps.cache-paths.outputs.sbt_toolpath }}
33-
key: ${{ runner.os }}-sbt-${{ inputs.sbt-runner-version }}-1.1.4
49+
key: ${{ steps.cache-paths.outputs.sbt_cachekey }}
3450
- name: "Download and Install sbt"
3551
shell: bash
3652
env:
3753
SBT_RUNNER_VERSION: ${{ inputs.sbt-runner-version }}
54+
SBT_TOOLPATH: "${{ steps.cache-paths.outputs.sbt_toolpath }}"
55+
SBT_DOWNLOADPATH: "${{ steps.cache-paths.outputs.sbt_downloadpath }}"
3856
if: steps.cache-tool-dir.outputs.cache-hit != 'true' && steps.cache-dir.outputs.cache-hit != 'true'
3957
run: |
40-
mkdir -p "${{ steps.cache-paths.outputs.sbt_downloadpath }}"
58+
mkdir -p "$SBT_DOWNLOADPATH"
4159
curl -sL "https://github.com/sbt/sbt/releases/download/v$SBT_RUNNER_VERSION/sbt-$SBT_RUNNER_VERSION.zip" > \
42-
"${{ steps.cache-paths.outputs.sbt_downloadpath }}/sbt-$SBT_RUNNER_VERSION.zip"
60+
"$SBT_DOWNLOADPATH/sbt-$SBT_RUNNER_VERSION.zip"
4361
44-
pushd "${{ steps.cache-paths.outputs.sbt_downloadpath }}"
45-
unzip -o "sbt-${{ inputs.sbt-runner-version }}.zip" -d "${{ steps.cache-paths.outputs.sbt_toolpath }}"
46-
popd
62+
cd "$SBT_DOWNLOADPATH"
63+
unzip -o "sbt-$SBT_RUNNER_VERSION.zip" -d "$SBT_TOOLPATH"
4764
- name: "Setup PATH"
4865
shell: bash
66+
env:
67+
SBT_TOOLPATH: "${{ steps.cache-paths.outputs.sbt_toolpath }}"
4968
run: |
50-
pushd "${{ steps.cache-paths.outputs.sbt_toolpath }}"
69+
cd "$SBT_TOOLPATH"
5170
ls sbt/bin/sbt
5271
echo "$PWD/sbt/bin" >> "$GITHUB_PATH"
53-
popd

0 commit comments

Comments
 (0)