From db1f03e4d1889749accf6a12c70473bdf2a96cb5 Mon Sep 17 00:00:00 2001 From: Nikita Vasilev Date: Wed, 3 Dec 2025 10:10:05 +0400 Subject: [PATCH] feat: switch from Makefile to Mise --- .github/workflows/ci.yml | 188 +++++------------- .swiftformat | 2 +- .swiftlint.yml | 2 - Makefile | 19 -- .../IRetryPolicyService.swift | 2 +- .../RetryPolicyService.swift | 2 +- .../Strategy/RetryPolicyStrategy.swift | 14 +- .../UnitTests/RetryPolicyServiceTests.swift | 2 +- hooks/pre-commit | 38 ---- mise.toml | 10 + mise/tasks/install.sh | 57 ++++++ mise/tasks/lint | 13 ++ 12 files changed, 146 insertions(+), 203 deletions(-) delete mode 100644 Makefile delete mode 100755 hooks/pre-commit create mode 100644 mise.toml create mode 100755 mise/tasks/install.sh create mode 100755 mise/tasks/lint diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 772bff4..638af61 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,16 @@ on: - "Source/**" - "Tests/**" +permissions: + contents: read + +concurrency: + group: typhoon-${{ github.head_ref }} + cancel-in-progress: true + +env: + SCHEME_NAME: "Typhoon" + jobs: SwiftLint: runs-on: ubuntu-latest @@ -24,37 +34,8 @@ jobs: args: --strict env: DIFF_BASE: ${{ github.base_ref }} - macOS: - name: ${{ matrix.name }} - runs-on: ${{ matrix.runsOn }} - env: - DEVELOPER_DIR: "/Applications/${{ matrix.xcode }}.app/Contents/Developer" - timeout-minutes: 20 - strategy: - fail-fast: false - matrix: - include: - - xcode: "Xcode_26.0.1" - runsOn: macOS-26 - name: "macOS 26, Xcode 26.0, Swift 6.2.0" - - xcode: "Xcode_16.1" - runsOn: macOS-14 - name: "macOS 14, Xcode 16.1, Swift 6.0.2" - - xcode: "Xcode_15.4" - runsOn: macOS-14 - name: "macOS 14, Xcode 15.4, Swift 5.10" - steps: - - uses: actions/checkout@v5 - - name: ${{ matrix.name }} - run: xcodebuild test -scheme "Typhoon" -destination "platform=macOS" clean -enableCodeCoverage YES -resultBundlePath "test_output/${{ matrix.name }}.xcresult" || exit 1 - - name: Upload test coverage reports to Codecov - uses: space-code/oss-common-actions/.github/actions/upload_test_coverage_report@main - with: - scheme_name: Typhoon - filename: ${{ matrix.name }} - token: ${{ secrets.CODECOV_TOKEN }} - iOS: + test-apple-platforms: name: ${{ matrix.name }} runs-on: ${{ matrix.runsOn }} env: @@ -64,100 +45,45 @@ jobs: fail-fast: false matrix: include: - - destination: "OS=26.0.1,name=iPhone 17 Pro" - xcode: "Xcode_26.0.1" - runsOn: macOS-26 - name: "OS=26.0, Xcode 26.0, Swift 6.2.0" - - destination: "OS=18.1,name=iPhone 16 Pro" - name: "iOS 18.1" - xcode: "Xcode_16.1" - runsOn: macOS-14 - - destination: "OS=17.4,name=iPhone 15 Pro" - name: "iOS 17.4" - xcode: "Xcode_15.3" - runsOn: macos-14 - steps: - - uses: actions/checkout@v5 - - name: ${{ matrix.name }} - run: xcodebuild test -scheme "Typhoon" -destination "${{ matrix.destination }}" clean -enableCodeCoverage YES -resultBundlePath "test_output/${{ matrix.name }}.xcresult" || exit 1 - - name: Upload test coverage reports to Codecov - uses: space-code/oss-common-actions/.github/actions/upload_test_coverage_report@main - with: - scheme_name: Typhoon - filename: ${{ matrix.name }} - token: ${{ secrets.CODECOV_TOKEN }} + # macOS + - { platform: macOS, name: "macOS 26, Xcode 26.0, Swift 6.2.0", xcode: "Xcode_26.0.1", runsOn: macOS-26, destination: "platform=macOS" } + - { platform: macOS, name: "macOS 14, Xcode 16.1, Swift 6.0.2", xcode: "Xcode_16.1", runsOn: macOS-14, destination: "platform=macOS" } + - { platform: macOS, name: "macOS 14, Xcode 15.4, Swift 5.10", xcode: "Xcode_15.4", runsOn: macOS-14, destination: "platform=macOS" } - tvOS: - name: ${{ matrix.name }} - runs-on: ${{ matrix.runsOn }} - env: - DEVELOPER_DIR: "/Applications/${{ matrix.xcode }}.app/Contents/Developer" - timeout-minutes: 20 - strategy: - fail-fast: false - matrix: - include: - - destination: "OS=26.0,name=Apple TV" - xcode: "Xcode_26.0.1" - runsOn: macOS-26 - name: "tvOS 26.0" - - destination: "OS=18.1,name=Apple TV" - name: "tvOS 18.1" - xcode: "Xcode_16.1" - runsOn: macOS-14 - - destination: "OS=17.4,name=Apple TV" - name: "tvOS 17.4" - xcode: "Xcode_15.3" - runsOn: macos-14 - steps: - - uses: actions/checkout@v5 - - name: ${{ matrix.name }} - run: xcodebuild test -scheme "Typhoon" -destination "${{ matrix.destination }}" clean -enableCodeCoverage YES -resultBundlePath "test_output/${{ matrix.name }}.xcresult" || exit 1 - - name: Upload test coverage reports to Codecov - uses: space-code/oss-common-actions/.github/actions/upload_test_coverage_report@main - with: - scheme_name: Typhoon - filename: ${{ matrix.name }} - token: ${{ secrets.CODECOV_TOKEN }} + # iOS + - { platform: iOS, name: "iOS 26.0, Xcode 26.0, Swift 6.2.0", xcode: "Xcode_26.0.1", runsOn: macOS-26, destination: "OS=26.0.1,name=iPhone 17 Pro" } + - { platform: iOS, name: "iOS 18.1", xcode: "Xcode_16.1", runsOn: macOS-14, destination: "OS=18.1,name=iPhone 16 Pro" } + - { platform: iOS, name: "iOS 17.4", xcode: "Xcode_15.3", runsOn: macOS-14, destination: "OS=17.4,name=iPhone 15 Pro" } - watchOS: - name: ${{ matrix.name }} - runs-on: ${{ matrix.runsOn }} - env: - DEVELOPER_DIR: "/Applications/${{ matrix.xcode }}.app/Contents/Developer" - timeout-minutes: 20 - strategy: - fail-fast: false - matrix: - include: - - destination: "OS=26.0,name=Apple Watch Ultra 3 (49mm)" - xcode: "Xcode_26.0.1" - runsOn: macOS-26 - name: "watchOS 26.0" - - destination: "OS=11.1,name=Apple Watch Series 10 (46mm)" - name: "watchOS 11.1" - xcode: "Xcode_16.1" - runsOn: macOS-14 - - destination: "OS=10.5,name=Apple Watch Series 9 (45mm)" - name: "watchOS 10.5" - xcode: "Xcode_15.3" - runsOn: macOS-14 - - destination: "OS=10.4,name=Apple Watch Series 9 (45mm)" - name: "watchOS 10.4" - xcode: "Xcode_15.3" - runsOn: macos-14 + # tvOS + - { platform: tvOS, name: "tvOS 26.0", xcode: "Xcode_26.0.1", runsOn: macOS-26, destination: "OS=26.0,name=Apple TV" } + - { platform: tvOS, name: "tvOS 18.1", xcode: "Xcode_16.1", runsOn: macOS-14, destination: "OS=18.1,name=Apple TV" } + - { platform: tvOS, name: "tvOS 17.4", xcode: "Xcode_15.3", runsOn: macOS-14, destination: "OS=17.4,name=Apple TV" } + + # watchOS + - { platform: watchOS, name: "watchOS 26.0", xcode: "Xcode_26.0.1", runsOn: macOS-26, destination: "OS=26.0,name=Apple Watch Ultra 3 (49mm)" } + - { platform: watchOS, name: "watchOS 11.1", xcode: "Xcode_16.1", runsOn: macOS-14, destination: "OS=11.1,name=Apple Watch Series 10 (46mm)" } + - { platform: watchOS, name: "watchOS 10.5", xcode: "Xcode_15.3", runsOn: macOS-14, destination: "OS=10.5,name=Apple Watch Series 9 (45mm)" } + - { platform: watchOS, name: "watchOS 10.4", xcode: "Xcode_15.3", runsOn: macOS-14, destination: "OS=10.4,name=Apple Watch Series 9 (45mm)" } steps: - - uses: actions/checkout@v5 - - name: ${{ matrix.name }} - run: xcodebuild test -scheme "Typhoon" -destination "${{ matrix.destination }}" clean -enableCodeCoverage YES -resultBundlePath "test_output/${{ matrix.name }}.xcresult" || exit 1 - - name: Upload test coverage reports to Codecov + - name: Checkout code + uses: actions/checkout@v5 + - name: Run tests - ${{ matrix.name }} + run: | + xcodebuild test \ + -scheme "${{ env.SCHEME_NAME }}" \ + -destination "${{ matrix.destination }}" \ + -enableCodeCoverage YES \ + -resultBundlePath "test_output/${{ matrix.name }}.xcresult" \ + clean || exit 1 + - name: Upload test coverage to Codecov uses: space-code/oss-common-actions/.github/actions/upload_test_coverage_report@main with: - scheme_name: Typhoon + scheme_name: ${{ env.SCHEME_NAME }} filename: ${{ matrix.name }} token: ${{ secrets.CODECOV_TOKEN }} - spm: + spm-build: name: ${{ matrix.name }} runs-on: ${{ matrix.runsOn }} env: @@ -167,37 +93,33 @@ jobs: fail-fast: false matrix: include: - - destination: "macOS 26, SPM 6.2.0 Test" - xcode: "Xcode_26.0.1" - runsOn: macOS-26 - - destination: "macOS 15, SPM 6.0.2 Test" - xcode: "Xcode_16.0" - runsOn: macOS-15 - - name: "macOS 14, SPM 6.0.2 Test" - xcode: "Xcode_16.1" - runsOn: macOS-14 - - name: "macOS 14, SPM 5.10.0 Test" - xcode: "Xcode_15.3" - runsOn: macos-14 + - { name: "macOS 26, SPM 6.2.0", xcode: "Xcode_26.0.1", runsOn: macOS-26 } + - { name: "macOS 15, SPM 6.0.2", xcode: "Xcode_16.0", runsOn: macOS-15 } + - { name: "macOS 14, SPM 6.0.2", xcode: "Xcode_16.1", runsOn: macOS-14 } + - { name: "macOS 14, SPM 5.10.0", xcode: "Xcode_15.3", runsOn: macOS-14 } steps: - - uses: actions/checkout@v5 - - name: ${{ matrix.name }} + - name: Checkout code + uses: actions/checkout@v5 + - name: Build with Swift Package Manager - ${{ matrix.name }} run: swift build -c release merge-test-reports: - needs: [iOS, macOS, watchOS, tvOS] + needs: test-apple-platforms runs-on: macos-15 steps: - name: Download artifacts uses: actions/download-artifact@v6 with: path: test_output + - run: xcrun xcresulttool merge test_output/**/*.xcresult --output-path test_output/final/final.xcresult - - name: Upload Merged Artifact + + - name: Upload merged test results uses: actions/upload-artifact@v5 with: - name: MergedResult + name: MergedTestResults path: test_output/final + retention-days: 30 discover-typos: name: Discover Typos diff --git a/.swiftformat b/.swiftformat index bb0e67c..e6e1917 100644 --- a/.swiftformat +++ b/.swiftformat @@ -1,6 +1,6 @@ # Stream rules ---swiftversion 5.3 +--swiftversion 5.10 # Use 'swiftformat --options' to list all of the possible options diff --git a/.swiftlint.yml b/.swiftlint.yml index f63618f..7990dc4 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -15,7 +15,6 @@ disabled_rules: - opening_brace opt_in_rules: # some rules are only opt-in - - anyobject_protocol - array_init - attributes - closure_body_length @@ -44,7 +43,6 @@ opt_in_rules: # some rules are only opt-in - ibinspectable_in_extension - identical_operands - implicit_return - - inert_defer - joined_default_parameter - last_where - legacy_multiple diff --git a/Makefile b/Makefile deleted file mode 100644 index 856d64b..0000000 --- a/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -all: bootstrap - -bootstrap: hook - mint bootstrap - -hook: - ln -sf ../../hooks/pre-commit .git/hooks/pre-commit - chmod +x .git/hooks/pre-commit - -mint: - mint bootstrap - -lint: - mint run swiftlint - -fmt: - mint run swiftformat Sources Tests - -.PHONY: all bootstrap hook mint lint fmt \ No newline at end of file diff --git a/Sources/Typhoon/Classes/RetryPolicyService/IRetryPolicyService.swift b/Sources/Typhoon/Classes/RetryPolicyService/IRetryPolicyService.swift index 64fbbe3..9c6b570 100644 --- a/Sources/Typhoon/Classes/RetryPolicyService/IRetryPolicyService.swift +++ b/Sources/Typhoon/Classes/RetryPolicyService/IRetryPolicyService.swift @@ -1,6 +1,6 @@ // // Typhoon -// Copyright © 2024 Space Code. All rights reserved. +// Copyright © 2023 Space Code. All rights reserved. // import Foundation diff --git a/Sources/Typhoon/Classes/RetryPolicyService/RetryPolicyService.swift b/Sources/Typhoon/Classes/RetryPolicyService/RetryPolicyService.swift index 16f7c33..3a69e71 100644 --- a/Sources/Typhoon/Classes/RetryPolicyService/RetryPolicyService.swift +++ b/Sources/Typhoon/Classes/RetryPolicyService/RetryPolicyService.swift @@ -1,6 +1,6 @@ // // Typhoon -// Copyright © 2024 Space Code. All rights reserved. +// Copyright © 2023 Space Code. All rights reserved. // import Foundation diff --git a/Sources/Typhoon/Classes/Strategy/RetryPolicyStrategy.swift b/Sources/Typhoon/Classes/Strategy/RetryPolicyStrategy.swift index e03c3a7..72bfe71 100644 --- a/Sources/Typhoon/Classes/Strategy/RetryPolicyStrategy.swift +++ b/Sources/Typhoon/Classes/Strategy/RetryPolicyStrategy.swift @@ -1,6 +1,6 @@ // // Typhoon -// Copyright © 2024 Space Code. All rights reserved. +// Copyright © 2023 Space Code. All rights reserved. // import Foundation @@ -42,11 +42,11 @@ public enum RetryPolicyStrategy: Sendable { public var retries: Int { switch self { case let .constant(retry, _): - return retry + retry case let .exponential(retry, _, _): - return retry + retry case let .exponentialWithJitter(retry, _, _, _, _): - return retry + retry } } @@ -54,11 +54,11 @@ public enum RetryPolicyStrategy: Sendable { public var duration: DispatchTimeInterval { switch self { case let .constant(_, duration): - return duration + duration case let .exponential(_, _, duration): - return duration + duration case let .exponentialWithJitter(_, _, _, _, duration): - return duration + duration } } } diff --git a/Tests/TyphoonTests/UnitTests/RetryPolicyServiceTests.swift b/Tests/TyphoonTests/UnitTests/RetryPolicyServiceTests.swift index 28752af..ad9e69b 100644 --- a/Tests/TyphoonTests/UnitTests/RetryPolicyServiceTests.swift +++ b/Tests/TyphoonTests/UnitTests/RetryPolicyServiceTests.swift @@ -1,6 +1,6 @@ // // Typhoon -// Copyright © 2024 Space Code. All rights reserved. +// Copyright © 2023 Space Code. All rights reserved. // import Typhoon diff --git a/hooks/pre-commit b/hooks/pre-commit deleted file mode 100755 index 956fdcb..0000000 --- a/hooks/pre-commit +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash -git diff --diff-filter=d --staged --name-only | grep -e '\.swift$' | while read line; do - if [[ $line == *"/Generated"* ]]; then - echo "IGNORING GENERATED FILE: " "$line"; - else - mint run swiftformat swiftformat "${line}"; - git add "$line"; - fi -done - -LINT=$(which mint) -if [[ -e "${LINT}" ]]; then - # Export files in SCRIPT_INPUT_FILE_$count to lint against later - count=0 - while IFS= read -r file_path; do - export SCRIPT_INPUT_FILE_$count="$file_path" - count=$((count + 1)) - done < <(git diff --name-only --cached --diff-filter=d | grep ".swift$") - export SCRIPT_INPUT_FILE_COUNT=$count - - if [ "$count" -eq 0 ]; then - echo "No files to lint!" - exit 0 - fi - - echo "Found $count lintable files! Linting now.." - mint run swiftlint --use-script-input-files --strict --config .swiftlint.yml - RESULT=$? # swiftline exit value is number of errors - - if [ $RESULT -eq 0 ]; then - echo "🎉 Well done. No violation." - fi - exit $RESULT -else - echo "⚠️ WARNING: SwiftLint not found" - echo "⚠️ You might want to edit .git/hooks/pre-commit to locate your swiftlint" - exit 0 -fi \ No newline at end of file diff --git a/mise.toml b/mise.toml new file mode 100644 index 0000000..9e7282a --- /dev/null +++ b/mise.toml @@ -0,0 +1,10 @@ +[tools] +git-cliff = "2.9.1" +swiftlint = "0.62.2" +swiftformat = "0.58.7" + +[settings] +experimental = true + +[hooks] +postinstall = "mise run install" \ No newline at end of file diff --git a/mise/tasks/install.sh b/mise/tasks/install.sh new file mode 100755 index 0000000..efcc5e3 --- /dev/null +++ b/mise/tasks/install.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +set -e + +echo "🔧 Installing git hooks..." + +# Find git repository root +GIT_ROOT=$(git rev-parse --show-toplevel 2>/dev/null) + +if [ -z "$GIT_ROOT" ]; then + echo "❌ Error: Not a git repository" + exit 1 +fi + +echo "📁 Git root: $GIT_ROOT" + +# Create hooks directory if it doesn't exist +mkdir -p "$GIT_ROOT/.git/hooks" + +# Create pre-commit hook +cat > "$GIT_ROOT/.git/hooks/pre-commit" <<'HOOK_EOF' +#!/bin/bash + +echo "🔍 Running linters..." + +echo "📝 Formatting staged Swift files..." +git diff --diff-filter=d --staged --name-only | grep -e '\.swift$' | while read line; do + if [[ $line == *"/Generated"* ]]; then + echo "⏭️ Skipping generated file: $line" + else + echo "✨ Formatting: $line" + mise exec swiftformat -- swiftformat "${line}" + git add "$line" + fi +done + +if ! mise run lint; then + echo "❌ Lint failed. Please fix the issues before committing." + echo "💡 Tip: Run 'mise run format' to auto-fix some issues" + echo "⚠️ To skip this hook, use: git commit --no-verify" + exit 1 +fi + +echo "✅ All checks passed!" +exit 0 +HOOK_EOF + +chmod +x "$GIT_ROOT/.git/hooks/pre-commit" + +echo "✅ Git hooks installed successfully!" +echo "📍 Hook location: $GIT_ROOT/.git/hooks/pre-commit" +echo "" +echo "Pre-commit hook will:" +echo " 1. Format staged Swift files (except /Generated)" +echo " 2. Run mise lint" +echo "" +echo "To skip the hook, use: git commit --no-verify" diff --git a/mise/tasks/lint b/mise/tasks/lint new file mode 100755 index 0000000..cd07c0c --- /dev/null +++ b/mise/tasks/lint @@ -0,0 +1,13 @@ +#!/bin/bash +#MISE description="Lint the validator package using SwiftLint and SwiftFormat" +#MISE usage flag "-f --fix" help="Fix the fixable issues" + +set -eo pipefail + +if [ "$usage_fix" = "true" ]; then + swiftformat Sources Tests + swiftlint lint --fix --strict --config .swiftlint.yml Sources Tests +else + swiftformat Sources Tests --lint + swiftlint lint --strict --config .swiftlint.yml Sources Tests +fi \ No newline at end of file