Skip to content

Commit b66a7af

Browse files
Merge pull request #1288 from apollographql/fix/moar-cli
More CLI fixes
2 parents 70eb192 + 4143477 commit b66a7af

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

Sources/ApolloCodegenLib/ApolloCLI.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ public struct ApolloCLI {
1313
/// - timeout: The maximum time to wait before indicating that the download timed out, in seconds.
1414
public static func createCLI(cliFolderURL: URL, timeout: Double) throws -> ApolloCLI {
1515
try CLIDownloader.downloadIfNeeded(cliFolderURL: cliFolderURL, timeout: timeout)
16+
17+
if !(try CLIExtractor.validateSHASUMOfDownloadedFile(in: cliFolderURL)) {
18+
CodegenLogger.log("Downloaded zip file has incorrect SHASUM, forcing redownolad")
19+
try CLIDownloader.forceRedownload(cliFolderURL: cliFolderURL, timeout: timeout)
20+
}
21+
1622
let binaryFolderURL = try CLIExtractor.extractCLIIfNeeded(from: cliFolderURL)
1723
return ApolloCLI(binaryFolderURL: binaryFolderURL)
1824
}

Sources/ApolloCodegenLib/CLIExtractor.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,22 @@ struct CLIExtractor {
7878
return true
7979
}
8080

81+
static func validateSHASUMOfDownloadedFile(in cliFolderURL: URL, expected: String = CLIExtractor.expectedSHASUM) throws -> Bool {
82+
let zipFileURL = ApolloFilePathHelper.zipFileURL(fromCLIFolder: cliFolderURL)
83+
84+
do {
85+
try self.validateZipFileSHASUM(at: zipFileURL)
86+
return true
87+
} catch {
88+
switch error {
89+
case CLIExtractorError.zipFileHasInvalidSHASUM:
90+
return false
91+
default:
92+
throw error
93+
}
94+
}
95+
}
96+
8197
/// Writes the SHASUM of the extracted version of the CLI to a file for faster checks to ensure we have the correct version.
8298
///
8399
/// - Parameter apolloFolderURL: The URL to the extracted apollo folder.
@@ -119,7 +135,7 @@ struct CLIExtractor {
119135
/// - Parameter expected: The expected SHASUM. Defaults to the real expected SHASUM. This parameter exists mostly for testing.
120136
static func validateZipFileSHASUM(at zipFileURL: URL, expected: String = CLIExtractor.expectedSHASUM) throws {
121137
let shasum = try FileManager.default.apollo.shasum(at: zipFileURL)
122-
print("SHASUM: \(shasum)")
138+
print("SHASUM of downloaded file: \(shasum)")
123139
guard shasum == expected else {
124140
throw CLIExtractorError.zipFileHasInvalidSHASUM(expectedSHASUM: expected, gotSHASUM: shasum)
125141
}

scripts/run-bundled-codegen.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ SCRIPT_DIR="$(dirname "$0")"
1111

1212
# Get the SHASUM of the tarball
1313
ZIP_FILE="${SCRIPT_DIR}/apollo.tar.gz"
14-
ZIP_FILE_DOWNLOAD_URL="https://install.apollographql.com/legacy-cli/darwin/2.28.0"
14+
ZIP_FILE_DOWNLOAD_URL="https://install.apollographql.com/legacy-cli/darwin/2.28.3"
1515
SHASUM_FILE="${SCRIPT_DIR}/apollo/.shasum"
1616
APOLLO_DIR="${SCRIPT_DIR}"/apollo
1717
IS_RETRY="false"
@@ -58,7 +58,7 @@ extract_cli() {
5858

5959
validate_codegen_and_extract_if_needed() {
6060
# Make sure the SHASUM matches the release for this version
61-
EXPECTED_SHASUM="060d893aea4ebc2effa74b20433f5d0f586b31fec0d0f73c210ee152c032185e"
61+
EXPECTED_SHASUM="cb2f4b9f53eb8443661e7658e407a3837da3d781649f8bc66a1c6cf7d32acef1"
6262
update_shasum
6363

6464
if [[ ${SHASUM} = ${EXPECTED_SHASUM}* ]]; then

0 commit comments

Comments
 (0)