From 3b901ca28cd818138af67ddfd7a9572c6439acff Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 3 Nov 2023 22:44:36 +0000 Subject: [PATCH] Migrate CI to GitHub Actions --- .github/actions/setup-darwin/action.yml | 81 +++++++++++++ .github/actions/smoke-tests-darwin/action.yml | 42 +++++++ .github/workflows/main.yml | 108 ++++++++++++++++++ sample/ios/Runner.xcodeproj/project.pbxproj | 6 +- sample/ios/UITests/SmokeTests.swift | 2 +- 5 files changed, 236 insertions(+), 3 deletions(-) create mode 100644 .github/actions/setup-darwin/action.yml create mode 100644 .github/actions/smoke-tests-darwin/action.yml create mode 100644 .github/workflows/main.yml diff --git a/.github/actions/setup-darwin/action.yml b/.github/actions/setup-darwin/action.yml new file mode 100644 index 0000000..606710a --- /dev/null +++ b/.github/actions/setup-darwin/action.yml @@ -0,0 +1,81 @@ +name: Set up iOS/macOS environment +description: Set up the environment for building and testing the library on iOS/macOS + +inputs: + platform: + description: Either iOS or macOS + required: true + + flutter: + description: The version of Flutter to use + required: true + + xcode: + description: The version of Xcode to use + required: true + + auth0-domain: + description: The Auth0 domain + required: true + + auth0-client-id: + description: The Auth0 client ID + required: true + +runs: + using: composite + + steps: + - name: Lowercase platform value + id: lowercase-platform + run: echo "platform=$(echo ${{ inputs.platform }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT" + shell: bash + + - name: Install Flutter + uses: subosito/flutter-action@48cafc24713cca54bbe03cdc3a423187d413aafa + with: + flutter-version: ${{ inputs.flutter }} + channel: stable + cache: true + + - name: Install Flutter dependencies + working-directory: sample + run: flutter pub get + shell: bash + + - name: Set Ruby version + working-directory: sample/${{ steps.lowercase-platform.outputs.platform }} + run: ruby -e 'puts RUBY_VERSION' | tee .ruby-version + shell: bash + + - name: Set up Ruby + uses: ruby/setup-ruby@250fcd6a742febb1123a77a841497ccaa8b9e939 + with: + bundler-cache: true + cache-version: 1 + working-directory: sample/${{ steps.lowercase-platform.outputs.platform }} + + - name: Setup Xcode + run: sudo xcode-select --switch /Applications/Xcode_${{ inputs.xcode }}.app/Contents/Developer + shell: bash + + - name: Save Xcode version + run: xcodebuild -version | tee .xcode-version + shell: bash + + - id: restore-pods-cache + name: Restore Pods cache + uses: actions/cache@f5ce41475b483ad7581884324a6eca9f48f8dcc7 + with: + path: sample/${{ steps.lowercase-platform.outputs.platform }}/Pods + key: pods-${{ hashFiles('Podfile.lock') }}-${{ hashFiles('.xcode-version') }}-v1 + + - name: Install pods + working-directory: sample/${{ steps.lowercase-platform.outputs.platform }} + run: pod install + shell: bash + + - name: Set .env + working-directory: sample + run: printf '%s\n%s\n%s' 'AUTH0_DOMAIN=${{ inputs.auth0-domain }}' 'AUTH0_CLIENT_ID=${{ inputs.auth0-client-id }}' 'AUTH0_CUSTOM_SCHEME=demo' >> .env + shell: bash diff --git a/.github/actions/smoke-tests-darwin/action.yml b/.github/actions/smoke-tests-darwin/action.yml new file mode 100644 index 0000000..9012f3f --- /dev/null +++ b/.github/actions/smoke-tests-darwin/action.yml @@ -0,0 +1,42 @@ +name: Run iOS/macOS smoke tests +description: Execute the smoke test suite on iOS/macOS + +inputs: + platform: + description: Either iOS or macOS + required: true + + destination: + description: The destination string for xcodebuild + required: true + +runs: + using: composite + + steps: + - name: Lowercase platform value + id: lowercase-platform + run: echo "platform=$(echo ${{ inputs.platform }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT" + shell: bash + + - name: Build ${{ inputs.platform }} app + working-directory: sample/${{ steps.lowercase-platform.outputs.platform }} + run: flutter build ${{ steps.lowercase-platform.outputs.platform }} --debug ${{ inputs.platform == 'iOS' && '--no-codesign' || '' }} + shell: bash + + - name: Disable iOS hardware keyboard + if: ${{ inputs.platform == 'iOS' }} + run: defaults write com.apple.iphonesimulator ConnectHardwareKeyboard 0 + shell: bash + + - name: Run ${{ inputs.platform }} smoke tests + working-directory: sample/${{ steps.lowercase-platform.outputs.platform }} + run: xcodebuild test -scheme Runner -workspace Runner.xcworkspace -destination '${{ inputs.destination }}' -resultBundlePath smoke-tests.xcresult -only-testing:RunnerUITests + shell: bash + + - name: Upload xcresult bundles + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 + if: ${{ failure() }} + with: + name: '${{ inputs.platform }} xcresult bundles' + path: 'sample/${{ steps.lowercase-platform.outputs.platform }}/smoke-tests.xcresult' diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..321d581 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,108 @@ +name: CI + +on: + pull_request: + types: + - opened + - synchronize + +permissions: {} + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} + +env: + flutter: '3.x' + ios-simulator: iPhone 15 + +jobs: + authorize: + name: Authorize + environment: ${{ github.event.pull_request.head.repo.fork && 'external' || 'internal' }} + runs-on: ubuntu-latest + steps: + - run: true + + analyze-dart: + name: Analyze Dart code + needs: authorize + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + + - name: Install Flutter + uses: subosito/flutter-action@2783a3f08e1baf891508463f8c6653c258246225 + with: + flutter-version: ${{ env.flutter }} + channel: stable + cache: true + + - name: Add sample/.env + working-directory: sample + run: cp .env.example .env + + - name: Run Dart analyzer + working-directory: sample + run: flutter analyze + + test-dart: + name: Test Dart code + needs: authorize + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + + - name: Install Flutter + uses: subosito/flutter-action@2783a3f08e1baf891508463f8c6653c258246225 + with: + flutter-version: ${{ env.flutter }} + channel: stable + cache: true + + - name: Add sample/.env + working-directory: sample + run: cp .env.example .env + + - name: Run Dart tests + working-directory: sample + run: flutter test + + test-ios-smoke: + name: Run native iOS smoke tests using Xcode ${{ matrix.xcode }} + needs: authorize + runs-on: macos-13-large + environment: ${{ github.event.pull_request.head.repo.fork && 'external' || 'internal' }} + + env: + platform: iOS + USER_EMAIL: ${{ secrets.USER_EMAIL }} + USER_PASSWORD: ${{ secrets.USER_PASSWORD }} + + strategy: + matrix: + xcode: + - '15.0.1' + + steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + + - name: Set up environment + uses: ./.github/actions/setup-darwin + with: + platform: ${{ env.platform }} + flutter: ${{ env.flutter }} + xcode: ${{ matrix.xcode }} + auth0-domain: ${{ vars.AUTH0_DOMAIN }} + auth0-client-id: ${{ vars.AUTH0_CLIENT_ID }} + + - name: Run iOS smoke tests + uses: ./.github/actions/smoke-tests-darwin + with: + platform: ${{ env.platform }} + destination: 'platform=iOS Simulator,name=iPhone 15' diff --git a/sample/ios/Runner.xcodeproj/project.pbxproj b/sample/ios/Runner.xcodeproj/project.pbxproj index 4caebb8..0258dc1 100644 --- a/sample/ios/Runner.xcodeproj/project.pbxproj +++ b/sample/ios/Runner.xcodeproj/project.pbxproj @@ -204,7 +204,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 1340; - LastUpgradeCheck = 1300; + LastUpgradeCheck = 1430; ORGANIZATIONNAME = ""; TargetAttributes = { 5C84DBD72879193000E317DB = { @@ -265,6 +265,7 @@ files = ( ); inputPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", ); name = "Thin Binary"; outputPaths = ( @@ -638,7 +639,8 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - CODE_SIGN_STYLE = Manual; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; DEVELOPMENT_TEAM = ""; ENABLE_BITCODE = NO; diff --git a/sample/ios/UITests/SmokeTests.swift b/sample/ios/UITests/SmokeTests.swift index 82c0c41..6b18bfc 100644 --- a/sample/ios/UITests/SmokeTests.swift +++ b/sample/ios/UITests/SmokeTests.swift @@ -6,7 +6,7 @@ class SmokeTests: XCTestCase { private let loginButton = "Login" private let logoutButton = "Logout" private let continueButton = "Continue" - private let timeout: TimeInterval = 10 + private let timeout: TimeInterval = 30 override func setUp() { continueAfterFailure = false