Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c7401a6
Split install.sh into install.sh and install_private.sh
albertodebortoli Feb 28, 2023
b5215af
Fix typos
albertodebortoli Feb 28, 2023
4bfb3c7
Remove broken reference to StellarTests from StellarEnv scheme
albertodebortoli Feb 28, 2023
74fdd71
Update swift-tools-support-core to version already in .resolved
albertodebortoli Feb 28, 2023
f5132e7
Use .upToNextMajor for swift-tools-support-core as done for the other…
albertodebortoli Feb 28, 2023
7bf6316
Sort entries in Package.swift
albertodebortoli Feb 28, 2023
27999e5
Sort targets in Package.swift
albertodebortoli Feb 28, 2023
66cc186
Remove duplicate HintTemplateNames
albertodebortoli Feb 28, 2023
3a4732b
Add toolFolder to FileConstants
albertodebortoli Feb 28, 2023
5775bfc
Minor name consistency and sorting
albertodebortoli Feb 28, 2023
eaa6981
Improve FileManager's withTemporaryDirectory
albertodebortoli Mar 1, 2023
70ea5cb
Minor improvements in BundleUpdater
albertodebortoli Mar 4, 2023
7f2098c
Minor improvements in CLIInstaller
albertodebortoli Mar 4, 2023
20cdcd8
Minor improvements in EnvInstaller
albertodebortoli Mar 4, 2023
47667fa
Minor improvements in CommandResolver
albertodebortoli Mar 4, 2023
89da287
Minor improvements in ReleaseProvider
albertodebortoli Mar 4, 2023
fc771df
Minor improvements in VersionResolver
albertodebortoli Mar 4, 2023
e4b27e5
Minor improvements in URLManager
albertodebortoli Mar 4, 2023
8b8f0dd
Put RemoteRelease Codable conformance in extension
albertodebortoli Mar 4, 2023
8d652f8
Minor improvements in Shell
albertodebortoli Mar 4, 2023
e237dc6
Minor remaining improvements
albertodebortoli Mar 4, 2023
5470869
Fix binName constant
albertodebortoli Mar 4, 2023
1097f2e
Remove resources from StellarEnvTests to fix build warning
albertodebortoli Mar 4, 2023
98d6ca9
Correct GitHub Actions workflows
albertodebortoli Mar 4, 2023
696d0a9
Update run-tests workflow to run tests on any PR
albertodebortoli Mar 4, 2023
47f85ac
Fix uninstall.sh
albertodebortoli Mar 4, 2023
fe8fe0e
Move workflows back to macos-12
albertodebortoli Mar 5, 2023
33f6b08
Use @main in StellarEnvCommand to leverage Argument Parser
albertodebortoli Mar 5, 2023
87e0730
Revert back to macOS(.v12) in Package.swift
albertodebortoli Mar 5, 2023
a9b36c1
Revert "Use @main in StellarEnvCommand to leverage Argument Parser"
albertodebortoli Mar 5, 2023
fe82f78
Rename 3 methods in URLManager
albertodebortoli Mar 5, 2023
9b73858
Fix retrieval of the GitHub token content
albertodebortoli Mar 6, 2023
b7b3991
Minor renaming
albertodebortoli Mar 6, 2023
88447ea
Minor renaming of a method
albertodebortoli Mar 6, 2023
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
17 changes: 4 additions & 13 deletions .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ jobs:
fail-fast: false
matrix:
macos: ['macos-12']
xcode: ['14.1.0']
command: ['build']
scheme: ['StellarCLI','StellarEnv']
destination: ['platform=macOS']
xcode: ['14.2.0']
steps:
- name: Switch xcode to ${{ matrix.xcode }}
run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
Expand All @@ -30,13 +27,7 @@ jobs:
- name: Show buildable schemes
working-directory: ./Stellar
run: xcodebuild -list
- name: Show eligible build destinations for ${{ matrix.scheme }}
working-directory: ./Stellar
run: xcodebuild -showdestinations -scheme ${{ matrix.scheme }}
- name: Run command ${{ matrix.command }} on ${{ matrix.scheme }} for destination ${{ matrix.destination }}
working-directory: ./Stellar
run: xcodebuild ${{ matrix.command }} -scheme ${{ matrix.scheme }} -destination "${{ matrix.destination }}"
- name: Archive using ${{ matrix.scheme }} for destination ${{ matrix.destination }}
- name: Build products for release
working-directory: ./Stellar
run: swift build -c release --arch arm64 --arch x86
- name: Copy Templates.bundle
Expand All @@ -58,7 +49,7 @@ jobs:
release_name: Release ${{ github.ref }}
draft: false # just for testing
prerelease: false # just for testing
- name: Upload StellarCLI
- name: Upload StellarCLI release asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
Expand All @@ -67,7 +58,7 @@ jobs:
asset_path: ./Stellar/.build/apple/Products/Release/StellarCLI.zip
asset_name: StellarCLI.zip
asset_content_type: application/zip
- name: Upload StellarEnv
- name: Upload StellarEnv release asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- master
pull_request:
branches:
- master
- '**'

jobs:
build:
Expand All @@ -15,9 +15,9 @@ jobs:
fail-fast: false
matrix:
macos: ['macos-12']
xcode: ['14.1.0']
xcode: ['14.2.0']
command: ['test']
scheme: ['StellarCLI']
scheme: ['StellarCLI', 'StellarEnv']
destination: ['platform=macOS']
steps:
- name: Switch xcode to ${{ matrix.xcode }}
Expand Down
10 changes: 0 additions & 10 deletions Stellar/.swiftpm/xcode/xcshareddata/xcschemes/StellarEnv.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "StellarTests"
BuildableName = "StellarTests"
BlueprintName = "StellarTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
Expand Down
34 changes: 17 additions & 17 deletions Stellar/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PackageDescription

let package = Package(
name: "Stellar",
platforms: [.macOS(.v13)],
platforms: [.macOS(.v12)],
products: [
.executable(
name: "StellarCLI",
Expand All @@ -19,17 +19,11 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMajor(from: "1.0.0")),
.package(url: "https://github.com/apple/swift-tools-support-core.git", .upToNextMajor(from: "0.5.2")),
.package(url: "https://github.com/SwiftGen/StencilSwiftKit.git", .upToNextMajor(from: "2.8.0")),
.package(url: "https://github.com/JohnSundell/ShellOut.git", .upToNextMajor(from: "2.3.0")),
.package(url: "https://github.com/apple/swift-tools-support-core.git", from: "0.3.0")
.package(url: "https://github.com/JohnSundell/ShellOut.git", .upToNextMajor(from: "2.3.0"))
],
targets: [
.executableTarget(
name: "StellarEnv",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.target(name: "StellarCore")],
path: "Sources/Env"),
.executableTarget(
name: "StellarCLI",
dependencies: [
Expand All @@ -40,16 +34,18 @@ let package = Package(
name: "StellarCore",
dependencies: [
.product(name: "ShellOut", package: "ShellOut"),
.product(name: "TSCBasic", package: "swift-tools-support-core"),
.product(name: "StencilSwiftKit", package: "StencilSwiftKit")
.product(name: "StencilSwiftKit", package: "StencilSwiftKit"),
.product(name: "TSCBasic", package: "swift-tools-support-core")

],
path: "Sources/Core",
resources: [.copy("Resources")]),
.testTarget(
name: "StellarEnvTests",
dependencies: ["StellarEnv"],
path: "Tests/Env",
resources: [.copy("Tests")]),
.executableTarget(
name: "StellarEnv",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.target(name: "StellarCore")],
path: "Sources/Env"),
.testTarget(
name: "StellarCLITests",
dependencies: ["StellarCLI"],
Expand All @@ -58,6 +54,10 @@ let package = Package(
name: "StellarCoreTests",
dependencies: ["StellarCore"],
path: "Tests/Core",
resources: [.copy("Resources")])
resources: [.copy("Resources")]),
.testTarget(
name: "StellarEnvTests",
dependencies: ["StellarEnv"],
path: "Tests/Env")
]
)
17 changes: 7 additions & 10 deletions Stellar/Sources/Core/Constants/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ struct Constants {
static let executor = "Executor"
}

struct HintTemplateNames {
static let actionCreatedOnDefaultPath = "ActionCreatedOnDefaultPath.stencil"
}

struct FileConstants {
static let versionsFile = ".stellar-version"
static let binFolder = ".stellar-bin"
static let binName = ".stellar"
static let binName = "stellar"
static let toolFolder = ".stellar"
static let envInstallDirectory = "/usr/local/bin"
static let envBinName = "stellarenv"
}
Expand All @@ -29,25 +26,25 @@ struct GitHubAPI {
static let tokenFile = ".GITHUB-TOKEN"

static var gitHubToken: String = {
let tokenFileURL = URLManager().systemLocation()
let tokenFileURL = URLManager().homeStellarLocation()
.appendingPathComponent(GitHubAPI.tokenFile)

guard FileManager.default.fileExists(at: tokenFileURL) else {
print(tokenFileURL.path)
fatalError("Missing \(GitHubAPI.tokenFile) in \(FileConstants.binName) directory")
fatalError("Missing \(GitHubAPI.tokenFile) in ~/\(FileConstants.toolFolder) directory.")
}

let token = try? String(contentsOf: tokenFileURL)
.trimmingCharacters(in: .whitespacesAndNewlines)
return token ?? ""
}()

}

struct RemoteConstants {
static let releaseZip = "release.zip"
static let stellarPackage = "\(stellarCLI).zip"
static let stellarCLI = "StellarCLI"

static let stellarCLIZipAsset = "\(stellarCLI).zip"
static let stellarEnvCLI = "StellarEnv"
static let stellarEnvPackage = "\(stellarEnvCLI).zip"
static let stellarEnvZipAsset = "\(stellarEnvCLI).zip"
}
20 changes: 9 additions & 11 deletions Stellar/Sources/Core/FileManaging/FileManager+FileManaging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,27 @@ extension FileManager: FileManaging {
try moveItem(atPath: location.path, toPath: destination.path)
}

/// Creates a temporary directory and evaluates a closure with the directory path as an argument.
/// Create a temporary directory and evaluates a closure with the directory path as an argument.
///
///
/// - Parameters:
/// - path: when specified this path is used as root of the temporary directory.
/// If not the system temporary directory path is used.
/// - prefix: The prefix to the temporary file name.
/// - autoRemove: If enabled try to delete the whole directory tree otherwise remove only if its empty.
/// - prefix: The prefix of the temporary directory.
/// - autoRemove: If true, it tries to delete the temporary directory after executing the closure.
/// - closure: A closure to execute that receives the absolute path of the directory as an argument.
/// If `body` has a return value, that value is also used as the return value of the function.
/// - Returns: `Result` specified
/// - Returns: The value returned by the closure.
public func withTemporaryDirectory<Result>(path: String? = nil,
prefix: String = "TempDir",
autoRemove: Bool = true ,
autoRemove: Bool = true,
_ closure: (URL) throws -> Result) throws -> Result {
// Construct path to the temporary directory.
let folderName = "\(prefix)-\(UUID().uuidString)"
let directoryPath = URL(fileURLWithPath: (path ?? NSTemporaryDirectory()), isDirectory: true).appendingPathComponent(folderName, isDirectory: true)
try FileManager.default.createDirectory(atPath: directoryPath.path, withIntermediateDirectories: true)
let location = URL(fileURLWithPath: (path ?? NSTemporaryDirectory()), isDirectory: true).appendingPathComponent(folderName, isDirectory: true)
try createDirectory(at: location, withIntermediateDirectories: true)

let res = try closure(directoryPath)
let res = try closure(location)
if autoRemove {
try? FileManager.default.removeItem(atPath: directoryPath.path)
try? removeItem(at: location)
}
return res
}
Expand Down
34 changes: 18 additions & 16 deletions Stellar/Sources/Core/Installer/BundleUpdater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ public final class BundleUpdater: BundleUpdating {

// MARK: - Public Properties

public var cliInstaller: CLIInstaller
public var envInstaller: EnvInstaller
public let cliInstaller: CLIInstaller
public let envInstaller: EnvInstaller

private let logger = Logger()

public var releaseProvider: ReleaseProviding {
cliInstaller.releaseProvider
Expand Down Expand Up @@ -48,15 +50,15 @@ public final class BundleUpdater: BundleUpdating {
// MARK: - Private Functions

private func updateBundle(toVersion version: String) throws -> URL? {
// Version is not available locally, we would to retrive it remotely.
// Version is not available locally, we retrive it remotely.
if try versionResolver.isVersionInstalled(version) == false {
Logger().log("Version \(version) not found locally. Installing...")
logger.log("Version \(version) not found locally. Installing...")
return try cliInstaller.install(version: version)
}

// Attempt to get the path of the release.
guard let versionPath = try versionResolver.pathForVersion(version)?.path else {
Logger().log("Failed to use version \(version). Aborting the process...")
logger.log("Failed to use version \(version). Aborting the process...")
return nil
}

Expand All @@ -65,36 +67,36 @@ public final class BundleUpdater: BundleUpdating {

private func updateBundleToLatestVersion() throws -> URL? {
guard let release = try releaseProvider.latestRelease() else {
Logger().log("No remote version found")
logger.log("No remote version found")
return nil
}

let versionURL = try updateCLI(toRemoteVersion: release)
try updateENV(toRemoteVersion: release)
let versionURL = try updateCLIToLatestVersion(release.version)
try updateENVToLatestVersion(release.version)

Logger().log("Stellar version \(release.description) installed")
logger.log("Stellar version \(release.description) installed")

return versionURL
}

private func updateCLI(toRemoteVersion version: RemoteRelease) throws -> URL? {
private func updateCLIToLatestVersion(_ version: SemVer) throws -> URL? {
if let latestLocalVersion = try cliInstaller.latestInstalledVersion() {
guard version.version > latestLocalVersion.version else {
Logger().log("There are not updates available")
guard version > latestLocalVersion.version else {
logger.log("Version \(latestLocalVersion) is installed and greater than latest available \(version)")
return nil
}

Logger().log("Installing new version available \(version)")
logger.log("Installing new version available \(version)")
} else {
Logger().log("No local version available. Installing latest version \(version)")
logger.log("No local version available. Installing latest version \(version)")
}

// Install version of stellar
return try cliInstaller.install(version: version.description)
}

private func updateENV(toRemoteVersion version: RemoteRelease) throws {
Logger().log("Updating stellarenv")
private func updateENVToLatestVersion(_ version: SemVer) throws {
logger.log("Updating stellarenv")
try envInstaller.install(version: version.description)
}

Expand Down
Loading