Skip to content

Commit 74ba8b3

Browse files
authored
Add caching to install-swift (#134)
Avoid downloading and installing swift in every workflow run if the `.swift-version` file hasn't changed.
1 parent 9bbb91f commit 74ba8b3

File tree

1 file changed

+43
-14
lines changed

1 file changed

+43
-14
lines changed

.github/actions/install-swift/action.yml

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,36 @@ description: Installs the Swift specified by a .swift-version file
44
runs:
55
using: "composite"
66
steps:
7+
# - name: "Cache: Swift"
8+
# id: cache-swift
9+
# uses: actions/cache@v4
10+
# with:
11+
# path: "$HOME/.local/share/swiftly"
12+
# key: swift-${{ hashFiles('.swift-version') }}
13+
14+
- name: Setup Environment
15+
shell: bash
16+
run: |
17+
export SWIFTLY_HOME_DIR="$HOME/.local/share/swiftly"
18+
echo "SWIFTLY_HOME_DIR=$SWIFTLY_HOME_DIR" >> $GITHUB_ENV
19+
echo "SWIFTLY_HOME_DIR=$SWIFTLY_HOME_DIR" >> $HOME/.bashrc
20+
21+
export SWIFTLY_BIN_DIR="$HOME/.local/share/swiftly/bin"
22+
echo "SWIFTLY_BIN_DIR=$SWIFTLY_BIN_DIR" >> $GITHUB_ENV
23+
echo "SWIFTLY_BIN_DIR=$SWIFTLY_BIN_DIR" >> $HOME/.bashrc
24+
25+
echo "PATH=$SWIFTLY_BIN_DIR:$PATH" >> $GITHUB_ENV
26+
echo "PATH=\$SWIFTLY_BIN_DIR:\$PATH" >> $HOME/.bashrc
27+
28+
- name: "Restore: Swift"
29+
uses: actions/cache/restore@v4
30+
id: cache-swift
31+
with:
32+
path: "~/.local/share/swiftly"
33+
key: swift-${{ hashFiles('**/.swift-version') }}
34+
735
- name: Install `apt` Dependencies
36+
if: steps.cache-swift.outputs.cache-hit != 'true'
837
shell: bash
938
run: |
1039
SUDO=$(if [[ $EUID -ne 0 ]]; then echo sudo; fi)
@@ -14,16 +43,9 @@ runs:
1443
DEBIAN_FRONTEND: noninteractive
1544

1645
- name: Install Swiftly
46+
if: steps.cache-swift.outputs.cache-hit != 'true'
1747
shell: bash
1848
run: |
19-
export SWIFTLY_HOME_DIR="$HOME/.local/share/swiftly"
20-
echo "SWIFTLY_HOME_DIR=$SWIFTLY_HOME_DIR" >> $GITHUB_ENV
21-
echo "SWIFTLY_HOME_DIR=$SWIFTLY_HOME_DIR" >> $HOME/.bashrc
22-
23-
export SWIFTLY_BIN_DIR="$HOME/.local/share/swiftly/bin"
24-
echo "SWIFTLY_BIN_DIR=$SWIFTLY_BIN_DIR" >> $GITHUB_ENV
25-
echo "SWIFTLY_BIN_DIR=$SWIFTLY_BIN_DIR" >> $HOME/.bashrc
26-
2749
UNAME=$(uname -m)
2850
curl -O "https://download.swift.org/swiftly/linux/swiftly-$UNAME.tar.gz"
2951
tar zxf "swiftly-$UNAME.tar.gz"
@@ -33,11 +55,18 @@ runs:
3355
--quiet-shell-followup \
3456
--no-modify-profile
3557
36-
echo "PATH=$SWIFTLY_BIN_DIR:$PATH" >> $GITHUB_ENV
37-
echo "PATH=\$SWIFTLY_BIN_DIR:\$PATH" >> $HOME/.bashrc
38-
3958
- name: Install Swift
59+
if: steps.cache-swift.outputs.cache-hit != 'true'
4060
shell: bash
41-
run: |
42-
swiftly install --post-install-file ./out.sh
43-
swift --version
61+
run: swiftly install --post-install-file ./out.sh
62+
63+
- name: "Save: Swift"
64+
if: steps.cache-swift.outputs.cache-hit != 'true'
65+
uses: actions/cache/save@v4
66+
with:
67+
path: "~/.local/share/swiftly"
68+
key: swift-${{ hashFiles('**/.swift-version') }}
69+
70+
- name: Print Swift Version
71+
shell: bash
72+
run: swift --version

0 commit comments

Comments
 (0)