diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration_tests.yml new file mode 100644 index 00000000..36eeb989 --- /dev/null +++ b/.github/workflows/integration_tests.yml @@ -0,0 +1,50 @@ +name: Reusable action of Integration tests + +on: + workflow_call: + secrets: + CI_USER_TOKEN: + required: true + TRAVIS_COM_TOKEN: + required: true + +jobs: + integration_tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + # You should create a personal access token and store it in your repository + token: ${{ secrets.CI_USER_TOKEN }} + repository: 'optimizely/travisci-tools' + path: 'home/runner/travisci-tools' + ref: 'master' + - name: set SDK Branch if PR + if: ${{ github.event_name == 'pull_request' }} + run: | + echo "SDK_BRANCH=${{ github.head_ref }}" >> $GITHUB_ENV + - name: set SDK Branch if not pull request + if: ${{ github.event_name != 'pull_request' }} + run: | + echo "SDK_BRANCH=${{ github.ref_name }}" >> $GITHUB_ENV + echo "TRAVIS_BRANCH=${{ github.ref_name }}" >> $GITHUB_ENV + - name: Trigger build + env: + SDK: swift + TESTAPP_TAG: master + BUILD_NUMBER: ${{ github.run_id }} + TESTAPP_BRANCH: master + GITHUB_TOKEN: ${{ secrets.CI_USER_TOKEN }} + TRAVIS_EVENT_TYPE: ${{ github.event_name }} + TRAVIS_REPO_SLUG: ${{ github.repository }} + TRAVIS_PULL_REQUEST_SLUG: ${{ github.repository }} + UPSTREAM_REPO: ${{ github.repository }} + TRAVIS_COMMIT: ${{ github.sha }} + TRAVIS_PULL_REQUEST_SHA: ${{ github.event.pull_request.head.sha }} + TRAVIS_PULL_REQUEST: ${{ github.event.pull_request.number }} + UPSTREAM_SHA: ${{ github.sha }} + TRAVIS_COM_TOKEN: ${{ secrets.TRAVIS_COM_TOKEN }} + EVENT_MESSAGE: ${{ github.event.message }} + HOME: 'home/runner' + run: | + home/runner/travisci-tools/trigger-script-with-status-update.sh diff --git a/.github/workflows/lint_markdown.yml b/.github/workflows/lint_markdown.yml new file mode 100644 index 00000000..e3e90314 --- /dev/null +++ b/.github/workflows/lint_markdown.yml @@ -0,0 +1,19 @@ +name: Reusable action of linting markdown files + +on: [workflow_call] + +jobs: + lint_markdown: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '2.6' + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + - name: Install gem and Run tests + run: | + cd ../../ + gem install awesome_bot + find . -type f -name '*.md' -exec awesome_bot {} \; diff --git a/.github/workflows/source_clear_cron.yml b/.github/workflows/source_clear_cron.yml new file mode 100644 index 00000000..4a9b2dcf --- /dev/null +++ b/.github/workflows/source_clear_cron.yml @@ -0,0 +1,18 @@ +name: Source clear + +on: + push: + branches: [ master ] + schedule: + # Runs "weekly" + - cron: '0 0 * * 0' + +jobs: + source_clear: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Source clear scan + env: + SRCCLR_API_TOKEN: ${{ secrets.SRCCLR_API_TOKEN }} + run: curl -sSL https://download.sourceclear.com/ci.sh | bash -s - scan diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml new file mode 100644 index 00000000..1ac7229d --- /dev/null +++ b/.github/workflows/swift.yml @@ -0,0 +1,89 @@ +name: Swift + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + workflow_dispatch: + inputs: + PREP: + required: false + type: boolean + description: prepare to release + RELEASE: + required: false + type: boolean + description: release + +env: + VERSION: 3.10.1 + +jobs: + + lint_markdown_files: + uses: optimizely/swift-sdk/.github/workflows/lint_markdown.yml@yasir/gitAction + + integration_tests: + if: "${{ github.event.inputs.PREP == '' && github.event.inputs.RELEASE == '' }}" + uses: optimizely/swift-sdk/.github/workflows/integration_tests.yml@yasir/gitAction + secrets: + CI_USER_TOKEN: ${{ secrets.CI_USER_TOKEN }} + TRAVIS_COM_TOKEN: ${{ secrets.TRAVIS_COM_TOKEN }} + + lint: + runs-on: macos-latest + steps: + - uses: actions/checkout@v3 + - uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: '12.4' + - env: + SRCCLR_API_TOKEN: ${{ secrets.SRCCLR_API_TOKEN }} + run: | + gem install cocoapods -v '1.9.3' + pod spec lint --quick + curl -sSL https://download.sourceclear.com/ci.sh | bash + + unittests: + if: "${{ github.event.inputs.PREP == '' && github.event.inputs.RELEASE == '' }}" + uses: optimizely/swift-sdk/.github/workflows/unit_tests.yml@yasir/gitAction + + prepare_for_release: + runs-on: macos-latest + if: "${{ github.event.inputs.PREP == 'true' && github.event_name == 'workflow_dispatch' }}" + steps: + - uses: actions/checkout@v3 + - uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: '12.4' + - id: prepare_for_release + name: Prepare for release + env: + HOME: 'home/runner' + REPO_SLUG: ${{ github.repository }} + BRANCH: ${{ github.ref_name }} + GITHUB_USER: optibot + GITHUB_TOKEN: ${{ secrets.CI_USER_TOKEN }} + run: | + gem install cocoapods -v '1.9.3' + Scripts/run_prep.sh + - name: Check prepare for release failure + if: steps.prepare_for_release.conclusion == 'failure' + run: cat /tmp/build.out + + release: + if: "${{github.event.inputs.RELEASE == 'true' && github.event_name == 'workflow_dispatch' }}" + runs-on: macos-latest + steps: + - uses: actions/checkout@v3 + - uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: '12.4' + - name: Push to cocoapods.org + env: + GITHUB_TOKEN: ${{ secrets.CI_USER_TOKEN }} + BRANCH: ${{ github.ref_name }} + run: | + gem install cocoapods -v '1.9.3' + Scripts/run_release.sh diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml new file mode 100644 index 00000000..36a9b8b7 --- /dev/null +++ b/.github/workflows/unit_tests.yml @@ -0,0 +1,95 @@ +name: Reusable action of Unit tests + +on: [workflow_call] + +env: + COVERAGE_DIR: ./COVERAGE + +jobs: + unittests: + runs-on: macos-10.15 + strategy: + fail-fast: false + matrix: + include: + - os: 14.4 + device: "iPhone 11" + scheme: "OptimizelySwiftSDK-iOS" + test_sdk: "iphonesimulator" + platform: "iOS Simulator" + os_type: "iOS" + simulator_xcode_version: 12.4 + - os: 13.3 + device: "iPhone 8" + scheme: "OptimizelySwiftSDK-iOS" + test_sdk: "iphonesimulator" + platform: "iOS Simulator" + os_type: "iOS" + simulator_xcode_version: 11.3.1 + - os: 12.4 + device: "iPad Air" + scheme: "OptimizelySwiftSDK-iOS" + test_sdk: "iphonesimulator" + platform: "iOS Simulator" + os_type: "iOS" + simulator_xcode_version: 10.3 + - os: 12.4 + device: "Apple TV 4K" + scheme: "OptimizelySwiftSDK-tvOS" + test_sdk: "appletvsimulator" + platform: "tvOS Simulator" + os_type: "tvOS" + simulator_xcode_version: 10.3 + steps: + - uses: actions/checkout@v3 + - uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: 12.4 + - name: set SDK Branch if PR + if: ${{ github.event_name == 'pull_request' }} + run: | + echo "BRANCH=${{ github.base_ref }}" >> $GITHUB_ENV + - name: set SDK Branch if not pull request + if: ${{ github.event_name != 'pull_request' }} + run: | + echo "BRANCH=${{ github.ref_name }}" >> $GITHUB_ENV + - id: unit_tests + env: + SCHEME: ${{ matrix.scheme }} + TEST_SDK: ${{ matrix.test_sdk }} + PLATFORM: ${{ matrix.platform }} + OS: ${{ matrix.os }} + OS_TYPE: ${{ matrix.os_type }} + SIMULATOR_XCODE_VERSION: ${{ matrix.simulator_xcode_version }} + NAME: ${{ matrix.device }} + run: | + gem install coveralls-lcov + gem install cocoapods -v '1.9.3' + pod repo update + pod install + HOMEBREW_NO_INSTALL_CLEANUP=true brew update && brew install jq + Scripts/prepare_simulator.sh + Scripts/run_unit_tests.sh + - name: Check on failures (Archive Test Results) + uses: actions/upload-artifact@v3 + if: steps.unit_tests.outcome != 'success' + with: + name: build-logs-${{ matrix.device }}-${{ matrix.os }} + path: build/Logs + - # - report coverage for PR and iPhone 11 only (avoid redundant ones) + # - use Xcode12.4+ (older Xcode reports a wrong number) + name: Check on success + id: coveralls + if: ${{ steps.unit_tests.outcome == 'success' && env.BRANCH == 'master' && env.PLATFORM == 'iOS Simulator' && env.NAME == 'iPhone 11' }} + env: + PLATFORM: ${{ matrix.platform }} + NAME: ${{ matrix.device }} + run: | + Scripts/prepare_coveralls_report.sh + sleep 5 + - name: Upload coveralls report + if: steps.coveralls.outcome == 'success' + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: ./xccov2lcov/lcov.info diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 83c87e49..00000000 --- a/.travis.yml +++ /dev/null @@ -1,136 +0,0 @@ -language: minimal -os: linux - -# Integration tests need to run first to reset the PR build status to pending -stages: - - name: 'Source Clear' - - name: 'Lint markdown files' - - name: 'Trigger Integration Tests' - if: env(RUN_COMPAT_SUITE) = true and env(PREP) IS NOT present and env(RELEASE) IS NOT present - - name: 'Lint' - - name: 'Unit Tests' - if: env(PREP) IS NOT present and env(RELEASE) IS NOT present - - name: 'Prepare for release' - if: env(PREP) = true and type = api - - name: 'Release' - if: env(RELEASE) = true and type = api - -jobs: - include: - - stage: 'Lint markdown files' - os: linux - language: generic - install: gem install awesome_bot - script: - - find . -type f -name '*.md' -exec awesome_bot {} \; - notifications: - email: false - - - stage: 'Trigger Integration Tests' - language: minimal - os: linux - env: - - SDK=swift - - BUILD_NUMBER=${TRAVIS_JOB_NUMBER/.} - - TESTAPP_TAG=master - - SDK_BRANCH=$TRAVIS_PULL_REQUEST_BRANCH - - cache: false - install: - - mkdir $HOME/travisci-tools && pushd $HOME/travisci-tools && git init && git pull https://$CI_USER_TOKEN@github.com/optimizely/travisci-tools.git && popd - script: - - $HOME/travisci-tools/trigger-script-with-status-update.sh - - - stage: 'Lint' - language: swift - os: osx - osx_image: xcode12.4 - install: - - gem install cocoapods -v '1.9.3' - script: - - pod spec lint --quick - after_script: - - curl -sSL https://download.sourceclear.com/ci.sh | bash - - - stage: 'Source Clear' - if: type = cron - addons: - srcclr: true - before_install: skip - install: skip - before_script: skip - script: skip - after_success: skip - - - &unittests - stage: 'Unit Tests' - language: swift - os: osx - osx_image: xcode12.4 - branches: - only: - - master - env: COVERAGE_DIR=./COVERAGE SCHEME=OptimizelySwiftSDK-iOS TEST_SDK=iphonesimulator PLATFORM='iOS Simulator' OS=14.4 NAME='iPhone 11' - name: PLATFORM='iOS Simulator' OS=14.4 NAME='iPhone 11' - install: - #- gem install slather --no-document --quiet - - gem install coveralls-lcov - # - - gem install cocoapods -v '1.9.3' - - pod repo update - - pod install - # install jq without cleaning up - - HOMEBREW_NO_INSTALL_CLEANUP=true brew update && brew install jq - # preload simulator - - Scripts/start_simulator.sh - script: - - Scripts/run_unit_tests.sh - after_success: - - Scripts/upload_coveralls.sh - - sleep 5 # https://github.com/travis-ci/travis-ci/issues/4725 - after_failure: - # install travis artifacts uploader - - sudo curl -sL https://raw.githubusercontent.com/travis-ci/artifacts/master/install | bash - - artifacts upload --target-paths "/${TRAVIS_REPO_SLUG}/${TRAVIS_BUILD_NUMBER}/${TRAVIS_JOB_NUMBER}/xcodebuild_logs" $(find /Users/travis/Library/Developer/Xcode/ -name *.xcresult -o -name *.log) - - artifacts upload --target-paths "/${TRAVIS_REPO_SLUG}/${TRAVIS_BUILD_NUMBER}/${TRAVIS_JOB_NUMBER}/buildoutput" "$TRAVIS_BUILD_DIR/buildoutput" - - <<: *unittests - env: COVERAGE_DIR=./COVERAGE SCHEME=OptimizelySwiftSDK-iOS TEST_SDK=iphonesimulator PLATFORM='iOS Simulator' OS=13.3 NAME='iPhone 8' - name: PLATFORM='iOS Simulator' OS=13.3 NAME='iPhone 8' - - <<: *unittests - env: COVERAGE_DIR=./COVERAGE SCHEME=OptimizelySwiftSDK-iOS TEST_SDK=iphonesimulator PLATFORM='iOS Simulator' OS=11.4 NAME='iPad Air' - name: PLATFORM='iOS Simulator' OS=11.4 NAME='iPad Air' - - <<: *unittests - env: COVERAGE_DIR=./COVERAGE SCHEME=OptimizelySwiftSDK-tvOS TEST_SDK=appletvsimulator PLATFORM='tvOS Simulator' OS=12.1 NAME='Apple TV 4K' - name: PLATFORM='tvOS Simulator' OS=12.1 NAME='Apple TV 4K' - - - stage: 'Prepare for release' - name: Prepare for release - language: swift - os: osx - osx_image: xcode12.4 - env: - - VERSION=3.10.1 - install: - # install hub - - wget https://github.com/github/hub/releases/download/v2.11.2/hub-darwin-amd64-2.11.2.tgz -O /tmp/hub-darwin-amd64-2.11.2.tgz && tar -xvf /tmp/hub-darwin-amd64-2.11.2.tgz -C /usr/local/opt && ln -s /usr/local/opt/hub-darwin-amd64-2.11.2/bin/hub /usr/local/bin/hub - # upgrade cocoapods - - gem install cocoapods -v '1.9.3' - script: - - Scripts/run_prep.sh - after_failure: - - cat /tmp/build.out - - - stage: 'Release' - name: Push to cocoapods.org - language: minimal - os: osx - osx_image: xcode12.4 - env: - - VERSION=3.10.1 - install: - # install hub - - wget https://github.com/github/hub/releases/download/v2.11.2/hub-darwin-amd64-2.11.2.tgz -O /tmp/hub-darwin-amd64-2.11.2.tgz && tar -xvf /tmp/hub-darwin-amd64-2.11.2.tgz -C /usr/local/opt && ln -s /usr/local/opt/hub-darwin-amd64-2.11.2/bin/hub /usr/local/bin/hub - # upgrade cocoapods - - gem install cocoapods -v '1.9.3' - script: - - Scripts/run_release.sh diff --git a/README.md b/README.md index 01b50fc8..bffeb3f5 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # SWIFT SDK [![Apache 2.0](https://img.shields.io/github/license/nebula-plugins/gradle-extra-configurations-plugin.svg)](http://www.apache.org/licenses/LICENSE-2.0) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/carthage/carthage) -[![Build Status](https://travis-ci.com/optimizely/swift-sdk.svg?branch=master)](https://travis-ci.com/optimizely/swift-sdk) +[![Build Status](https://github.com/optimizely/swift-sdk/actions/workflows/swift.yml/badge.svg?branch=yasir/gitAction)](https://github.com/optimizely/swift-sdk/actions) [![Coverage Status](https://coveralls.io/repos/github/optimizely/swift-sdk/badge.svg?branch=master)](https://coveralls.io/github/optimizely/swift-sdk?branch=master) [![Platforms](https://img.shields.io/cocoapods/p/OptimizelySwiftSDK.svg)](https://img.shields.io/cocoapods/p/OptimizelySwiftSDK.svg) [![Podspec](https://img.shields.io/cocoapods/v/OptimizelySwiftSDK.svg)](https://cocoapods.org/pods/OptimizelySwiftSDK) diff --git a/Scripts/build_all.sh b/Scripts/build_all.sh index d5e7b960..5b728397 100755 --- a/Scripts/build_all.sh +++ b/Scripts/build_all.sh @@ -35,4 +35,3 @@ main() { } main - diff --git a/Scripts/prepare_coveralls_report.sh b/Scripts/prepare_coveralls_report.sh new file mode 100755 index 00000000..adfb0eba --- /dev/null +++ b/Scripts/prepare_coveralls_report.sh @@ -0,0 +1,14 @@ +#!/bin/bash -e + +# prepare_coveralls_report.sh +# +# Usage: +# $ ./prepare_coveralls_report.sh +# + +# [coveralls] +# - exclude coverage for Test codes by setting OptimizelySwiftSDK-iOS scheme > Test > Options > Gather coverage for selected targets +mkdir xccov2lcov && cd xccov2lcov && git init && git fetch --depth=1 https://github.com/trax-retail/xccov2lcov.git && git checkout FETCH_HEAD +xcrun xccov view --report --json ../$COVERAGE_DIR/Logs/Test/*.xcresult > coverage.json +swift run xccov2lcov coverage.json > lcov.info +cd .. diff --git a/Scripts/prepare_simulator.sh b/Scripts/prepare_simulator.sh new file mode 100755 index 00000000..3f2dba41 --- /dev/null +++ b/Scripts/prepare_simulator.sh @@ -0,0 +1,46 @@ +#!/bin/bash -e +set -eou pipefail + +# expects the following environment variables defined +# PLATFORM (eg. iOS Simulator) +# OS (eg. 12.0) +# NAME (eg. iPad Air) +# OS_TYPE (eg. iOS) +# SIMULATOR_XCODE_VERSION (Which Xcode's simulator to use) +# Since github actions only provides limit simulators with each xcode, we need to link simulators from other versions of xcode to be used by current xcode. +# We must use old simulators with current xcode since older xcode versions do not support swift 5 which is required by Swift SDK. +# More about XCode and its compatible simulators can be found here: https://github.com/actions/virtual-environments/blob/main/images/macos/macos-10.15-Readme.md +# https://github.com/actions/virtual-environments/issues/551 + +if [ "$SIMULATOR_XCODE_VERSION" != 12.4 ]; then + os_folder="iPhoneOS" + os="${OS/./-}" + name="${NAME// /-}" + + sudo mkdir -p /Library/Developer/CoreSimulator/Profiles/Runtimes + + # Check if device is Apple tv, update os_folder for linking purposes + if [[ "$NAME" = "Apple TV"* ]] + then + name="${name}-1080p" + os_folder="AppleTVOS" + fi + + # update os_folder as per xcode version + if [ "$SIMULATOR_XCODE_VERSION" == 10.3 ] + then + os_folder="${os_folder}.platform/Developer/Library" + else + os_folder="${os_folder}.platform/Library/Developer" + fi + + # Link and create simulators from older xcode versions which are not part of the current xcode version + sudo ln -s /Applications/Xcode_$SIMULATOR_XCODE_VERSION.app/Contents/Developer/Platforms/$os_folder/CoreSimulator/Profiles/Runtimes/$OS_TYPE.simruntime /Library/Developer/CoreSimulator/Profiles/Runtimes/$OS_TYPE\ $OS.simruntime + xcrun simctl create "custom-device" "com.apple.CoreSimulator.SimDeviceType.$name" "com.apple.CoreSimulator.SimRuntime.$OS_TYPE-$os" + CUSTOM_SIMULATOR="$(instruments -s devices | grep -m 1 'custom-device' | awk -F'[][]' '{print $2}')" +else + echo ".devices.\"com.apple.CoreSimulator.SimRuntime.${PLATFORM/ Simulator/}-${OS/./-}\"" > /tmp/jq_file + CUSTOM_SIMULATOR=$( xcrun simctl list --json devices | jq -f /tmp/jq_file | jq -r '.[] | select(.name==env.NAME) | .udid' ) +fi +xcrun simctl boot $CUSTOM_SIMULATOR && sleep 30 +xcrun simctl list | grep Booted diff --git a/Scripts/run_prep.sh b/Scripts/run_prep.sh index 7209e9ca..f387d54a 100755 --- a/Scripts/run_prep.sh +++ b/Scripts/run_prep.sh @@ -1,19 +1,16 @@ -#!/usr/bin/env bash -set -e +#!/bin/bash -e -# Because `hub` is used, this script expects the following environment variables defined in travis job settings: +# Because `hub` is used, this script expects the following environment variables: # GITHUB_TOKEN - github api token with repo permissions (display value in build log setting: OFF) # GITHUB_USER - github username that GITHUB_TOKEN is associated with (display value in build log setting: ON) # Additionally, it needs the following environment variables: -# VERSION - defined in .travis.yml - -# Variables starting with TRAVIS_ are default environment variables available to all Travis CI builds +# VERSION - defined in swift.yml COLOR_RESET='\033[0m' COLOR_MAGENTA='\033[0;35m' COLOR_CYAN='\033[0;36m' -MYREPO=${HOME}/workdir/${TRAVIS_REPO_SLUG} +MYREPO=${HOME}/workdir/${REPO_SLUG} AUTOBRANCH=${GITHUB_USER}/prepareRelease${VERSION} BUILD_OUTPUT=/tmp/build.out touch $BUILD_OUTPUT @@ -21,7 +18,7 @@ touch $BUILD_OUTPUT function prep_workspace { rm -rf ${MYREPO} mkdir -p ${MYREPO} - git clone -b ${TRAVIS_BRANCH} https://${GITHUB_TOKEN}@github.com/${TRAVIS_REPO_SLUG} ${MYREPO} + git clone -b ${BRANCH} https://${GITHUB_TOKEN}@github.com/${REPO_SLUG} ${MYREPO} cd ${MYREPO} git checkout -b ${AUTOBRANCH} } @@ -38,7 +35,6 @@ function error_handler() { } function do_stuff { - # keepalive for Travis while :; do sleep 10; echo -n .; done & trap "kill $!" EXIT trap 'error_handler' ERR @@ -64,7 +60,7 @@ function push_changes { git config user.name "${GITHUB_USER}" git add --all # this is like a try/catch - git commit -m "ci(travis): auto release prep for $VERSION" || + git commit -m "ci(git-action): auto release prep for $VERSION" || { case $? in 1 ) @@ -77,10 +73,10 @@ function push_changes { ;; esac } - git push https://${GITHUB_TOKEN}@github.com/${TRAVIS_REPO_SLUG} ${AUTOBRANCH} - PR_URL=$(hub pull-request --no-edit -b ${TRAVIS_BRANCH}) + git push https://${GITHUB_TOKEN}@github.com/${REPO_SLUG} ${AUTOBRANCH} + PR_URL=$(hub pull-request --no-edit -b ${BRANCH}) echo -e "${COLOR_CYAN}ATTENTION:${COLOR_RESET} review and merge ${COLOR_CYAN}${PR_URL}${COLOR_RESET}" - echo "then to release to cocoapods use Travis CI's Trigger build with the following payload:" + echo "then to release to cocoapods use Git action's Trigger build with the following payload:" echo -e "${COLOR_MAGENTA}env:${COLOR_RESET}" echo -e "${COLOR_MAGENTA} - RELEASE=true${COLOR_RESET}" } diff --git a/Scripts/run_release.sh b/Scripts/run_release.sh index c10724b6..a62bc9b6 100755 --- a/Scripts/run_release.sh +++ b/Scripts/run_release.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -e -# Because `hub` is used, this script expects the following environment variables defined in travis job settings: +# Because `hub` is used, this script expects the following environment variables: # GITHUB_TOKEN - github api token with repo permissions (display value in build log setting: OFF) # GITHUB_USER - github username that GITHUB_TOKEN is associated with (display value in build log setting: ON) @@ -22,7 +22,7 @@ function release_github { DESCRIPTION=$(awk "/^${NEW_VERSION}$/,/^${LAST_VERSION:-nothingmatched}$/" ${CHANGELOG} | grep -v "^${LAST_VERSION:-nothingmatched}$") - hub release create v${VERSION} -m "Release ${VERSION}" -m "${DESCRIPTION}" -t "${TRAVIS_BRANCH}" + hub release create v${VERSION} -m "Release ${VERSION}" -m "${DESCRIPTION}" -t "${BRANCH}" } diff --git a/Scripts/run_unit_tests.sh b/Scripts/run_unit_tests.sh index bea41425..4541b654 100755 --- a/Scripts/run_unit_tests.sh +++ b/Scripts/run_unit_tests.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -e # run xcode unit tests # @@ -7,7 +7,7 @@ # # unit tests for PR only -if [[ "$TRAVIS_BRANCH" == "master" ]] +if [[ "$BRANCH" == "master" ]] then xcodebuild test -derivedDataPath $COVERAGE_DIR -workspace OptimizelySwiftSDK.xcworkspace -scheme $SCHEME -configuration Release CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -sdk $TEST_SDK -destination "platform=$PLATFORM,OS=$OS,name=$NAME" ONLY_ACTIVE_ARCH=YES | tee buildoutput | xcpretty && test ${PIPESTATUS[0]} -eq 0 fi diff --git a/Scripts/start_simulator.sh b/Scripts/start_simulator.sh deleted file mode 100755 index 7cbc9bc0..00000000 --- a/Scripts/start_simulator.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash -set -eou pipefail - -# expects the following environment variables defined -# PLATFORM (eg. iOS Simulator) -# OS (eg. 12.0) -# NAME (eg. iPad Air) - -# prep jq arg because it doesnt allow parameter expansion within its single quotes -echo ".devices.\"com.apple.CoreSimulator.SimRuntime.${PLATFORM/ Simulator/}-${OS/./-}\"" > /tmp/jq_file - -simulator=$( xcrun simctl list --json devices | jq -f /tmp/jq_file | jq -r '.[] | select(.name==env.NAME) | .udid' ) -if [ -z $simulator ]; then - echo "The requested simulator ($PLATFORM $OS $NAME) cannot be found." - #xcrun instruments -s device - xcrun xctrace list devices - sleep 3 - exit 1 -fi - -xcrun simctl boot $simulator && sleep 30 -xcrun simctl list | grep Booted diff --git a/Scripts/test_all.sh b/Scripts/test_all.sh index 36e12d96..75f7f589 100755 --- a/Scripts/test_all.sh +++ b/Scripts/test_all.sh @@ -1,13 +1,22 @@ -echo 'Testing OptimizelySwiftSDK-iOS (iPhone 8,OS=12.1)' -xcrun xcodebuild -workspace OptimizelySwiftSDK.xcworkspace -scheme OptimizelySwiftSDK-iOS -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 8,OS=12.1' test -echo 'Testing OptimizelySwiftSDK-iOS (iPhone SE,OS=11.1)' -xcrun xcodebuild -workspace OptimizelySwiftSDK.xcworkspace -scheme OptimizelySwiftSDK-iOS -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone SE,OS=11.1' test -echo 'Testing OptimizelySwiftSDK-iOS (iPhone XS,OS=13.2)' -xcrun xcodebuild -workspace OptimizelySwiftSDK.xcworkspace -scheme OptimizelySwiftSDK-iOS -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone XS,OS=13.2' test +#!/bin/bash -e +# Since github actions only provides limit simulators with each xcode, we need to link simulators from other versions of xcode to be used by current xcode. +# We must use old simulators with current xcode since older xcode versions do not support swift 5 which is required by Swift SDK. +# More about XCode and its compatible simulators can be found here: https://github.com/actions/virtual-environments/blob/main/images/macos/macos-10.15-Readme.md +# https://github.com/actions/virtual-environments/issues/551 -echo 'Testing OptimizelySwiftSDK-tvOS (Apple TV,OS=11.1)' -xcrun xcodebuild -workspace OptimizelySwiftSDK.xcworkspace -scheme OptimizelySwiftSDK-tvOS -sdk appletvsimulator -destination 'platform=tvOS Simulator,name=Apple TV,OS=11.1' test -echo 'Testing OptimizelySwiftSDK-tvOS (Apple TV,OS=12.1)' -xcrun xcodebuild -workspace OptimizelySwiftSDK.xcworkspace -scheme OptimizelySwiftSDK-tvOS -sdk appletvsimulator -destination 'platform=tvOS Simulator,name=Apple TV,OS=12.1' test -echo 'Testing OptimizelySwiftSDK-tvOS (Apple TV 4K,OS=13.2)' -xcrun xcodebuild -workspace OptimizelySwiftSDK.xcworkspace -scheme OptimizelySwiftSDK-tvOS -sdk appletvsimulator -destination 'platform=tvOS Simulator,name=Apple TV 4K,OS=13.2' test +deviceModels=("iPhone SE" "iPhone 8" "iPhone 11" "Apple TV" "Apple TV" "Apple TV 4K") +osVersions=("12.4" "13.3" "14.4" "12.4" "13.3" "14.3") +xcodeVersions=("10.3" "11.3.1" "12.4" "10.3" "11.3.1" "12.4") +platforms=("iOS" "iOS" "iOS" "tvOS" "tvOS" "tvOS") +testSdks=("iphonesimulator" "iphonesimulator" "iphonesimulator" "appletvsimulator" "appletvsimulator" "appletvsimulator") + +for i in "${!deviceModels[@]}"; do + export PLATFORM="${platforms[$i]} Simulator" + export OS="${osVersions[$i]}" + export NAME="${deviceModels[$i]}" + export OS_TYPE="${platforms[$i]}" + export SIMULATOR_XCODE_VERSION="${xcodeVersions[$i]}" + Scripts/prepare_simulator.sh + echo "Testing OptimizelySwiftSDK-${platforms[$i]} (${deviceModels[$i]},OS=${osVersions[$i]})" + xcrun xcodebuild -workspace OptimizelySwiftSDK.xcworkspace -scheme "OptimizelySwiftSDK-${platforms[$i]}" -sdk "${testSdks[$i]}" -destination "platform=${platforms[$i]} Simulator,name=${deviceModels[$i]},OS=${osVersions[$i]}" test +done diff --git a/Scripts/upload_coveralls.sh b/Scripts/upload_coveralls.sh deleted file mode 100755 index c74239c1..00000000 --- a/Scripts/upload_coveralls.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -# upload_coveralls.sh -# -# Usage: -# $ ./upload_coveralls.sh -# - -# [coveralls] -# - exclude coverage for Test codes by setting OptimizelySwiftSDK-iOS scheme > Test > Options > Gather coverage for selected targets -# - report coverage for PR and iPhone 11 only (avoid redundant ones) -# - use Xcode12.4+ (older Xcode reports a wrong number) -if [[ "$TRAVIS_BRANCH" == "master" && "$PLATFORM" == "iOS Simulator" && "$NAME" == "iPhone 11" ]] -then - mkdir xccov2lcov && cd xccov2lcov && git init && git fetch --depth=1 https://github.com/trax-retail/xccov2lcov.git && git checkout FETCH_HEAD - xcrun xccov view --report --json ../$COVERAGE_DIR/Logs/Test/*.xcresult > coverage.json - swift run xccov2lcov coverage.json > lcov.info - - cd .. - coveralls-lcov -v --repo-token $COVERALLS_TOKEN xccov2lcov/lcov.info -fi