diff --git a/.gitignore b/.gitignore index 18eb50c..1f92665 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ .build/ .envrc .fseventsd +.idea/ .rubygems/ .swiftpm/ Carthage/ diff --git a/.swiftlint.yml b/.swiftlint.yml index abb72ba..1c9c9e3 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -4,13 +4,12 @@ # # https://github.com/realm/SwiftLint#configuration # - +--- disabled_rules: - non_optional_string_data_conversion - trailing_comma - excluded: - docs - opening_brace: - allow_multiline_func: true + ignore_multiline_function_signatures: true + ignore_multiline_statement_conditions: true diff --git a/Brewfile b/Brewfile index f849bab..9362a2f 100644 --- a/Brewfile +++ b/Brewfile @@ -1,6 +1,7 @@ brew "markdownlint-cli" brew "shellcheck" brew "shfmt" +brew "swift-format" brew "swiftformat" # Already installed on GitHub Actions runner. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 249795c..16760d6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,7 +8,7 @@ We love pull requests from everyone. By participating in this project, you agree - [Open an issue](https://github.com/mas-cli/mas/issues/new) to simply ask a question or request a new feature. - Search for similar issues with the [ERROR MESSAGE](https://github.com/mas-cli/mas/issues?utf8=%E2%9C%93&q=is%3Aopen+ERROR+MESSAGE) -you are exeriencing. +you are experiencing. - If one doesn't exist, [open a new issue](https://github.com/mas-cli/mas/issues/new) - Clearly describe the issue including steps to reproduce when it is a bug. - Include the earliest version of `mas` that you know has the issue. diff --git a/Package.resolved b/Package.resolved index ba46a29..6952cad 100644 --- a/Package.resolved +++ b/Package.resolved @@ -64,33 +64,6 @@ "version": "2.1.1" } }, - { - "package": "swift-argument-parser", - "repositoryURL": "https://github.com/apple/swift-argument-parser.git", - "state": { - "branch": null, - "revision": "c8ed701b513cf5177118a175d85fbbbcd707ab41", - "version": "1.3.0" - } - }, - { - "package": "swift-format", - "repositoryURL": "https://github.com/apple/swift-format", - "state": { - "branch": "release/5.9", - "revision": "1323e87eced56bdcfed1bb78af1f16f39274d032", - "version": null - } - }, - { - "package": "swift-syntax", - "repositoryURL": "https://github.com/apple/swift-syntax.git", - "state": { - "branch": "release/5.9", - "revision": "9a101b70eee2a9dec04f92d2d47b22ebe57a1aae", - "version": null - } - }, { "package": "Version", "repositoryURL": "https://github.com/mxcl/Version.git", diff --git a/Package.swift b/Package.swift index 15da902..2df3ba1 100644 --- a/Package.swift +++ b/Package.swift @@ -75,30 +75,3 @@ let package = Package( ], swiftLanguageVersions: [.v5] ) - -// https://github.com/apple/swift-format#matching-swift-format-to-your-swift-version-swift-57-and-earlier -#if compiler(>=5.8) - package.dependencies += [ - .package(url: "https://github.com/apple/swift-format", .branch("release/5.9")) - ] -#elseif compiler(>=5.7) - package.dependencies += [ - .package(url: "https://github.com/apple/swift-format", .branch("release/5.7")) - ] -#elseif compiler(>=5.6) - package.dependencies += [ - .package(url: "https://github.com/apple/swift-format", .branch("release/5.6")) - ] -#elseif compiler(>=5.5) - package.dependencies += [ - .package(url: "https://github.com/apple/swift-format", .branch("swift-5.5-branch")) - ] -#elseif compiler(>=5.4) - package.dependencies += [ - .package(url: "https://github.com/apple/swift-format", .branch("swift-5.4-branch")) - ] -#elseif compiler(>=5.3) - package.dependencies += [ - .package(url: "https://github.com/apple/swift-format", .branch("swift-5.3-branch")) - ] -#endif diff --git a/README.md b/README.md index e9282d1..6bf0ebe 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,6 @@ $ mas lucky twitter > Please note that this command will not allow you to install (or even purchase) an app for the first time: use the `purchase` command in that case. -> ⛔ The `purchase` command is not supported as of macOS 10.15 Catalina. Please see [Known Issues](#%EF%B8%8F-known-issues). ```bash $ mas purchase 768053424 @@ -190,10 +189,9 @@ docs for more details. ## ⚠️ Known Issues Over time, Apple has changed the APIs used by `mas` to manage App Store apps, limiting its capabilities. Please sign in -or purchase apps using the App Store app instead. Subsequent redownloads can be performed with `mas install`. +using the App Store app instead. Subsequent redownloads can be performed with `mas install`. - ⛔️ The `signin` command is not supported as of macOS 10.13 High Sierra. [#164](https://github.com/mas-cli/mas/issues/164) -- ⛔️ The `purchase` command is not supported as of macOS 10.15 Catalina. [#289](https://github.com/mas-cli/mas/issues/289) - ⛔️ The `account` command is not supported as of macOS 12 Monterey. [#417](https://github.com/mas-cli/mas/issues/417) The versions `mas` sees from the app bundles on your Mac don't always match the versions reported by the App Store for diff --git a/Sources/MasKit/Commands/Lucky.swift b/Sources/MasKit/Commands/Lucky.swift index f8288ab..9452eba 100644 --- a/Sources/MasKit/Commands/Lucky.swift +++ b/Sources/MasKit/Commands/Lucky.swift @@ -69,7 +69,7 @@ public struct LuckyCommand: CommandProtocol { /// /// - Parameters: /// - appId: App identifier - /// - options: command opetions. + /// - options: command options. /// - Returns: Result of the operation. fileprivate func install(_ appId: UInt64, options: Options) -> Result { // Try to download applications with given identifiers and collect results diff --git a/Sources/MasKit/Commands/Purchase.swift b/Sources/MasKit/Commands/Purchase.swift index c8dcd2a..9138027 100644 --- a/Sources/MasKit/Commands/Purchase.swift +++ b/Sources/MasKit/Commands/Purchase.swift @@ -29,12 +29,6 @@ public struct PurchaseCommand: CommandProtocol { /// Runs the command. public func run(_ options: Options) -> Result { - if #available(macOS 10.15, *) { - // Purchases are no longer possible as of Catalina. - // https://github.com/mas-cli/mas/issues/289 - return .failure(.notSupported) - } - // Try to download applications with given identifiers and collect results let appIds = options.appIds.filter { appId in if let product = appLibrary.installedApp(forId: appId) { diff --git a/Sources/MasKit/Controllers/AppLibrary.swift b/Sources/MasKit/Controllers/AppLibrary.swift index ac5ade4..2edbc89 100644 --- a/Sources/MasKit/Controllers/AppLibrary.swift +++ b/Sources/MasKit/Controllers/AppLibrary.swift @@ -28,9 +28,9 @@ protocol AppLibrary { /// Common logic extension AppLibrary { - /// Finds an app by name. + /// Finds an app by ID. /// - /// - Parameter id: MAS ID for app. + /// - Parameter forId: MAS ID for app. /// - Returns: Software Product of app if found; nil otherwise. func installedApp(forId identifier: UInt64) -> SoftwareProduct? { let appId = NSNumber(value: identifier) diff --git a/Sources/MasKit/Controllers/MasStoreSearch.swift b/Sources/MasKit/Controllers/MasStoreSearch.swift index 43b96c6..0db3268 100644 --- a/Sources/MasKit/Controllers/MasStoreSearch.swift +++ b/Sources/MasKit/Controllers/MasStoreSearch.swift @@ -108,7 +108,7 @@ class MasStoreSearch: StoreSearch { do { return try JSONDecoder().decode(SearchResultList.self, from: data).results } catch { - throw MASError.jsonParsing(error: error as NSError) + throw MASError.jsonParsing(data: data) } } } diff --git a/Sources/MasKit/Controllers/SoftwareMap.swift b/Sources/MasKit/Controllers/SoftwareMap.swift index f30301f..0294abe 100644 --- a/Sources/MasKit/Controllers/SoftwareMap.swift +++ b/Sources/MasKit/Controllers/SoftwareMap.swift @@ -6,7 +6,7 @@ // Copyright © 2020 mas-cli. All rights reserved. // -/// Somewhat analygous to CKSoftwareMap +/// Somewhat analogous to CKSoftwareMap protocol SoftwareMap { func allSoftwareProducts() -> [SoftwareProduct] func product(for bundleIdentifier: String) -> SoftwareProduct? diff --git a/Sources/MasKit/Errors/MASError.swift b/Sources/MasKit/Errors/MASError.swift index d5c4683..7fb0fb2 100644 --- a/Sources/MasKit/Errors/MASError.swift +++ b/Sources/MasKit/Errors/MASError.swift @@ -31,7 +31,7 @@ public enum MASError: Error, Equatable { case uninstallFailed case noData - case jsonParsing(error: NSError?) + case jsonParsing(data: Data?) } // MARK: - CustomStringConvertible @@ -90,8 +90,16 @@ extension MASError: CustomStringConvertible { return "Uninstall failed" case .noData: return "Service did not return data" - case .jsonParsing: - return "Unable to parse response JSON" + case .jsonParsing(let data): + if let data { + if let unparsable = String(data: data, encoding: .utf8) { + return "Unable to parse response as JSON: \n\(unparsable)" + } else { + return "Received defective response" + } + } else { + return "Received empty response" + } } } } diff --git a/Sources/MasKit/Formatters/AppListFormatter.swift b/Sources/MasKit/Formatters/AppListFormatter.swift index e147595..21c915c 100644 --- a/Sources/MasKit/Formatters/AppListFormatter.swift +++ b/Sources/MasKit/Formatters/AppListFormatter.swift @@ -15,8 +15,8 @@ enum AppListFormatter { /// Formats text output with list results. /// - /// - Parameter products: List of sortware products app data. - /// - Returns: Multiliune text outoutp. + /// - Parameter products: List of software products app data. + /// - Returns: Multiline text output. static func format(products: [SoftwareProduct]) -> String { // find longest appName for formatting, default 50 let maxLength = products.map(\.appNameOrBundleIdentifier.count).max() ?? nameColumnMinWidth diff --git a/Sources/MasKit/Formatters/SearchResultFormatter.swift b/Sources/MasKit/Formatters/SearchResultFormatter.swift index 03160cf..cd0061e 100644 --- a/Sources/MasKit/Formatters/SearchResultFormatter.swift +++ b/Sources/MasKit/Formatters/SearchResultFormatter.swift @@ -13,7 +13,7 @@ enum SearchResultFormatter { /// Formats text output with search results. /// /// - Parameter results: Search results with app data - /// - Returns: Multiliune text outoutp. + /// - Returns: Multiline text output. static func format(results: [SearchResult], includePrice: Bool = false) -> String { // find longest appName for formatting, default 50 let maxLength = results.map(\.trackName.count).max() ?? 50 diff --git a/Sources/MasKit/Models/SearchResult.swift b/Sources/MasKit/Models/SearchResult.swift index fe928b6..b2ccd6b 100644 --- a/Sources/MasKit/Models/SearchResult.swift +++ b/Sources/MasKit/Models/SearchResult.swift @@ -10,7 +10,6 @@ struct SearchResult: Decodable { var bundleId: String var currentVersionReleaseDate: String var fileSizeBytes: String? - var kind: String var minimumOsVersion: String var price: Double? var sellerName: String @@ -24,7 +23,6 @@ struct SearchResult: Decodable { bundleId: String = "", currentVersionReleaseDate: String = "", fileSizeBytes: String = "0", - kind: String = "", minimumOsVersion: String = "", price: Double = 0.0, sellerName: String = "", @@ -37,7 +35,6 @@ struct SearchResult: Decodable { self.bundleId = bundleId self.currentVersionReleaseDate = currentVersionReleaseDate self.fileSizeBytes = fileSizeBytes - self.kind = kind self.minimumOsVersion = minimumOsVersion self.price = price self.sellerName = sellerName diff --git a/Sources/MasKit/Models/SoftwareProduct.swift b/Sources/MasKit/Models/SoftwareProduct.swift index 280266a..6ce7180 100644 --- a/Sources/MasKit/Models/SoftwareProduct.swift +++ b/Sources/MasKit/Models/SoftwareProduct.swift @@ -28,15 +28,13 @@ extension SoftwareProduct { /// - Parameter storeApp: App from search result. /// - Returns: true if the app is outdated; false otherwise. func isOutdatedWhenComparedTo(_ storeApp: SearchResult) -> Bool { - // Only look at min OS version if we have one, also only consider macOS apps - // Replace string literal with MasStoreSearch.Entity once `search` branch is merged. - if let osVersion = Version(tolerant: storeApp.minimumOsVersion), storeApp.kind == "mac-software" { + // If storeApp requires a version of macOS newer than the running version, do not consider self outdated. + if let osVersion = Version(tolerant: storeApp.minimumOsVersion) { let requiredVersion = OperatingSystemVersion( majorVersion: osVersion.major, minorVersion: osVersion.minor, patchVersion: osVersion.patch ) - // Don't consider an app outdated if the version in the app store requires a higher OS version. guard ProcessInfo.processInfo.isOperatingSystemAtLeast(requiredVersion) else { return false } diff --git a/Tests/MasKitTests/Commands/PurchaseCommandSpec.swift b/Tests/MasKitTests/Commands/PurchaseCommandSpec.swift index ce85977..8ceaa4a 100644 --- a/Tests/MasKitTests/Commands/PurchaseCommandSpec.swift +++ b/Tests/MasKitTests/Commands/PurchaseCommandSpec.swift @@ -20,11 +20,7 @@ public class PurchaseCommandSpec: QuickSpec { it("purchases apps") { let cmd = PurchaseCommand() let result = cmd.run(PurchaseCommand.Options(appIds: [])) - expect(result) - .to( - beFailure { error in - expect(error) == .notSupported - }) + expect(result).to(beSuccess()) } } } diff --git a/Tests/MasKitTests/Controllers/AppLibraryMock.swift b/Tests/MasKitTests/Controllers/AppLibraryMock.swift index 4ca7256..2a1f4b1 100644 --- a/Tests/MasKitTests/Controllers/AppLibraryMock.swift +++ b/Tests/MasKitTests/Controllers/AppLibraryMock.swift @@ -27,7 +27,7 @@ class AppLibraryMock: AppLibrary { } } -/// Members not part of the AppLibrary protocol that are only for test state managment. +/// Members not part of the AppLibrary protocol that are only for test state management. extension AppLibraryMock { /// Clears out the list of installed apps. func reset() { diff --git a/Tests/MasKitTests/Errors/MASErrorTestCase.swift b/Tests/MasKitTests/Errors/MASErrorTestCase.swift index 38e4ae1..503b1ce 100644 --- a/Tests/MasKitTests/Errors/MASErrorTestCase.swift +++ b/Tests/MasKitTests/Errors/MASErrorTestCase.swift @@ -122,7 +122,7 @@ class MASErrorTestCase: XCTestCase { } func testJsonParsing() { - error = .jsonParsing(error: nil) - XCTAssertEqual(error.description, "Unable to parse response JSON") + error = .jsonParsing(data: nil) + XCTAssertEqual(error.description, "Received empty response") } } diff --git a/Tests/MasKitTests/Models/SoftwareProductSpec.swift b/Tests/MasKitTests/Models/SoftwareProductSpec.swift index ba1262f..73806a4 100644 --- a/Tests/MasKitTests/Models/SoftwareProductSpec.swift +++ b/Tests/MasKitTests/Models/SoftwareProductSpec.swift @@ -26,10 +26,10 @@ public class SoftwareProductSpec: QuickSpec { itemIdentifier: 111 ) - let currentApp = SearchResult(kind: "mac-software", version: "1.0.0") - let appUpdate = SearchResult(kind: "mac-software", version: "2.0.0") - let higherOs = SearchResult(kind: "mac-software", minimumOsVersion: "99.0.0", version: "3.0.0") - let updateIos = SearchResult(kind: "software", minimumOsVersion: "99.0.0", version: "3.0.0") + let currentApp = SearchResult(version: "1.0.0") + let appUpdate = SearchResult(version: "2.0.0") + let higherOs = SearchResult(minimumOsVersion: "99.0.0", version: "3.0.0") + let updateIos = SearchResult(minimumOsVersion: "99.0.0", version: "3.0.0") it("is not outdated when there is no new version available") { expect(app.isOutdatedWhenComparedTo(currentApp)) == false @@ -37,11 +37,11 @@ public class SoftwareProductSpec: QuickSpec { it("is outdated when there is a new version available") { expect(app.isOutdatedWhenComparedTo(appUpdate)) == true } - it("is not outdated when the new version requires a higher OS version") { + it("is not outdated when the new version of mac-software requires a higher OS version") { expect(app.isOutdatedWhenComparedTo(higherOs)) == false } - it("ignores minimum iOS version") { - expect(app.isOutdatedWhenComparedTo(updateIos)) == true + it("is not outdated when the new version of software requires a higher OS version") { + expect(app.isOutdatedWhenComparedTo(updateIos)) == false } } } diff --git a/docs/sample.swift b/docs/sample.swift index 793d947..fd7091e 100644 --- a/docs/sample.swift +++ b/docs/sample.swift @@ -74,7 +74,7 @@ case let .success(data): print("The response returned successfully \(data)") case let .failure(error): - print("An error occured: \(error)") + print("An error occurred: \(error)") } // MARK: Organization diff --git a/script/bootstrap b/script/bootstrap index 9177fc7..fcfc38d 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/bin/bash -eu # # script/bootstrap # mas @@ -6,10 +6,17 @@ # Installs development dependencies and builds project dependencies. # +mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")" + +if ! cd -- "${mas_dir}"; then + printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2 + exit 1 +fi + main() { script/clean - echo "==> 👢 Bootstrapping" + printf $'==> 👢 Bootstrapping\n' # Install Homebrew tools rm -f Brewfile.lock.json diff --git a/script/build b/script/build index 8f0d1ae..44f3db0 100755 --- a/script/build +++ b/script/build @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/bin/bash -eu # # script/build # mas @@ -6,9 +6,16 @@ # Builds the Swift Package. # +mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")" + +if ! cd -- "${mas_dir}"; then + printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2 + exit 1 +fi + # Build for the host architecture by default. ARCH=() -if [[ "$1" == '--universal' ]]; then +if [[ "${#}" -gt 1 && "${1}" == '--universal' ]]; then ARCH=(--arch arm64 --arch x86_64) fi @@ -21,6 +28,6 @@ fi echo "==> 🏗️ Building mas ($(script/version))" swift build \ --configuration release \ - "${ARCH[@]}" \ + "${ARCH[@]+"${ARCH[@]}"}" \ --disable-sandbox \ - "${CACHE[@]}" + "${CACHE[@]+"${CACHE[@]}"}" diff --git a/script/format b/script/format index dc1287c..9091140 100755 --- a/script/format +++ b/script/format @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/bin/bash -eu # # script/format # mas @@ -6,34 +6,42 @@ # Linting checks for development and CI. # # Automatically formats and fixes style violations using various tools. -# Additionally runs `lint` to report any remaining style violations. # # Please keep in sync with script/lint. # -echo "==> 🚨 Formatting mas" +mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")" -for LINTER in markdownlint shfmt swiftformat swiftlint; do +if ! cd -- "${mas_dir}"; then + printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2 + exit 1 +fi + +printf $'==> 🚨 Formatting mas\n' + +for LINTER in markdownlint shfmt swift-format swiftformat swiftlint; do if [[ ! -x "$(command -v ${LINTER})" ]]; then - echo "error: ${LINTER} is not installed. Run 'script/bootstrap' or 'brew install ${LINTER}'." + printf $'error: %s is not installed. Run \'script/bootstrap\' or \'brew install %s\'.\n' "${LINTER}" "${LINTER}" exit 1 fi done -echo -echo "--> 🖊 Markdown" -markdownlint --config .markdownlint.json --fix .github . - -echo -echo "--> 🕊️ Swift" for SOURCE in Package.swift Sources Tests; do - swiftformat ${SOURCE} - swift run swift-format format --in-place --recursive ${SOURCE} - swiftlint lint --fix --strict ${SOURCE} + printf -- $'--> 🕊 %s swift-format\n' "${SOURCE}" + swift-format format --in-place --recursive "${SOURCE}" + printf -- $'--> 🕊 %s swiftformat\n' "${SOURCE}" + swiftformat "${SOURCE}" + printf -- $'--> 🕊 %s swiftlint\n' "${SOURCE}" + swiftlint --fix --strict "${SOURCE}" done -echo -echo "--> 📜 Bash" -shfmt -i 2 -l -w contrib/ script/ +printf -- $'--> 📜 Bash shfmt\n' +shfmt \ + --write \ + --list \ + --indent 2 \ + --case-indent \ + contrib/ script/ -script/lint +printf -- $'--> 〽️ Markdown\n' +markdownlint --config .markdownlint.json --fix .github . diff --git a/script/lint b/script/lint index e3c3668..c362dbb 100755 --- a/script/lint +++ b/script/lint @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/bin/bash -u # # script/lint # mas @@ -10,32 +10,63 @@ # Please keep in sync with script/format. # -echo "==> 🚨 Linting mas" +set -o pipefail -for LINTER in git markdownlint periphery shfmt swiftformat swiftlint; do - if [[ ! -x "$(command -v ${LINTER})" ]]; then - echo "error: ${LINTER} is not installed. Run 'script/bootstrap' or 'brew install ${LINTER}'." +mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")" + +if ! cd -- "${mas_dir}"; then + printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2 + exit 1 +fi + +printf $'==> 🚨 Linting mas (%s)\n' "$(script/version)" + +for linter in git markdownlint periphery shellcheck shfmt swift-format swiftformat swiftlint; do + if [[ ! -x "$(command -v ${linter})" ]]; then + printf $'error: %s is not installed. Run \'script/bootstrap\' or \'brew install %s\'.\n' "${linter}" "${linter}" exit 1 fi done -echo "--> 🌳 Git" -git diff --check - -echo -echo "--> 🖊 Markdown" -markdownlint --config .markdownlint.json .github . - -echo -echo "--> 🕊️ Swift" -for SOURCE in Package.swift Sources Tests; do - swiftformat --lint ${SOURCE} - swift run swift-format lint --recursive ${SOURCE} - swiftlint lint --strict ${SOURCE} +exit_code=0 +for source in Package.swift Sources Tests; do + printf -- $'--> 🕊 %s swift-format\n' "${source}" + swift-format lint --strict --recursive "${source}" + ((exit_code |= "${?}")) + printf -- $'--> 🕊 %s swiftformat\n' "${source}" + script -q /dev/null swiftformat --lint --strict "${source}" | + (grep -vxE $'Running SwiftFormat\\.\\.\\.\r|\\(lint mode - no files will be changed\\.\\)\r|Reading (?:config|swift-version) file at .*|\033\[32mSwiftFormat completed in \\d+\\.\\d+s\\.\033\\[0m\r|0/\\d+ files require formatting\\.\r' || true) + ((exit_code |= "${?}")) + printf -- $'--> 🕊 %s swiftlint\n' "${source}" + swiftlint --strict --quiet "${source}" 2> \ + >((grep -vxF $'warning: Configuration option \'allow_multiline_func\' in \'opening_brace\' rule is deprecated. Use the option \'ignore_multiline_function_signatures\' instead.' || true) >&2) + ((exit_code |= "${?}")) done -periphery scan -echo -echo "--> 📜 Bash" +printf -- $'--> 🐚 Bash shellcheck\n' shellcheck --shell=bash script/* -shfmt -d -i 2 -l contrib/ script/ +((exit_code |= "${?}")) + +printf -- $'--> 📜 Bash shfmt\n' +shfmt \ + --diff \ + --list \ + --indent 2 \ + --case-indent \ + contrib/ script/ +((exit_code |= "${?}")) + +printf -- $'--> 〽️ Markdown\n' +markdownlint --config .markdownlint.json .github . +((exit_code |= "${?}")) + +printf -- $'--> 🌳 Git\n' +PAGER='cat' git diff --check +((exit_code |= "${?}")) + +printf -- $'--> 🌀 Periphery\n' +script -q /dev/null periphery scan --strict --quiet --disable-update-check | + (grep -vxF $'\033[0;1;32m* \033[0;0m\033[0;1mNo unused code detected.\033[0;0m\r\n' || true) +((exit_code |= "${?}")) + +exit "${exit_code}" diff --git a/script/test b/script/test index 01188ef..e927db7 100755 --- a/script/test +++ b/script/test @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/bin/bash -eu # # script/test # mas @@ -6,5 +6,13 @@ # Runs mas tests. # -echo "==> ✅ Testing" +mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")" + +if ! cd -- "${mas_dir}"; then + printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2 + exit 1 +fi + +printf $'==> ✅ Testing mas (%s)\n' "$(script/version)" + swift test diff --git a/script/version b/script/version index 9bce7a8..bbc2219 100755 --- a/script/version +++ b/script/version @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/bin/bash -eu # # script/version # mas @@ -9,12 +9,17 @@ # This no longer works with MARKETING_VERSION build setting in Info.plist # agvtool what-marketing-version -terse1 +mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")" + +if ! cd -- "${mas_dir}"; then + printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2 + exit 1 +fi + VERSION=$(git describe --abbrev=0 --tags) VERSION=${VERSION#v} -SCRIPT_PATH=$(dirname "$(which "$0")") - -cat <"${SCRIPT_PATH}/../Sources/MasKit/Package.swift" +cat <"Sources/MasKit/Package.swift" // Generated by: script/version enum Package { static let version = "${VERSION}"