Skip to content

Commit

Permalink
Use local scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
sushichop committed Jan 28, 2025
1 parent 8340ce8 commit ef736c6
Show file tree
Hide file tree
Showing 10 changed files with 327 additions and 399 deletions.
112 changes: 82 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,27 @@ on:
- "**"

jobs:
swiftpm:
SwiftPM:
name: SwiftPM - Swift ${{ matrix.swift-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ['macos-12', 'ubuntu-20.04', 'windows-latest']
swift-version: ['5.6', '5.7.1']
os: ['macos-14', 'ubuntu-22.04', 'windows-2022']
swift-version: ['6.0.3', '5.10', '2025-01-10-a']
fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Select Xcode if needed - Swift ${{ matrix.swift-version }}
if: runner.os == 'macOS'
run: |
ls -al /Applications | grep Xcode
if [ '${{ matrix.swift-version }}' = '5.4.2' ]; then echo DEVELOPER_DIR=/Applications/Xcode_12.5.1.app >> $GITHUB_ENV; fi
if [ '${{ matrix.swift-version }}' = '5.5.2' ]; then echo DEVELOPER_DIR=/Applications/Xcode_13.2.1.app >> $GITHUB_ENV; fi
if [ '${{ matrix.swift-version }}' = '5.6' ]; then echo DEVELOPER_DIR=/Applications/Xcode_13.3.1.app >> $GITHUB_ENV; fi
if [ '${{ matrix.swift-version }}' = '6.0.3' ]; then echo DEVELOPER_DIR=/Applications/Xcode_16.2.app >> $GITHUB_ENV; fi
if [ '${{ matrix.swift-version }}' = '5.10' ]; then echo DEVELOPER_DIR=/Applications/Xcode_15.4.app >> $GITHUB_ENV; fi
if [ '${{ matrix.swift-version }}' = '5.7' ]; then echo DEVELOPER_DIR=/Applications/Xcode_14.0.1.app >> $GITHUB_ENV; fi
if [ '${{ matrix.swift-version }}' = '5.7.1' ]; then echo DEVELOPER_DIR=/Applications/Xcode_14.1.app >> $GITHUB_ENV; fi
- name: sushichop/gha-swift-env@v1
if [ '${{ matrix.swift-version }}' = '5.6' ]; then echo DEVELOPER_DIR=/Applications/Xcode_13.3.1.app >> $GITHUB_ENV; fi
if [ '${{ matrix.swift-version }}' = '5.5.2' ]; then echo DEVELOPER_DIR=/Applications/Xcode_13.2.1.app >> $GITHUB_ENV; fi
if [ '${{ matrix.swift-version }}' = '5.4.2' ]; then echo DEVELOPER_DIR=/Applications/Xcode_12.5.1.app >> $GITHUB_ENV; fi
- name: gha-swift-env-local
uses: ./
with:
swift-version: ${{ matrix.swift-version }}
Expand All @@ -41,55 +42,106 @@ jobs:
- name: Test a Swift package
run: swift test -v -Xswiftc -warnings-as-errors

cmake-macos-linux:
CMake:
name: CMake - Swift ${{ matrix.swift-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ['macos-12', 'ubuntu-20.04']
swift-version: ['5.6']
os: ['macos-14', 'ubuntu-22.04', 'windows-2022']
swift-version: ['6.0.3', '5.10', '2025-01-10-a']
fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Select Xcode if needed - Swift ${{ matrix.swift-version }}
if: runner.os == 'macOS'
run: |
ls -al /Applications | grep Xcode
if [ '${{ matrix.swift-version }}' = '5.4.2' ]; then echo DEVELOPER_DIR=/Applications/Xcode_12.5.1.app >> $GITHUB_ENV; fi
if [ '${{ matrix.swift-version }}' = '5.5.3' ]; then echo DEVELOPER_DIR=/Applications/Xcode_13.2.1.app >> $GITHUB_ENV; fi
if [ '${{ matrix.swift-version }}' = '6.0.3' ]; then echo DEVELOPER_DIR=/Applications/Xcode_16.2.app >> $GITHUB_ENV; fi
if [ '${{ matrix.swift-version }}' = '5.10' ]; then echo DEVELOPER_DIR=/Applications/Xcode_15.4.app >> $GITHUB_ENV; fi
if [ '${{ matrix.swift-version }}' = '5.7' ]; then echo DEVELOPER_DIR=/Applications/Xcode_14.0.1.app >> $GITHUB_ENV; fi
if [ '${{ matrix.swift-version }}' = '5.6.1' ]; then echo DEVELOPER_DIR=/Applications/Xcode_13.4.1.app >> $GITHUB_ENV; fi
if [ '${{ matrix.swift-version }}' = '5.6' ]; then echo DEVELOPER_DIR=/Applications/Xcode_13.3.1.app >> $GITHUB_ENV; fi
if [ '${{ matrix.swift-version }}' = '5.7' ]; then echo DEVELOPER_DIR=/Applications/Xcode_14.0.1.app >> $GITHUB_ENV; fi
if [ '${{ matrix.swift-version }}' = '5.7.1' ]; then echo DEVELOPER_DIR=/Applications/Xcode_14.1.app >> $GITHUB_ENV; fi
- name: sushichop/gha-swift-env@1
if [ '${{ matrix.swift-version }}' = '5.5.2' ]; then echo DEVELOPER_DIR=/Applications/Xcode_13.2.1.app >> $GITHUB_ENV; fi
if [ '${{ matrix.swift-version }}' = '5.4.2' ]; then echo DEVELOPER_DIR=/Applications/Xcode_12.5.1.app >> $GITHUB_ENV; fi
- name: gha-swift-env-local
uses: ./
with:
swift-version: ${{ matrix.swift-version }}
- name: Show Swift version
run: swift --version
- name: Build with CMake and Ninja
shell: bash
run: |
cmake --version
ninja --version
./scripts/cmake-script.sh
CMake-macOS:
name: CMake directly - Swift ${{ matrix.swift-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ['macos-latest']
swift-version: ['6.0.3']
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: gha-swift-env-local
uses: ./
with:
swift-version: ${{ matrix.swift-version }}
- name: Show Swift version
run: swift --version
- name: Build with CMake and Ninja
run: |
brew update && brew install ninja
cmake --version
ninja --version
cmake -B ./build -D CMAKE_C_COMPILER=clang -D CMAKE_BUILD_TYPE=RelWithDebInfo -G Ninja -S .
ninja -C ./build -v
cmake-windows:
name: CMake - Swift ${{ matrix.swift-version }} on ${{ matrix.os }}
CMake-Linux:
name: CMake directly - Swift ${{ matrix.swift-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ['windows-latest']
swift-version: ['5.4.2', '5.6']
os: ['ubuntu-latest']
swift-version: ['6.0.3']
fail-fast: false
steps:
- uses: actions/checkout@v3
- name: sushichop/gha-swift-env@v1
- uses: actions/checkout@v4
- name: gha-swift-env-local
uses: ./
with:
swift-version: ${{ matrix.swift-version }}
- name: Show Swift version
run: swift --version
- name: Build with CMake and Ninja
run: |
sudo apt-get -qq update && sudo apt-get -qq install -y ninja-build
cmake --version
ninja --version
cmake -B ./build -D CMAKE_C_COMPILER=clang -D CMAKE_BUILD_TYPE=RelWithDebInfo -G Ninja -S .
ninja -C ./build -v
CMake-Windows:
name: CMake directly - Swift ${{ matrix.swift-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ['windows-latest']
swift-version: ['6.0.3']
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: gha-swift-env-local
uses: ./
with:
swift-version: ${{ matrix.swift-version }}
- name: Build with CMake and Ninja
run: |
choco install ninja --yes --no-progress
cmake --version
ninja --version
$SwiftFlags = '-sdk ' + "$Env:SDKROOT".Replace('\', '/')
cmake -B ./build -D CMAKE_C_COMPILER=clang -D CMAKE_BUILD_TYPE=Release -D CMAKE_Swift_FLAGS=$SwiftFlags -G Ninja -S .
ninja -C ./build -v
Expand All @@ -100,18 +152,18 @@ jobs:
strategy:
matrix:
os: ['windows-latest']
swift-version: ['5.7.1']
swift-version: ['6.0.3']
fail-fast: false
steps:
- uses: actions/checkout@v3
- name: sushichop/gha-swift-env@v1
- uses: actions/checkout@v4
- name: gha-swift-env-local
uses: ./
with:
swift-version: ${{ matrix.swift-version }}
- name: Show Swift version
run: swift --version
# Check C:\hostedtoolcache\windows\node\x.y.z\x64
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 18
node-version: 'lts/*'
- run: node -v
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2022 Koichi Yokota
Copyright (c) 2022-2025 Koichi Yokota

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
46 changes: 15 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,37 @@
![CI](https://github.com/sushichop/gha-swift-env/workflows/CI/badge.svg)
[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/sushichop/gha-swift-env/blob/main/LICENSE)

`gha-swift-env` is a GitHub Action that sets up a Swift environment for **cross-platform(macOS, Ubuntu Linux, and Windows)**.

And it also automatically installs Ninja, which is required for building a Swift code with CMake.
`gha-swift-env` is a GitHub Action that sets up Swift environment for **cross-platform(macOS, Ubuntu Linux, and Windows)**.

## Usage

You can set the Swift version of the release.
You can set the release version of Swift.

```yaml
- uses: sushichop/gha-swift-env@v1
with:
swift-version: '5.6'
- name: Show Swift version and build a Swift package
swift-version: '6.0.3'
- name: Show Swift version and build Swift package
run: |
swift --version
swift build -v -c release
```
You can also set the Swift version of the snapshot.
You can also set the snapshot version of Swift.
```yaml
- uses: sushichop/gha-swift-env@v1
with:
swift-version: '2022-07-20-a'
- name: Show Swift version and build a Swift package
swift-version: '2025-01-10-a'
- name: Show Swift version and build Swift package
run: |
swift --version
swift build -v -c release
```
## Example
You can build and test a Swift package on cross-platform(macOS, Ubuntu Linux, and Windows).
You can build and test Swift package for cross-platform(macOS, Ubuntu Linux, and Windows).
```yaml
Expand All @@ -50,11 +48,11 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ['macos-11', 'ubuntu-latest', 'windows-latest']
swift-version: ['5.6', '2022-07-20-a']
os: ['macos-14', 'ubuntu-22.04', 'windows-2022']
swift-version: ['6.0.3', '5.10', '2025-01-10-a']
fail-fast: false
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: sushichop/gha-swift-env@V1
with:
swift-version: ${{ matrix.swift-version }}
Expand All @@ -64,31 +62,17 @@ jobs:
swift test -v -Xswiftc -warnings-as-errors
```
You can also build a Swift package with CMake and Ninja.
```yaml
- uses: sushichop/gha-swift-env@v1
with:
swift-version: '5.4.2'
- name: Build with CMake and Ninja
run: |
cmake -B ./build -DCMAKE_C_COMPILER=clang -DCMAKE_BUILD_TYPE=RelWithDebInfo -G Ninja -S .
ninja -C ./build -v
```
## Inputs
- `swift-version` – (required) Swift version to use
- Specify release or snapshot version
- `'5.4.2'`, `'5.6'`, `'2022-01-09-a'`, ...
- `'5.10'`, `'6.0.3'`, `'2025-01-10-a'`, ...
- Default
- `'5.4.2'`
- This value is the minimum Swift version to support Swift
package on cross-platform

- `'6.0.3'`

- `winsdk-version` – (optional) WinSDK to use on Windows
- Specify Windows 10 SDK version
- `''`, `'10.019041.0'`, `'10.0.20348.0'`, ...
- `''`, `'10.0.26100.0'`, ...
- Default:
- `''`
- This value(an empty string) sets the default Windows 10 SDK version
Expand Down
Loading

0 comments on commit ef736c6

Please sign in to comment.