Skip to content

Commit 645aff8

Browse files
authored
ci: unify Swift selection, runner OS across actions (#41)
* chore: update release docs * chore: bump BinaryDependenciesManager version * ci: universal approach to caching and swift selection * chore: save * chore: ci * fix: action template path * fix: action template * chore: remove ENV output
1 parent 368e337 commit 645aff8

File tree

6 files changed

+163
-46
lines changed

6 files changed

+163
-46
lines changed

.github/workflows/build-multi-platform-binary.yml

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
- '*'
1010

1111
jobs:
12+
load-env:
13+
uses: ./.github/workflows/load-env.yml
14+
1215
create-release:
1316
runs-on: ubuntu-latest
1417
outputs:
@@ -33,22 +36,27 @@ jobs:
3336
run: node ./.github/workflows/scripts/build-multi-platform-binary/check-release.js
3437

3538
build-binary:
36-
needs: create-release
39+
needs: [load-env, create-release]
40+
env:
41+
package_name: ${{ needs.load-env.outputs.package-name }}
3742
strategy:
3843
matrix:
3944
include:
40-
- os: macos-latest
41-
platform: macOS
45+
- os: ${{ needs.load-env.outputs.macOS-runner-os }}
4246
arch: universal
43-
- os: macos-latest
44-
platform: macOS
47+
xcode-version: ${{ needs.load-env.outputs.xcode-version }}
48+
swift-version: ${{ needs.load-env.outputs.swift-version }}
49+
- os: ${{ needs.load-env.outputs.macOS-runner-os }}
4550
arch: arm64
46-
- os: macos-latest
47-
platform: macOS
51+
xcode-version: ${{ needs.load-env.outputs.xcode-version }}
52+
swift-version: ${{ needs.load-env.outputs.swift-version }}
53+
- os: ${{ needs.load-env.outputs.macOS-runner-os }}
4854
arch: x86_64
55+
xcode-version: ${{ needs.load-env.outputs.xcode-version }}
56+
swift-version: ${{ needs.load-env.outputs.swift-version }}
4957
- os: ubuntu-latest
50-
platform: linux
5158
arch: x86_64
59+
swift-version: ${{ needs.load-env.outputs.swift-version }}
5260
runs-on: ${{ matrix.os }}
5361

5462
steps:
@@ -60,13 +68,25 @@ jobs:
6068
- name: Checkout tag
6169
run: git checkout ${{ needs.create-release.outputs.tag_name }}
6270

71+
- name: Select Swift Version
72+
uses: ./.github/workflows/templates/select-swift-version/
73+
with:
74+
xcode-version: ${{ matrix.xcode-version }}
75+
swift-version: ${{ matrix.swift-version }}
76+
77+
- name: Cache Swift Packages
78+
uses: ./.github/workflows/templates/swift-cache/
79+
with:
80+
package-name: ${{ env.package_name }}
81+
build-system: swift
82+
6383
- name: Check if asset already exists
6484
id: check-asset
6585
env:
6686
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6787
RELEASE_ID: ${{ needs.create-release.outputs.release_id }}
6888
TAG_NAME: ${{ needs.create-release.outputs.tag_name }}
69-
PLATFORM: ${{ matrix.platform }}
89+
PLATFORM: ${{ runner.os }}
7090
ARCH: ${{ matrix.arch }}
7191
run: node ./.github/workflows/scripts/build-multi-platform-binary/check-asset.js
7292

@@ -75,7 +95,7 @@ jobs:
7595
if: steps.check-asset.outputs.asset_exists == 'false'
7696
env:
7797
TAG_NAME: ${{ needs.create-release.outputs.tag_name }}
78-
PLATFORM: ${{ matrix.platform }}
98+
PLATFORM: ${{ runner.os }}
7999
ARCH: ${{ matrix.arch }}
80100
run: ./.github/workflows/scripts/build-multi-platform-binary/build-binary.sh
81101

.github/workflows/load-env.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Load Environment
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
package-name:
7+
description: 'Swift package name'
8+
type: string
9+
required: false
10+
default: 'binary-dependencies-manager'
11+
swift-version:
12+
description: 'Swift version'
13+
type: string
14+
required: false
15+
default: '6.1'
16+
xcode-version:
17+
description: 'Xcode version'
18+
type: string
19+
required: false
20+
default: '16.4'
21+
macOS-runner-os:
22+
description: 'macOS runner OS (macos-15, macos-latest)'
23+
type: string
24+
required: false
25+
default: 'macos-15'
26+
outputs:
27+
package-name:
28+
description: 'Swift package name'
29+
value: ${{ jobs.load-env.outputs.package-name }}
30+
swift-version:
31+
description: 'Swift version'
32+
value: ${{ jobs.load-env.outputs.swift-version }}
33+
xcode-version:
34+
description: 'Xcode version'
35+
value: ${{ jobs.load-env.outputs.xcode-version }}
36+
macOS-runner-os:
37+
description: 'macOS runner OS'
38+
value: ${{ jobs.load-env.outputs.macOS-runner-os }}
39+
40+
jobs:
41+
load-env:
42+
runs-on: ubuntu-latest
43+
outputs:
44+
package-name: ${{ steps.common-env.outputs.package-name }}
45+
swift-version: ${{ steps.common-env.outputs.swift-version }}
46+
xcode-version: ${{ steps.common-env.outputs.xcode-version }}
47+
macOS-runner-os: ${{ steps.common-env.outputs.macOS-runner-os }}
48+
steps:
49+
- name: Setup Common Environment
50+
id: common-env
51+
shell: bash
52+
run: |
53+
echo "package-name=${{ inputs.package-name }}" >> $GITHUB_OUTPUT
54+
echo "swift-version=${{ inputs.swift-version }}" >> $GITHUB_OUTPUT
55+
echo "xcode-version=${{ inputs.xcode-version }}" >> $GITHUB_OUTPUT
56+
echo "macOS-runner-os=${{ inputs.macOS-runner-os }}" >> $GITHUB_OUTPUT

.github/workflows/scripts/build-multi-platform-binary/build-binary.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ elif [ "$PLATFORM" == "macOS" ] && [[ "$ARCH" == "arm64" || "$ARCH" == "x86_64"
3333
# Verify the binary
3434
echo "Verifying binary..."
3535
file build/$BINARY_NAME
36-
elif [ "$PLATFORM" == "linux" ] && [ "$ARCH" == "x86_64" ]; then
36+
elif [ "$PLATFORM" == "Linux" ] && [ "$ARCH" == "x86_64" ]; then
3737
# Build for Linux x86_64
3838
echo "Building for Linux x86_64..."
3939
swift build --configuration release
@@ -54,7 +54,7 @@ cd build
5454
if [ "$PLATFORM" == "macOS" ]; then
5555
# Use ditto on macOS
5656
ditto -c -k --sequesterRsrc --keepParent $BINARY_NAME "../$ARCHIVE_NAME"
57-
elif [ "$PLATFORM" == "linux" ]; then
57+
elif [ "$PLATFORM" == "Linux" ]; then
5858
# Use zip on Linux
5959
zip "../$ARCHIVE_NAME" $BINARY_NAME
6060
else
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: 'Select Swift Version'
2+
description: 'Select Xcode version for Swift compilation'
3+
inputs:
4+
xcode-version:
5+
description: 'Xcode version to select'
6+
required: false
7+
default: '16.4'
8+
swift-version:
9+
description: 'Swift version to select'
10+
required: false
11+
default: ''
12+
runs:
13+
using: 'composite'
14+
steps:
15+
- name: Setup Xcode
16+
# Select Xcode for swift and xcodebuild.
17+
# We need 6.1 swift and setup-swift@v2 is broken.
18+
if: ${{ inputs.xcode-version != '' && runner.os == 'macOS' }}
19+
shell: bash
20+
run: sudo xcode-select -s '/Applications/Xcode_${{ inputs.xcode-version }}.app'
21+
22+
# Issues: https://github.com/swift-actions/setup-swift/issues/694, https://github.com/swift-actions/setup-swift/issues/739
23+
# Author is focused on new action version: https://github.com/swift-actions/setup-swift/pull/710
24+
# - name: Setup Swift (Linux)
25+
# if: ${{ inputs.swift-version != '' && runner.os == 'Linux' }}
26+
# uses: swift-actions/setup-swift@v2
27+
# with:
28+
# swift-version: ${{ matrix.swift-version }}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: 'Cache Swift Packages'
2+
description: 'Cache Swift Package Manager dependencies and build artifacts'
3+
inputs:
4+
package-name:
5+
description: 'Name of the Swift package'
6+
required: true
7+
build-system:
8+
description: 'Build system being used (swift or xcodebuild)'
9+
required: true
10+
default: ''
11+
runs:
12+
using: 'composite'
13+
steps:
14+
- name: Cache Swift packages
15+
uses: actions/cache@v4
16+
with:
17+
path: |
18+
.build/artifacts
19+
.build/checkouts
20+
.build/repositories
21+
.build/workspace-state.json
22+
DerivedData/${{ inputs.package-name }}/SourcePackages
23+
~/Library/Caches/org.swift.swiftpm/
24+
~/.cache/org.swift.swiftpm/
25+
key: ${{ runner.os }}-${{ inputs.build-system }}-spm-${{ hashFiles('**/Package.resolved') }}
26+
restore-keys: |
27+
${{ runner.os }}-${{ inputs.build-system }}-spm-

.github/workflows/test.yml

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,47 @@ on:
44
pull_request:
55
branches:
66
- main
7-
- chore/refactor
87

98
jobs:
9+
load-env:
10+
uses: ./.github/workflows/load-env.yml
11+
1012
test:
13+
needs: 'load-env'
1114
env:
12-
package_name: binary-dependencies-manager
15+
package_name: ${{ needs.load-env.outputs.package-name }}
1316

1417
strategy:
1518
matrix:
1619
include:
17-
- os: macos-15
20+
- os: ${{ needs.load-env.outputs.macOS-runner-os }}
1821
build-system: swift
19-
swift-version: '6.1'
20-
xcode-version: '16.4'
22+
swift-version: ${{ needs.load-env.outputs.swift-version }}
23+
xcode-version: ${{ needs.load-env.outputs.xcode-version }}
2124
- os: ubuntu-latest
2225
build-system: swift
23-
swift-version: '6.1'
24-
- os: macos-15
26+
swift-version: ${{ needs.load-env.outputs.swift-version }}
27+
- os: ${{ needs.load-env.outputs.macOS-runner-os }}
2528
build-system: xcodebuild
26-
xcode-version: '16.4'
29+
xcode-version: ${{ needs.load-env.outputs.xcode-version }}
2730

2831
runs-on: ${{ matrix.os }}
2932

3033
steps:
3134
- name: Checkout repository
3235
uses: actions/checkout@v4
3336

34-
# Issues: https://github.com/swift-actions/setup-swift/issues/694, https://github.com/swift-actions/setup-swift/issues/739
35-
# Author is focused on new action version: https://github.com/swift-actions/setup-swift/pull/710
36-
# - name: Setup Swift (Linux)
37-
# if: matrix.os == 'ubuntu-latest'
38-
# uses: swift-actions/setup-swift@v2
39-
# with:
40-
# swift-version: ${{ matrix.swift-version }}
41-
42-
- name: Setup Xcode
43-
# Select Xcode for swift and xcodebuild.
44-
# We need 6.1 swift and setup-swift@v2 is broken.
45-
if: matrix.xcode-version != ''
46-
run: sudo xcode-select -s '/Applications/Xcode_${{ matrix.xcode-version }}.app'
37+
- name: Select Swift Version
38+
uses: ./.github/workflows/templates/select-swift-version/
39+
with:
40+
xcode-version: ${{ matrix.xcode-version }}
41+
swift-version: ${{ matrix.swift-version }}
4742

48-
- name: Cache Swift packages
49-
uses: actions/cache@v4
43+
- name: Cache Swift Packages
44+
uses: ./.github/workflows/templates/swift-cache/
5045
with:
51-
path: |
52-
.build/artifacts
53-
.build/checkouts
54-
.build/repositories
55-
.build/workspace-state.json
56-
DerivedData/${{ env.package_name }}/SourcePackages
57-
~/Library/Caches/org.swift.swiftpm/
58-
~/.cache/org.swift.swiftpm/
59-
key: ${{ runner.os }}-${{ matrix.build-system }}-spm-${{ hashFiles('**/Package.resolved') }}
60-
restore-keys: |
61-
${{ runner.os }}-${{ matrix.build-system }}-spm-
46+
package-name: ${{ env.package_name }}
47+
build-system: ${{ matrix.build-system }}
6248

6349
- name: Build with Swift Package Manager
6450
if: matrix.build-system == 'swift'

0 commit comments

Comments
 (0)