|
| 1 | +# Copyright © 2025 Cassidy Spring (Bee). |
| 2 | +# This Source Code Form is subject to the terms of the Mozilla Public |
| 3 | +# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 | +# file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 5 | + |
| 6 | +name: Swiftly Swift |
| 7 | +author: Cassidy Spring (Bee) |
| 8 | +description: Installs Swiftly and a Swift Toolchain. |
| 9 | +branding: |
| 10 | + icon: command |
| 11 | + color: orange |
| 12 | + |
| 13 | +inputs: |
| 14 | + swift-version: |
| 15 | + description: Swift Toolchain version that Swiftly will install and use, defaults to latest. |
| 16 | + required: true |
| 17 | + default: latest |
| 18 | + |
| 19 | +runs: |
| 20 | + using: composite |
| 21 | + steps: |
| 22 | + - name: Check Runner OS |
| 23 | + if: ${{ runner.os != 'macOS' && runner.os != 'Linux' }} |
| 24 | + shell: bash |
| 25 | + run: | |
| 26 | + echo "::error::Only supports macOS and linux" |
| 27 | + exit 1 |
| 28 | +
|
| 29 | + - name: Get Date |
| 30 | + id: date |
| 31 | + shell: bash |
| 32 | + run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT |
| 33 | + |
| 34 | + - name: Restore Swiftly - macOS |
| 35 | + if: ${{ runner.os == 'macOS' }} |
| 36 | + uses: actions/cache/restore@v4 |
| 37 | + id: restore-swiftly-cache-macos |
| 38 | + with: |
| 39 | + path: swiftly.pkg |
| 40 | + key: swiftly-${{ runner.os }}-${{ runner.arch }}-${{ steps.date.outputs.date }} |
| 41 | + |
| 42 | + - name: Download Swiftly - macOS |
| 43 | + if: ${{ runner.os == 'macOS' && steps.restore-swiftly-cache-macos.outputs.cache-hit != 'true' }} |
| 44 | + shell: bash |
| 45 | + run: | |
| 46 | + curl -O https://download.swift.org/swiftly/darwin/swiftly.pkg |
| 47 | + pkgutil --check-signature swiftly.pkg |
| 48 | +
|
| 49 | + - name: Cache Swiftly - macOS |
| 50 | + if: ${{ runner.os == 'macOS' && steps.restore-swiftly-cache-macos.outputs.cache-hit != 'true' }} |
| 51 | + uses: actions/cache/save@v4 |
| 52 | + id: save-swiftly-cache-macos |
| 53 | + with: |
| 54 | + path: swiftly.pkg |
| 55 | + key: swiftly-${{ runner.os }}-${{ runner.arch }}-${{ steps.date.outputs.date }} |
| 56 | + |
| 57 | + - name: Install Swiftly - macOS |
| 58 | + if: ${{ runner.os == 'macOS' }} |
| 59 | + shell: bash |
| 60 | + run: | |
| 61 | + installer -pkg swiftly.pkg -target CurrentUserHomeDirectory |
| 62 | + ~/.swiftly/bin/swiftly init --verbose --assume-yes --skip-install |
| 63 | + . "${SWIFTLY_HOME_DIR:-$HOME/.swiftly}/env.sh" |
| 64 | + hash -r |
| 65 | + echo "PATH=$PATH" >> $GITHUB_ENV |
| 66 | + |
| 67 | + - name: Restore Swiftly - Linux |
| 68 | + if: ${{ runner.os == 'Linux' }} |
| 69 | + uses: actions/cache/restore@v4 |
| 70 | + id: restore-swiftly-cache-linux |
| 71 | + with: |
| 72 | + path: swiftly.tar.gz |
| 73 | + key: swiftly-${{ runner.os }}-${{ runner.arch }}-${{ steps.date.outputs.date }} |
| 74 | + |
| 75 | + - name: Download Swiftly - Linux |
| 76 | + if: ${{ runner.os == 'Linux' && steps.restore-swiftly-cache-linux.outputs.cache-hit != 'true' }} |
| 77 | + shell: bash |
| 78 | + run: | |
| 79 | + curl -o swiftly.tar.gz https://download.swift.org/swiftly/linux/swiftly-$(uname -m).tar.gz |
| 80 | +
|
| 81 | + - name: Cache Swiftly - Linux |
| 82 | + if: ${{ runner.os == 'Linux' && steps.restore-swiftly-cache-linux.outputs.cache-hit != 'true' }} |
| 83 | + uses: actions/cache/save@v4 |
| 84 | + id: save-swiftly-cache-linux |
| 85 | + with: |
| 86 | + path: swiftly.tar.gz |
| 87 | + key: swiftly-${{ runner.os }}-${{ runner.arch }}-${{ steps.date.outputs.date }} |
| 88 | + |
| 89 | + - name: Install Swiftly - Linux |
| 90 | + if: ${{ runner.os == 'Linux' }} |
| 91 | + shell: bash |
| 92 | + run: | |
| 93 | + tar -zxf swiftly.tar.gz |
| 94 | + ./swiftly init --verbose --assume-yes --skip-install |
| 95 | + . "${SWIFTLY_HOME_DIR:-$HOME/.local/share/swiftly}/env.sh" |
| 96 | + hash -r |
| 97 | + echo "PATH=$PATH" >> $GITHUB_ENV |
| 98 | + |
| 99 | + # NOTE: It feels bad to have sudo statements here but I could not get the post install to work |
| 100 | + # without both of them in place on linux. Neither (and chmod at all) is required on macOS. |
| 101 | + # So this would be nice to dig into more but definitely done for now. |
| 102 | + - name: Install Swift Toolchain |
| 103 | + shell: bash |
| 104 | + run: | |
| 105 | + swiftly install --use ${{ inputs.swift-version }} --post-install-file=post-install.sh |
| 106 | + if [ -f post-install.sh ]; then |
| 107 | + sudo chmod u+x post-install.sh |
| 108 | + sudo ./post-install.sh |
| 109 | + fi |
0 commit comments