Skip to content

Commit f806167

Browse files
BobaFettersgh-action-runner
authored and
gh-action-runner
committedJan 12, 2024
InstallCLI Plugin Updates (apollographql/apollo-ios-dev#132)
1 parent 74e71b8 commit f806167

File tree

5 files changed

+33
-30
lines changed

5 files changed

+33
-30
lines changed
 

‎CLI/apollo-ios-cli.tar.gz

-2.73 MB
Binary file not shown.

‎Package.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.7
1+
// swift-tools-version:5.9
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
@@ -63,7 +63,8 @@ let package = Package(
6363
verb: "apollo-cli-install",
6464
description: "Installs the Apollo iOS Command line interface."),
6565
permissions: [
66-
.writeToPackageDirectory(reason: "Creates a symbolic link to the CLI executable in your project directory."),
66+
.writeToPackageDirectory(reason: "Downloads and unzips the CLI executable into your project directory."),
67+
.allowNetworkConnections(scope: .all(ports: []), reason: "Downloads the Apollo iOS CLI executable from the GitHub Release.")
6768
]),
6869
dependencies: [],
6970
path: "Plugins/InstallCLI"

‎Plugins/InstallCLI/InstallCLIPluginCommand.swift

+10-27
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,17 @@ import PackagePlugin
55
struct InstallCLIPluginCommand: CommandPlugin {
66

77
func performCommand(context: PackagePlugin.PluginContext, arguments: [String]) async throws {
8-
var apolloDirectoryPath: Path? = nil
98
let dependencies = context.package.dependencies
10-
dependencies.forEach { dep in
9+
try dependencies.forEach { dep in
1110
if dep.package.displayName == "Apollo" {
12-
apolloDirectoryPath = dep.package.directory
11+
let process = Process()
12+
let path = try context.tool(named: "sh").path
13+
process.executableURL = URL(fileURLWithPath: path.string)
14+
process.arguments = ["\(dep.package.directory)/scripts/download-cli.sh", context.package.directory.string]
15+
try process.run()
16+
process.waitUntilExit()
1317
}
1418
}
15-
16-
guard let apolloPath = apolloDirectoryPath else {
17-
fatalError("No Apollo dependency directory path")
18-
}
19-
20-
let process = Process()
21-
let tarPath = try context.tool(named: "tar").path
22-
process.executableURL = URL(fileURLWithPath: tarPath.string)
23-
process.arguments = ["-xvf", "\(apolloPath)/CLI/apollo-ios-cli.tar.gz"]
24-
try process.run()
25-
process.waitUntilExit()
26-
}
27-
28-
func createSymbolicLink(from: PackagePlugin.Path, to: PackagePlugin.Path) throws {
29-
let task = Process()
30-
task.standardInput = nil
31-
task.environment = ProcessInfo.processInfo.environment
32-
task.arguments = ["-c", "ln -f -s '\(from.string)' '\(to.string)'"]
33-
task.executableURL = URL(fileURLWithPath: "/bin/zsh")
34-
try task.run()
35-
task.waitUntilExit()
3619
}
3720

3821
}
@@ -47,9 +30,9 @@ extension InstallCLIPluginCommand: XcodeCommandPlugin {
4730
print("Installing Apollo CLI Plugin to Xcode project \(context.xcodeProject.displayName)")
4831
let apolloPath = "\(context.pluginWorkDirectory)/../../checkouts/apollo-ios"
4932
let process = Process()
50-
let tarPath = try context.tool(named: "tar").path
51-
process.executableURL = URL(fileURLWithPath: tarPath.string)
52-
process.arguments = ["-xvf", "\(apolloPath)/CLI/apollo-ios-cli.tar.gz"]
33+
let path = try context.tool(named: "sh").path
34+
process.executableURL = URL(fileURLWithPath: path.string)
35+
process.arguments = ["\(apolloPath)/scripts/download-cli.sh", context.xcodeProject.directory.string]
5336
try process.run()
5437
process.waitUntilExit()
5538
}

‎scripts/download-cli.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
# This script is intended for use only with the "InstallCLI" SPM plugin provided by Apollo iOS
4+
5+
directory=$(dirname "$0")
6+
projectDir="$1"
7+
8+
if [ -z "$projectDir" ];
9+
then
10+
echo "Missing project directory path." >&2
11+
exit 1
12+
fi
13+
14+
APOLLO_VERSION=$(sh "$directory/get-version.sh")
15+
DOWNLOAD_URL="https://www.github.com/apollographql/apollo-ios/releases/download/$APOLLO_VERSION/apollo-ios-cli.tar.gz"
16+
FILE_PATH="$projectDir/apollo-ios-cli.tar.gz"
17+
curl -L "$DOWNLOAD_URL" -s -o "$FILE_PATH"
18+
tar -xvf "$FILE_PATH"
19+
rm -f "$FILE_PATH"

‎scripts/get-version.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
directory=$(dirname "$0")
44
source "$directory/version-constants.sh"
55

6-
constantsFile=$(cat $directory/../$APOLLO_CONSTANTS_FILE)
6+
constantsFile=$(cat "$directory/../$APOLLO_CONSTANTS_FILE")
77
currentVersion=$(echo $constantsFile | sed 's/^.*ApolloVersion: String = "\([^"]*\).*/\1/')
88
echo $currentVersion

0 commit comments

Comments
 (0)
Please sign in to comment.