Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
slashmo committed Nov 16, 2021
0 parents commit 3591d5a
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: "daily"
reviewers:
- slashmo
24 changes: 24 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CI
on:
push:

jobs:
ci:
strategy:
fail-fast: false
matrix:
os: [ubuntu-18.04, ubuntu-20.04]
swift: [5.5, swift-DEVELOPMENT-SNAPSHOT-2021-11-12-a]
runs-on: ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install Swift
uses: ./
with:
version: ${{ matrix.swift }}

- name: Print Swift Version
run: swift --version
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Moritz Lang

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# install-swift

This action allows installing Swift toolchains, with support for both release and development versions.

## Usage

### Inputs

- `version` - The Swift version you want to install. This may either be a release version like `5.5`, or a development
snapshot like `swift-DEVELOPMENT-SNAPSHOT-2021-11-12-a`.

### Example

```yaml
- name: Install Swift
uses: slashmo/[email protected]
with:
version: 5.5
```
After adding this step, all following steps in this job will automatically use the newly installed Swift version:
```yaml
- name: Run Tests
run: swift test # <-- uses Swift 5.5
```
### Multiple Swift Versions
In case you want to run your GitHub Actions workflow using different versions of Swift, define a
[GitHub Action's matrix](https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix)
to spawn multiple instances of the same job:
```yaml
jobs:
test:
name: Run Tests
strategy:
matrix:
swift: [5.5, swift-DEVELOPMENT-SNAPSHOT-2021-11-12-a]
ubuntu: [ubuntu-18.04, ubuntu-20.04]
fail-fast: false
runs-on: ${{ matrix.ubuntu }}
steps:
- name: Install Swift
uses: slashmo/[email protected]
with:
version: ${{ matrix.swift }}
- name: Checkout
uses: actions/checkout@v2
- name: Run Tests
run: swift test
```
The action will automatically detect the Ubuntu version and install the correct toolchain.
### Caching
`install-swift` automatically caches toolchains based on the [version input](#inputs) and the detected Ubuntu version.
42 changes: 42 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: 'Install Swift'
description: 'Install the given Swift version.'

inputs:
version:
description: 'The Swift version to install.'
required: true

runs:
using: "composite"
steps:
- name: Determine Ubuntu Version
run: |
UBUNTU_VERSION=$(lsb_release -rs)
if [ $UBUNTU_VERSION != "18.04" ] && [ $UBUNTU_VERSION != "20.04" ]; then
echo "No Swift Toolchain available for Ubuntu version '$UBUNTU_VERSION'."
echo "Visit https://swift.org/download for more information."
exit 1;
fi
echo "UBUNTU_VERSION=$UBUNTU_VERSION" >> $GITHUB_ENV
shell: bash

- name: Cache Swift Toolchain
id: swift-toolchain-cache
uses: actions/cache@v2
with:
path: /usr/share/swift-toolchain
key: ubuntu-${{ env.UBUNTU_VERSION }}-${{ inputs.version }}

- name: Install Swift Toolchain
run: SWIFT_VERSION=${{ inputs.version }} $GITHUB_ACTION_PATH/install-swift.sh
shell: bash

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

branding:
icon: 'briefcase'
color: 'orange'
43 changes: 43 additions & 0 deletions install-swift.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

if [[ $SWIFT_VERSION == swift-DEVELOPMENT-SNAPSHOT* ]]; then
TOOLCHAIN_BASE_URL="https://download.swift.org/development/ubuntu${UBUNTU_VERSION//[.]/}/$SWIFT_VERSION"
TOOLCHAIN_PATH="$SWIFT_VERSION-ubuntu$UBUNTU_VERSION"
else
TOOLCHAIN_BASE_URL="https://download.swift.org/swift-$SWIFT_VERSION-release/ubuntu${UBUNTU_VERSION//[.]/}/swift-$SWIFT_VERSION-RELEASE"
TOOLCHAIN_PATH="swift-$SWIFT_VERSION-RELEASE-ubuntu$UBUNTU_VERSION"
fi

TOOLCHAIN_TAR="$TOOLCHAIN_PATH.tar.gz"
TOOLCHAIN_SIG="$TOOLCHAIN_TAR.sig"
TOOLCHAIN_TAR_URL="$TOOLCHAIN_BASE_URL/$TOOLCHAIN_TAR"
TOOLCHAIN_SIG_URL="$TOOLCHAIN_BASE_URL/$TOOLCHAIN_SIG"

echo "Installing system dependencies πŸ“¦"
sudo apt-get install \
binutils git gnupg2 libc6-dev libcurl4 libedit2 libgcc-9-dev libpython2.7 libsqlite3-0 libstdc++-9-dev libxml2 \
libz3-dev pkg-config tzdata uuid-dev zlib1g-dev

if [ -d "/usr/share/swift-toolchain" ]; then
echo "Toolchain already exists, skipping download βœ…"
else
echo "Reading toolchain version from .swift-version πŸ“„"
echo "Detected Swift toolchain version '$(cat .swift-version)' πŸ“„"

echo "Downloading Swift toolchain ☁️"
wget $TOOLCHAIN_TAR_URL

echo "Verifying Swift toolchain πŸ”‘"
wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import -
wget $TOOLCHAIN_SIG_URL
gpg --verify $TOOLCHAIN_SIG

echo "Installing Swift toolchain πŸ’»"
tar xzf $TOOLCHAIN_TAR

mv $TOOLCHAIN_PATH /usr/share/swift-toolchain
echo "Successfully installed Swift toolchain πŸŽ‰"
fi

export PATH=/usr/share/swift-toolchain/usr/bin:${PATH}
echo "PATH=$PATH" >> $GITHUB_ENV

0 comments on commit 3591d5a

Please sign in to comment.