Skip to content

Add caching to install-swift #134

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

Merged
merged 2 commits into from
May 17, 2025
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
57 changes: 43 additions & 14 deletions .github/actions/install-swift/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,36 @@ description: Installs the Swift specified by a .swift-version file
runs:
using: "composite"
steps:
# - name: "Cache: Swift"
# id: cache-swift
# uses: actions/cache@v4
# with:
# path: "$HOME/.local/share/swiftly"
# key: swift-${{ hashFiles('.swift-version') }}

- name: Setup Environment
shell: bash
run: |
export SWIFTLY_HOME_DIR="$HOME/.local/share/swiftly"
echo "SWIFTLY_HOME_DIR=$SWIFTLY_HOME_DIR" >> $GITHUB_ENV
echo "SWIFTLY_HOME_DIR=$SWIFTLY_HOME_DIR" >> $HOME/.bashrc

export SWIFTLY_BIN_DIR="$HOME/.local/share/swiftly/bin"
echo "SWIFTLY_BIN_DIR=$SWIFTLY_BIN_DIR" >> $GITHUB_ENV
echo "SWIFTLY_BIN_DIR=$SWIFTLY_BIN_DIR" >> $HOME/.bashrc

echo "PATH=$SWIFTLY_BIN_DIR:$PATH" >> $GITHUB_ENV
echo "PATH=\$SWIFTLY_BIN_DIR:\$PATH" >> $HOME/.bashrc

- name: "Restore: Swift"
uses: actions/cache/restore@v4
id: cache-swift
with:
path: "~/.local/share/swiftly"
key: swift-${{ hashFiles('**/.swift-version') }}

- name: Install `apt` Dependencies
if: steps.cache-swift.outputs.cache-hit != 'true'
shell: bash
run: |
SUDO=$(if [[ $EUID -ne 0 ]]; then echo sudo; fi)
Expand All @@ -14,16 +43,9 @@ runs:
DEBIAN_FRONTEND: noninteractive

- name: Install Swiftly
if: steps.cache-swift.outputs.cache-hit != 'true'
shell: bash
run: |
export SWIFTLY_HOME_DIR="$HOME/.local/share/swiftly"
echo "SWIFTLY_HOME_DIR=$SWIFTLY_HOME_DIR" >> $GITHUB_ENV
echo "SWIFTLY_HOME_DIR=$SWIFTLY_HOME_DIR" >> $HOME/.bashrc

export SWIFTLY_BIN_DIR="$HOME/.local/share/swiftly/bin"
echo "SWIFTLY_BIN_DIR=$SWIFTLY_BIN_DIR" >> $GITHUB_ENV
echo "SWIFTLY_BIN_DIR=$SWIFTLY_BIN_DIR" >> $HOME/.bashrc

UNAME=$(uname -m)
curl -O "https://download.swift.org/swiftly/linux/swiftly-$UNAME.tar.gz"
tar zxf "swiftly-$UNAME.tar.gz"
Expand All @@ -33,11 +55,18 @@ runs:
--quiet-shell-followup \
--no-modify-profile

echo "PATH=$SWIFTLY_BIN_DIR:$PATH" >> $GITHUB_ENV
echo "PATH=\$SWIFTLY_BIN_DIR:\$PATH" >> $HOME/.bashrc

- name: Install Swift
if: steps.cache-swift.outputs.cache-hit != 'true'
shell: bash
run: |
swiftly install --post-install-file ./out.sh
swift --version
run: swiftly install --post-install-file ./out.sh

- name: "Save: Swift"
if: steps.cache-swift.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: "~/.local/share/swiftly"
key: swift-${{ hashFiles('**/.swift-version') }}

- name: Print Swift Version
shell: bash
run: swift --version
Loading