chore(package): initial package config and files #17
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI — digipin-swift | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - "Sources/**" | |
| - "Tests/**" | |
| - "Package.swift" | |
| - ".github/workflows/ci.yml" | |
| pull_request: | |
| branches: [main] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| env: | |
| SWIFT_VERSION: "6.2" | |
| jobs: | |
| test: | |
| name: Build & Test (${{ matrix.os }}) | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| platform: linux | |
| - os: macos-latest | |
| platform: macos | |
| - os: windows-latest | |
| platform: windows | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 | |
| with: | |
| fetch-depth: 0 | |
| - name: Cache Swiftly | |
| id: cache-swiftly | |
| if: matrix.platform != 'windows' | |
| uses: actions/cache@8b402f58fbc84540c8b491a91e594a4576fec3d7 # v5.0.2 | |
| with: | |
| path: | | |
| ~/.swiftly | |
| ~/.local/share/swiftly | |
| key: swiftly-${{ matrix.platform }}-swift-${{ env.SWIFT_VERSION }} | |
| restore-keys: | | |
| swiftly-${{ matrix.platform }}- | |
| # ------------------------------------------------- | |
| # Linux — Swiftly (official prebuilt binary) | |
| # ------------------------------------------------- | |
| - name: Install Swift (Linux via Swiftly) | |
| if: matrix.platform == 'linux' && steps.cache-swiftly.outputs.cache-hit != 'true' | |
| run: | | |
| set -euxo pipefail | |
| curl --proto '=https' -fsSL \ | |
| https://download.swift.org/swiftly/linux/swiftly-$(uname -m).tar.gz \ | |
| -o swiftly.tar.gz | |
| tar zxf swiftly.tar.gz | |
| ./swiftly init --quiet-shell-followup -o -y | |
| . "${SWIFTLY_HOME_DIR:-$HOME/.local/share/swiftly}/env.sh" | |
| hash -r | |
| - name: Configure Swiftly PATH (Linux) | |
| if: matrix.platform == 'linux' | |
| run: | | |
| echo "$HOME/.local/share/swiftly/bin" >> "$GITHUB_PATH" | |
| # ------------------------------------------------- | |
| # macOS — Swiftly (official pkg installer) | |
| # ------------------------------------------------- | |
| - name: Install Swift (macOS via Swiftly pkg) | |
| if: matrix.platform == 'macos' && steps.cache-swiftly.outputs.cache-hit != 'true' | |
| run: | | |
| set -euxo pipefail | |
| curl --proto '=https' -fsSL https://download.swift.org/swiftly/darwin/swiftly.pkg -o swiftly.pkg | |
| installer -pkg swiftly.pkg -target CurrentUserHomeDirectory | |
| - name: Initialize Swiftly (macOS) | |
| if: matrix.platform == 'macos' | |
| run: | | |
| ~/.swiftly/bin/swiftly init --quiet-shell-followup && \ | |
| . "${SWIFTLY_HOME_DIR:-$HOME/.swiftly}/env.sh" && \ | |
| hash -r | |
| # ------------------------------------------------- | |
| # Select Swift toolchain (Swiftly) | |
| # ------------------------------------------------- | |
| - name: Select Swift toolchain | |
| if: matrix.platform != 'windows' | |
| run: | | |
| swiftly install $SWIFT_VERSION || true | |
| swiftly use $SWIFT_VERSION -g -y | |
| # ------------------------------------------------- | |
| # Windows — Swift + MSVC via WinGet (official) | |
| # ------------------------------------------------- | |
| - name: Install Swift (Windows via winget) | |
| if: matrix.platform == 'windows' | |
| shell: pwsh | |
| run: | | |
| winget install --id Microsoft.VisualStudio.2022.Community ` | |
| --exact --force ` | |
| --custom "--add Microsoft.VisualStudio.Component.Windows11SDK.22621 ` | |
| --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 ` | |
| --add Microsoft.VisualStudio.Component.VC.Tools.ARM64" | |
| winget install --id Swift.Toolchain -e ` | |
| --accept-source-agreements ` | |
| --accept-package-agreements | |
| - name: Locate Swift toolchain (Windows) | |
| if: matrix.platform == 'windows' | |
| shell: pwsh | |
| run: | | |
| $paths = @( | |
| "C:\Library\Developer\Toolchains", | |
| "C:\Program Files\Swift" | |
| ) | |
| foreach ($base in $paths) { | |
| if (Test-Path $base) { | |
| $swift = Get-ChildItem $base -Recurse -Filter swift.exe -ErrorAction SilentlyContinue | Select-Object -First 1 | |
| if ($swift) { | |
| $bin = Split-Path $swift.FullName | |
| Write-Host "Found swift at $bin" | |
| $bin | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append | |
| exit 0 | |
| } | |
| } | |
| } | |
| Write-Error "swift.exe not found" | |
| exit 1 | |
| # ------------------------------------------------- | |
| # Core CI steps | |
| # ------------------------------------------------- | |
| - name: Verify Swift toolchain | |
| run: swift --version | |
| - name: Cache SwiftPM | |
| uses: actions/cache@8b402f58fbc84540c8b491a91e594a4576fec3d7 # v5.0.2 | |
| with: | |
| path: .build | |
| key: spm-${{ matrix.platform }}-${{ hashFiles('Package.swift') }} | |
| restore-keys: | | |
| spm-${{ matrix.platform }}- | |
| - name: Build (debug) | |
| run: swift build --configuration debug | |
| - name: Test | |
| run: swift test --enable-test-discovery | |
| - name: Upload build artifacts (on failure) | |
| if: failure() | |
| uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # 6.0.0 | |
| with: | |
| name: swift-build-${{ matrix.os }} | |
| path: | | |
| .build/ |