Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions .github/workflows/octreotide-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: Octreotide CI

on:
push:
branches: [ feature/octreotide-algorithm ]
paths:
- 'Experimental/Octreotide/**'
pull_request:
branches: [ main ]
paths:
- 'Experimental/Octreotide/**'
workflow_dispatch: # Allow manual triggers

jobs:
test:
name: Run Tests
runs-on: macos-latest
strategy:
matrix:
xcode: ['14.3.1'] # Add more versions if needed
device: ['iPhone 14', 'iPhone 14 Pro', 'iPad Pro (12.9-inch) (6th generation)']

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Select Xcode ${{ matrix.xcode }}
run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app

- name: Run Unit Tests
run: |
xcodebuild test \
-workspace LoopWorkspace.xcworkspace \
-scheme LoopWorkspace \
-destination "platform=iOS Simulator,name=${{ matrix.device }},OS=latest" \
-only-testing:OctreotideAlgorithmTests \
-enableCodeCoverage YES \
-resultBundlePath TestResults.xcresult

- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v3
with:
name: test-results-${{ matrix.device }}
path: TestResults.xcresult

- name: Generate Coverage Report
if: success()
run: |
xcrun xccov view --report TestResults.xcresult > coverage-${{ matrix.device }}.txt

- name: Upload Coverage
if: success()
uses: actions/upload-artifact@v3
with:
name: code-coverage-${{ matrix.device }}
path: coverage-${{ matrix.device }}.txt

integration-tests:
name: Integration Tests
needs: unit-tests
runs-on: macos-latest

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode.app

- name: Run Simulation Tests
run: |
# Run simulator with different glucose patterns
xcodebuild test \
-workspace LoopWorkspace.xcworkspace \
-scheme LoopWorkspace \
-destination 'platform=iOS Simulator,name=iPhone 14,OS=latest' \
-only-testing:GlucoseSimulatorTests \
-resultBundlePath SimResults.xcresult

- name: Upload Simulation Results
if: always()
uses: actions/upload-artifact@v3
with:
name: simulation-results
path: SimResults.xcresult

build-only:
name: Build Without Signing
needs: [unit-tests, integration-tests]
runs-on: macos-latest

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode.app

- name: Build for Simulator
run: |
xcodebuild build \
-workspace LoopWorkspace.xcworkspace \
-scheme LoopWorkspace \
-destination 'platform=iOS Simulator,name=iPhone 14,OS=latest' \
-configuration Debug \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO

- name: Archive Build Logs
if: always()
uses: actions/upload-artifact@v3
with:
name: build-logs
path: ~/Library/Developer/Xcode/DerivedData/**/Logs/Build
84 changes: 84 additions & 0 deletions .github/workflows/testflight-upload.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: TestFlight Upload

on:
workflow_dispatch:
inputs:
build_type:
description: 'Build Type'
required: true
default: 'development'
type: choice
options:
- development
- release

env:
DEVELOPER_DIR: /Applications/Xcode.app/Contents/Developer
TEAMID: "5S2WW965AG"
FASTLANE_ISSUER_ID: "289e8063-2271-4b0a-9e3b-6376644ca657"
FASTLANE_KEY_ID: "KUT22ULSV9"

jobs:
build-and-upload:
name: Build and Upload to TestFlight
runs-on: macos-latest

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Apple Certificate
env:
BUILD_CERTIFICATE_BASE64: ${{ secrets.BUILD_CERTIFICATE_BASE64 }}
P12_PASSWORD: ${{ secrets.P12_PASSWORD }}
KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }}
run: |
# Create keychain
security create-keychain -p "$KEYCHAIN_PASSWORD" build.keychain
security default-keychain -s build.keychain
security unlock-keychain -p "$KEYCHAIN_PASSWORD" build.keychain
security set-keychain-settings -t 3600 -u build.keychain

# Import certificate
echo -n "$BUILD_CERTIFICATE_BASE64" | base64 --decode --output certificate.p12
security import certificate.p12 -k build.keychain -P "$P12_PASSWORD" -T /usr/bin/codesign
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KEYCHAIN_PASSWORD" build.keychain

- name: Install Ruby and Fastlane
run: |
gem install bundler
bundle install

- name: Setup Provisioning
env:
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
FASTLANE_KEY: ${{ secrets.FASTLANE_KEY }}
run: |
# Create fastlane match config
echo "FASTLANE_KEY='$FASTLANE_KEY'" > .env
bundle exec fastlane match appstore

- name: Build and Upload
env:
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
FASTLANE_KEY: ${{ secrets.FASTLANE_KEY }}
run: |
if [ "${{ github.event.inputs.build_type }}" = "release" ]; then
bundle exec fastlane release
else
bundle exec fastlane beta
fi

- name: Upload IPA
uses: actions/upload-artifact@v3
with:
name: loop-ipa
path: |
Loop.ipa
ExportOptions.plist

- name: Clean up keychain
if: always()
run: |
security delete-keychain build.keychain
53 changes: 53 additions & 0 deletions Experimental/Octreotide/GlucoseSimulator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import Foundation

/// Simulates glucose patterns for testing the Octreotide algorithm
struct GlucoseSimulator {
// Base glucose level (mg/dL)
private var baseLevel: Double
// Current trend direction (-1 to 1)
private var trendDirection: Double
// Noise amplitude (mg/dL)
private var noiseAmplitude: Double

init(baseLevel: Double = 80.0, trendDirection: Double = 0.0, noiseAmplitude: Double = 2.0) {
self.baseLevel = baseLevel
self.trendDirection = trendDirection
self.noiseAmplitude = noiseAmplitude
}

/// Generate simulated glucose values
/// - Parameters:
/// - count: Number of samples to generate
/// - intervalMinutes: Minutes between samples
func generateSamples(count: Int, intervalMinutes: Double = 5.0) -> [Double] {
var samples: [Double] = []
var currentLevel = baseLevel

for _ in 0..<count {
// Add random noise
let noise = Double.random(in: -noiseAmplitude...noiseAmplitude)

// Add trend
let trendChange = trendDirection * intervalMinutes

currentLevel += trendChange + noise
samples.append(currentLevel)

// Randomly adjust trend direction slightly
trendDirection += Double.random(in: -0.1...0.1)
trendDirection = max(-1.0, min(1.0, trendDirection))
}

return samples
}

/// Generate a falling glucose pattern
static func fallingPattern(from startLevel: Double = 90.0) -> GlucoseSimulator {
return GlucoseSimulator(baseLevel: startLevel, trendDirection: -0.5)
}

/// Generate a rising glucose pattern
static func risingPattern(from startLevel: Double = 70.0) -> GlucoseSimulator {
return GlucoseSimulator(baseLevel: startLevel, trendDirection: 0.5)
}
}
Loading