From adc120ac4a8e82aa915cde2cb8d726c857a4a3c7 Mon Sep 17 00:00:00 2001 From: Adam Sajko Date: Fri, 28 Jun 2024 11:39:11 +0200 Subject: [PATCH] Add E2E tests for Github Actions --- .github/actions/build-android/action.yml | 10 ++++ .github/actions/build-ios/action.yml | 14 ++++++ .github/actions/install-android/action.yml | 11 +++++ .github/actions/install-ios/action.yml | 25 ++++++++++ .github/actions/install/action.yml | 11 ++++- .github/workflows/e2e-tests.yml | 51 ++++++++++++++++++++ .github/workflows/{ci.yml => unit-tests.yml} | 7 ++- 7 files changed, 123 insertions(+), 6 deletions(-) create mode 100644 .github/actions/build-android/action.yml create mode 100644 .github/actions/build-ios/action.yml create mode 100644 .github/actions/install-android/action.yml create mode 100644 .github/actions/install-ios/action.yml create mode 100644 .github/workflows/e2e-tests.yml rename .github/workflows/{ci.yml => unit-tests.yml} (71%) diff --git a/.github/actions/build-android/action.yml b/.github/actions/build-android/action.yml new file mode 100644 index 0000000..7e5db06 --- /dev/null +++ b/.github/actions/build-android/action.yml @@ -0,0 +1,10 @@ +name: 'Build Android App' +description: 'Build the Android app' + +runs: + using: 'composite' + steps: + - name: Build Android App + shell: bash + working-directory: android + run: ./gradlew assembleRelease diff --git a/.github/actions/build-ios/action.yml b/.github/actions/build-ios/action.yml new file mode 100644 index 0000000..ef83e6d --- /dev/null +++ b/.github/actions/build-ios/action.yml @@ -0,0 +1,14 @@ +name: 'Build iOS App' +description: 'Build the iOS app' + +runs: + using: 'composite' + steps: + - name: Build iOS App + shell: bash + working-directory: ios + run: | + xcodebuild build -scheme 'WeatherApp' \ + -configuration Debug \ + -workspace 'WeatherApp.xcworkspace' \ + -destination 'generic/platform=iOS Simulator' CONFIGURATION_BUILD_DIR=$PWD/build diff --git a/.github/actions/install-android/action.yml b/.github/actions/install-android/action.yml new file mode 100644 index 0000000..fef52b5 --- /dev/null +++ b/.github/actions/install-android/action.yml @@ -0,0 +1,11 @@ +name: 'Install Android dependencies' +description: 'Install dependencies for the project' + +runs: + using: 'composite' + steps: + - name: Set up JDK 11 + uses: actions/setup-java@v2 + with: + java-version: '17' + distribution: 'adopt' diff --git a/.github/actions/install-ios/action.yml b/.github/actions/install-ios/action.yml new file mode 100644 index 0000000..f66c754 --- /dev/null +++ b/.github/actions/install-ios/action.yml @@ -0,0 +1,25 @@ +name: 'Install iOS dependencies' +description: 'Install dependencies for the project' + +runs: + using: 'composite' + steps: + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.0' + bundler-cache: true + + - name: Install Bundler + shell: bash + working-directory: ios + run: bundle install + + - name: Install CocoaPods + shell: bash + run: sudo gem install cocoapods + + - name: Install Pods + shell: bash + working-directory: ios + run: pod install diff --git a/.github/actions/install/action.yml b/.github/actions/install/action.yml index 1bb31bf..32cc99e 100644 --- a/.github/actions/install/action.yml +++ b/.github/actions/install/action.yml @@ -1,11 +1,18 @@ name: 'Install dependencies' description: 'Install dependencies for the project' +inputs: + WEATHER_API_KEY: + description: 'Weather API key' + required: true + runs: using: 'composite' steps: - - name: Copy .env file + - name: Create .env file shell: bash - run: cp .env.template .env + run: | + touch .env + echo WEATHER_API_KEY=${{ inputs.WEATHER_API_KEY }} >> .env - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml new file mode 100644 index 0000000..0931a45 --- /dev/null +++ b/.github/workflows/e2e-tests.yml @@ -0,0 +1,51 @@ +name: E2E Tests + +on: + push: + branches: ['main'] + pull_request: + branches: ['main'] + +jobs: + ios-e2e-tests: + runs-on: macos-latest + + strategy: + matrix: + node-version: [20.x] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/install + with: + WEATHER_API_KEY: ${{ secrets.WEATHER_API_KEY }} + - uses: ./.github/actions/install-ios + - uses: ./.github/actions/build-ios + - uses: mobile-dev-inc/action-maestro-cloud@v1.8.1 + with: + api-key: ${{ secrets.MAESTRO_CLOUD_API_KEY }} + app-file: build/WeatherApp.app + + android-e2e-tests: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [20.x] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + outputs: + apk: android/app/build/outputs/apk/release/app-release.apk + + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/install + with: + WEATHER_API_KEY: ${{ secrets.WEATHER_API_KEY }} + - uses: ./.github/actions/install-android + - uses: ./.github/actions/build-android + - uses: mobile-dev-inc/action-maestro-cloud@v1.8.1 + with: + api-key: ${{ secrets.MAESTRO_CLOUD_API_KEY }} + app-file: android/app/build/outputs/apk/release/app-release.apk diff --git a/.github/workflows/ci.yml b/.github/workflows/unit-tests.yml similarity index 71% rename from .github/workflows/ci.yml rename to .github/workflows/unit-tests.yml index c74116a..c877ec5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/unit-tests.yml @@ -1,7 +1,4 @@ -# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs - -name: CI +name: Unit Tests on: push: @@ -21,6 +18,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: ./.github/actions/install + with: + WEATHER_API_KEY: ${{ secrets.WEATHER_API_KEY }} - name: Run TypeScript env: