Skip to content
Merged
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
165 changes: 20 additions & 145 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Triggered by a version tag (v1.0.0): builds one DMG per architecture with
# ad-hoc signing and publishes a GitHub Release with checksums and first-launch
# instructions. Download URLs match the website convention agreed in fm-landing
# (site CTA points at /releases/latest).
# Triggered by a version tag (v1.0.0): publishes release notes and update instructions
# on GitHub Releases without producing ad-hoc prebuilt binaries (since File Provider
# extensions require local code signing with personal Apple ID for AMFI / App Groups).
name: Release

on:
Expand All @@ -12,150 +11,26 @@ permissions:
contents: write

jobs:
build-dmg:
name: Build DMG (${{ matrix.arch }})
runs-on: macos-26
strategy:
matrix:
arch: [arm64, x86_64]
steps:
- uses: actions/checkout@v7

- name: Cache pinned rclone runtime
uses: actions/cache@v6
with:
path: .build/rclone-artifacts
key: rclone-v1.75.1

- name: Install XcodeGen
run: brew install xcodegen

- name: Materialize build configuration
env:
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
run: |
if [ -n "$GOOGLE_CLIENT_ID" ]; then
printf 'FREEMOUNT_GOOGLE_CLIENT_ID = %s\nFREEMOUNT_GOOGLE_CLIENT_SECRET = %s\nDEVELOPMENT_TEAM =\n' \
"$GOOGLE_CLIENT_ID" "$GOOGLE_CLIENT_SECRET" > Configs/Secrets.xcconfig
else
cp Configs/Secrets.xcconfig.example Configs/Secrets.xcconfig
fi

- name: Generate Xcode project
run: xcodegen generate

- name: Build Release (${{ matrix.arch }})
run: |
xcodebuild -project FreeMount.xcodeproj -scheme FreeMount \
-configuration Release -destination 'platform=macOS' \
-derivedDataPath ci-derived \
ARCHS=${{ matrix.arch }} ONLY_ACTIVE_ARCH=NO \
CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO \
build

- name: Verify OAuth config embedded in built app
run: |
APP="ci-derived/Build/Products/Release/FM.app"
ID="$(plutil -extract FreeMountGoogleOAuthClientID raw "$APP/Contents/Info.plist" 2>/dev/null || true)"
if [ -z "$ID" ]; then
echo "::error=Built app has empty FREEMOUNT_GOOGLE_CLIENT_ID — xcconfig wiring or secrets broken"
exit 1
fi

- name: Stage app bundle (rename, prune foreign rclone runtime)
run: |
APP="ci-derived/Build/Products/Release/FM.app"
# Reclaim runner disk before image creation.
rm -rf "$HOME/Library/Developer/Xcode/DerivedData" \
ci-derived/Build/Intermediates.noindex
STAGE="dmg-stage"
mkdir -p "$STAGE"
# Ship as FreeMount.app even though PRODUCT_NAME is FM.
cp -R "$APP" "$STAGE/FreeMount.app"
# Slim DMG: keep only the rclone helper matching this build's arch.
if [ "${{ matrix.arch }}" = "arm64" ]; then
rm -f "$STAGE/FreeMount.app/Contents/Helpers/rclone-amd64"
else
rm -f "$STAGE/FreeMount.app/Contents/Helpers/rclone-arm64"
fi
ln -s /Applications "$STAGE/Applications"

- name: Ad-hoc sign staged bundle (nested Mach-O first, then app)
run: |
APP="dmg-stage/FreeMount.app"
# TODO(Task 12 spike): verify App Group + Keychain access group +
# File Provider registration survive ad-hoc signing on a clean Mac.
# Xcode expands $(TeamIdentifierPrefix)/$(AppIdentifierPrefix) only in
# its own signing step; manual codesign embeds them literally, so for
# ad-hoc (no team) builds we strip the empty prefixes ourselves.
python3 - <<'PYEOF'
import plistlib
def clean(src, dst):
d = plistlib.load(open(src, "rb"))
for k, v in list(d.items()):
if isinstance(v, list):
v = [s.replace("$(TeamIdentifierPrefix)", "").replace("$(AppIdentifierPrefix)", "")
if isinstance(s, str) else s for s in v]
d[k] = [s for s in v if s != ""]
elif isinstance(v, str):
d[k] = v.replace("$(TeamIdentifierPrefix)", "").replace("$(AppIdentifierPrefix)", "")
plistlib.dump(d, open(dst, "wb"))
clean("App/Resources/FreeMount.entitlements", "/tmp/app.ent")
clean("App/FileProviderExtension/FreeMountFileProvider.entitlements", "/tmp/ext.ent")
PYEOF
# CI builds with signing disabled, so bundled rclone helpers arrive
# unsigned; every Mach-O must carry a signature to run (required on
# Apple silicon), hence sign helpers -> appex -> app. Helpers now
# contain exactly one entry, matching this DMG's architecture.
find "$APP/Contents/Helpers" -type f -exec codesign --force --sign - {} \;
codesign --force --sign - --entitlements /tmp/ext.ent \
"$APP/Contents/PlugIns/FreeMountFileProvider.appex"
codesign --force --sign - --entitlements /tmp/app.ent "$APP"
codesign --verify --deep --strict --verbose=2 "$APP"
! codesign -d --entitlements - "$APP" 2>/dev/null | grep -q 'TeamIdentifierPrefix'

- name: Create DMG
run: |
hdiutil create -volname FreeMount -srcfolder dmg-stage -ov \
-format UDZO "FreeMount-${GITHUB_REF_NAME}-${{ matrix.arch }}.dmg"
shasum -a 256 "FreeMount-${GITHUB_REF_NAME}-${{ matrix.arch }}.dmg" >> checksums.txt
rm -rf dmg-stage

- name: Upload artifacts
uses: actions/upload-artifact@v7
with:
name: dmg-${{ matrix.arch }}
path: |
FreeMount-${{ github.ref_name }}-${{ matrix.arch }}.dmg
checksums.txt

publish-release:
name: Publish GitHub Release
needs: build-dmg
name: Publish Release Notes
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v8
with:
merge-multiple: true

- name: Release notes
id: notes
run: |
{
echo 'body<<EOF'
echo 'First-run note: builds are ad-hoc signed without Apple notarization (open source, no paid developer account). If macOS blocks the app, follow the steps in the repository README or remove quarantine with `xattr -dr com.apple.quarantine /Applications/FreeMount.app`.'
echo
echo '## Checksums'
echo '```'
cat checksums.txt
echo '```'
echo EOF
} >> "$GITHUB_OUTPUT"

- name: Create release
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
files: FreeMount-*.dmg
body: ${{ steps.notes.outputs.body }}
generate_release_notes: true
body: |
### Installing or Updating FreeMount

Because FreeMount uses Apple File Provider extensions, App Groups, and Keychain sharing, macOS requires it to be signed by your personal Apple ID team. Prebuilt unsigned or ad-hoc binaries cannot launch the extension on other Macs.

#### One-line Install / Update
Run the install script in Terminal:
```bash
git clone https://github.com/ChornyiDev/FreeMount.git && cd FreeMount && ./scripts/install-from-source.sh
```

If you already have FreeMount installed, click **"Update Now"** in FreeMount Settings → About, or run:
```bash
cd ~/FreeMount && git pull && ./scripts/install-from-source.sh
```
116 changes: 116 additions & 0 deletions App/Services/UpdateService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import Foundation

/// Represents a GitHub Release payload subset needed for update inspection.
public struct GitHubReleaseInfo: Codable, Sendable, Equatable {
public let tagName: String
public let name: String?
public let body: String?
public let htmlUrl: URL?
public let publishedAt: Date?

enum CodingKeys: String, CodingKey {
case tagName = "tag_name"
case name
case body
case htmlUrl = "html_url"
case publishedAt = "published_at"
}
}

/// Status of the manual update check.
public enum UpdateCheckStatus: Sendable, Equatable {
case idle
case checking
case upToDate(currentVersion: String)
case updateAvailable(latestVersion: String, currentVersion: String, release: GitHubReleaseInfo)
case failed(message: String)
}

/// Actor responsible for performing on-demand manual update checks against GitHub Releases.
public actor UpdateService {
private let session: URLSession
private let repositoryOwner: String
private let repositoryName: String

public init(
session: URLSession = .shared,
repositoryOwner: String = "ChornyiDev",
repositoryName: String = "FreeMount"
) {
self.session = session
self.repositoryOwner = repositoryOwner
self.repositoryName = repositoryName
}

/// Fetches the latest release from GitHub Releases API without downloading any binaries.
public func fetchLatestRelease() async throws -> GitHubReleaseInfo {
let endpoint = "https://api.github.com/repos/\(repositoryOwner)/\(repositoryName)/releases/latest"
guard let url = URL(string: endpoint) else {
throw URLError(.badURL)
}

var request = URLRequest(url: url)
request.httpMethod = "GET"
request.setValue("application/vnd.github+json", forHTTPHeaderField: "Accept")
request.setValue("FreeMount-App", forHTTPHeaderField: "User-Agent")
request.timeoutInterval = 15

let (data, response) = try await session.data(for: request)
guard let httpResponse = response as? HTTPURLResponse else {
throw URLError(.badServerResponse)
}

if httpResponse.statusCode == 404 {
// No releases published yet on the repository
throw UpdateError.noReleasesFound
}

guard (200...299).contains(httpResponse.statusCode) else {
throw UpdateError.httpError(statusCode: httpResponse.statusCode)
}

let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .iso8601
return try decoder.decode(GitHubReleaseInfo.self, from: data)
}

/// Compares two semantic version strings (e.g. "v1.0.1" vs "1.0.0").
/// Returns true if `remote` is strictly higher than `current`.
public static func isVersion(_ remote: String, newerThan current: String) -> Bool {
let cleanRemote = cleanVersion(remote)
let cleanCurrent = cleanVersion(current)

let remoteParts = cleanRemote.split(separator: ".").compactMap { Int($0) }
let currentParts = cleanCurrent.split(separator: ".").compactMap { Int($0) }

let count = max(remoteParts.count, currentParts.count)
for i in 0..<count {
let r = i < remoteParts.count ? remoteParts[i] : 0
let c = i < currentParts.count ? currentParts[i] : 0
if r > c { return true }
if r < c { return false }
}
return false
}

private static func cleanVersion(_ version: String) -> String {
version.trimmingCharacters(in: .whitespacesAndNewlines)
.lowercased()
.trimmingCharacters(in: CharacterSet(charactersIn: "v"))
}
}

public enum UpdateError: LocalizedError, Equatable {
case noReleasesFound
case httpError(statusCode: Int)

public var errorDescription: String? {
switch self {
case .noReleasesFound:
return "No official releases found on GitHub."
case .httpError(let code):
return "GitHub API responded with HTTP status \(code)."
}
}
}

46 changes: 46 additions & 0 deletions App/Services/UpdateWorkflowManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import AppKit
import Foundation

/// Manages resolution and execution of the source-based update workflow.
public enum UpdateWorkflowManager {
public static let defaultRepoPathKey = "FreeMountSourceRepositoryPath"
public static let cloneCommand = "git clone https://github.com/ChornyiDev/FreeMount.git && cd FreeMount && ./scripts/install-from-source.sh"

/// Discovers if the repository folder exists at the saved path or default home directory.
public static func resolveRepositoryPath() -> String? {
if let saved = UserDefaults.standard.string(forKey: defaultRepoPathKey),
FileManager.default.fileExists(atPath: saved + "/scripts/install-from-source.sh") {
return saved
}

let homeCandidate = FileManager.default.homeDirectoryForCurrentUser
.appendingPathComponent("FreeMount", isDirectory: true).path
if FileManager.default.fileExists(atPath: homeCandidate + "/scripts/install-from-source.sh") {
return homeCandidate
}

return nil
}

/// Stores the active repository path in preferences.
public static func recordRepositoryPath(_ path: String) {
UserDefaults.standard.set(path, forKey: defaultRepoPathKey)
}

/// Executes the update command in macOS Terminal using AppleScript.
/// This ensures that the user can see build progress and provide credentials if needed.
public static func executeUpdateInTerminal(at repoPath: String) {
let escapedPath = repoPath.replacingOccurrences(of: "\"", with: "\\\"")
let script = """
tell application "Terminal"
activate
do script "cd \\"\(escapedPath)\\" && git pull && ./scripts/install-from-source.sh"
end tell
"""
var error: NSDictionary?
if let appleScript = NSAppleScript(source: script) {
appleScript.executeAndReturnError(&error)
}
}
}

25 changes: 25 additions & 0 deletions App/ViewModels/SettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ final class SettingsViewModel {
private(set) var isRestarting = false
private(set) var errorMessage: String?

// Update checking state
private(set) var updateStatus: UpdateCheckStatus = .idle
private let updateService = UpdateService()

init(supervisor: RcloneProcessSupervisor) {
self.supervisor = supervisor
}
Expand Down Expand Up @@ -64,4 +68,25 @@ final class SettingsViewModel {
let minutes = (seconds % 3600) / 60
return hours > 0 ? "\(hours)h \(minutes)m" : "\(minutes)m"
}

func checkForUpdates(currentVersion: String) async {
guard updateStatus != .checking else { return }
updateStatus = .checking
do {
let release = try await updateService.fetchLatestRelease()
if UpdateService.isVersion(release.tagName, newerThan: currentVersion) {
updateStatus = .updateAvailable(
latestVersion: release.tagName,
currentVersion: currentVersion,
release: release
)
} else {
updateStatus = .upToDate(currentVersion: currentVersion)
}
} catch UpdateError.noReleasesFound {
updateStatus = .upToDate(currentVersion: currentVersion)
} catch {
updateStatus = .failed(message: error.localizedDescription)
}
}
}
9 changes: 9 additions & 0 deletions App/Views/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ struct SettingsView: View {
Text("Native macOS cloud storage powered by Apple File Provider and rclone.")
.multilineTextAlignment(.center)
.foregroundStyle(Color.dsTextSecondary)

UpdateSectionView(
status: viewModel.updateStatus,
currentVersion: appVersion,
onCheck: {
Task { await viewModel.checkForUpdates(currentVersion: appVersion) }
}
)

Text("rclone is distributed under the MIT License. Notices are included with the application.")
.font(.caption)
.foregroundStyle(Color.dsTextMuted)
Expand Down
Loading
Loading