From fa32f8477631a1eed6f5a67e045348fa2800026b Mon Sep 17 00:00:00 2001 From: William Walker Date: Wed, 18 Sep 2024 16:19:47 -0500 Subject: [PATCH] chore: add workflow (#9) * create build workflow * add xcresulttool * change min deployment target * change min deployment target for tests * run build first * install pkl * correct cache * reduce test footprint for debug * save test artifacts * xcpretty and save on failure * select xcode ver * proper install pkl * proper install pkl * reenable xcresulttool * restore all tests * restore build step * improve tests and add lint * simplify xcode test args and add func tests * install pkl for functional tests --- .github/workflows/lint.yml | 21 +++++++++ .github/workflows/test.yml | 80 ++++++++++++++++++++++++++++++++ .gitignore | 5 ++ Cosmic.xcodeproj/project.pbxproj | 4 ++ CosmicTests/CosmicTests.swift | 20 ++++---- 5 files changed, 120 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..922702b --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,21 @@ +name: Lint + +on: + workflow_dispatch: + pull_request: + branches: [main] + +jobs: + lint: + name: SwiftLint Linting + runs-on: macos-14 + steps: + - uses: actions/checkout@v4 + + - name: Install SwiftLint + run: | + brew install swiftlint + swiftlint version + + - name: Run SwiftLint + run: swiftlint diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..ae40456 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,80 @@ +name: Test + +on: + workflow_dispatch: + pull_request: + branches: [main] + +env: + DESTINATION: platform=macOS,arch=arm64 + SCHEME: Cosmic + TEST_SCHEME: CosmicTests + XCODE_PATH: /Applications/Xcode_16.0.app/Contents/Developer + PKL_VERSION: 0.26.3 + PKL_ARCH: macos-aarch64 + +jobs: + xcode_tests: + name: Xcode Tests + runs-on: macos-14 + steps: + - uses: actions/checkout@v4 + + - name: Install pkl + run: | + curl -L -o pkl "https://github.com/apple/pkl/releases/download/${PKL_VERSION}/pkl-${PKL_ARCH}" + chmod +x pkl + sudo mv pkl /usr/local/bin/pkl + pkl --version + + - name: Select Xcode version + run: sudo xcode-select -s "${XCODE_PATH}" + + - uses: actions/cache@v4 + with: + path: | + ~/Library/Developer/Xcode/DerivedData/Cosmic-*/SourcePackages/ + ~/Library/Caches/org.swift.swiftpm/ + key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }} + + - name: Execute build + run: xcodebuild build -scheme "$SCHEME" -destination "$DESTINATION" CODE_SIGNING_ALLOWED='NO' | xcpretty && exit ${PIPESTATUS[0]} + + - name: Execute test + run: xcodebuild test -resultBundlePath TestResults -scheme "$TEST_SCHEME" -destination "$DESTINATION" CODE_SIGNING_ALLOWED='NO' | xcpretty && exit ${PIPESTATUS[0]} + + - name: Archive test results + uses: actions/upload-artifact@v4 + with: + name: TestResults.xcresult + path: TestResults.xcresult/ + + functional_tests: + name: Functional Tests + runs-on: macos-14 + steps: + - uses: actions/checkout@v4 + + - name: Install pkl + run: | + curl -L -o pkl "https://github.com/apple/pkl/releases/download/${PKL_VERSION}/pkl-${PKL_ARCH}" + chmod +x pkl + sudo mv pkl /usr/local/bin/pkl + pkl --version + + - name: Select Xcode version + run: sudo xcode-select -s "${XCODE_PATH}" + + - name: Build and archive Cosmic + run: | + xcodebuild archive -scheme "$SCHEME" -destination "$DESTINATION" CODE_SIGNING_ALLOWED='NO' -archivePath ./build/Cosmic.xcarchive + ls ./build + + - name: Install Cosmic + run: | + sudo cp ./build/Cosmic.xcarchive/Products/usr/local/bin/cosmic /usr/local/bin/cosmic + cosmic --help + + - name: Run Cosmic command + run: | + cosmic add k9s diff --git a/.gitignore b/.gitignore index 79c35b2..ffd2109 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ +# .github/workflows/test.yml artifacts +build/ +TestResults.xcresult +TestResults + # macOS .DS_Store diff --git a/Cosmic.xcodeproj/project.pbxproj b/Cosmic.xcodeproj/project.pbxproj index c0c10bf..812337f 100644 --- a/Cosmic.xcodeproj/project.pbxproj +++ b/Cosmic.xcodeproj/project.pbxproj @@ -359,6 +359,7 @@ CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = QSQY64SHJ5; ENABLE_HARDENED_RUNTIME = YES; + MACOSX_DEPLOYMENT_TARGET = 14.6; PRODUCT_BUNDLE_IDENTIFIER = com.willswire.Cosmic; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -372,6 +373,7 @@ CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = QSQY64SHJ5; ENABLE_HARDENED_RUNTIME = YES; + MACOSX_DEPLOYMENT_TARGET = 14.6; PRODUCT_BUNDLE_IDENTIFIER = com.willswire.Cosmic; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -386,6 +388,7 @@ CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = QSQY64SHJ5; GENERATE_INFOPLIST_FILE = YES; + MACOSX_DEPLOYMENT_TARGET = 14.6; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = com.willswire.CosmicTests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -401,6 +404,7 @@ CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = QSQY64SHJ5; GENERATE_INFOPLIST_FILE = YES; + MACOSX_DEPLOYMENT_TARGET = 14.6; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = com.willswire.CosmicTests; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/CosmicTests/CosmicTests.swift b/CosmicTests/CosmicTests.swift index 0097433..57755a6 100644 --- a/CosmicTests/CosmicTests.swift +++ b/CosmicTests/CosmicTests.swift @@ -14,16 +14,16 @@ struct CosmicTests { @Test( "Install a package", arguments: [ - "k9s", - "zarf", - "age", - "hermes", - "dasel", - "apko", - "git-lfs", - "gitleaks", - "gh", - "sops" + "k9s" + //"zarf", + //"age", + //"hermes", + //"dasel", + //"apko", + //"git-lfs", + //"gitleaks", + //"gh", + //"sops", ]) func installPackage(packageName: String) async throws { let addCommand = Cosmic.Add()