Skip to content

Instantly share code, notes, and snippets.

@rutvikbhatt9
Created February 11, 2019 05:53
Show Gist options
  • Save rutvikbhatt9/92c1b9887188bcff671807869e5045ca to your computer and use it in GitHub Desktop.
Save rutvikbhatt9/92c1b9887188bcff671807869e5045ca to your computer and use it in GitHub Desktop.
.gitlab.ci.yml file for React-Native
image: openjdk:8-jdk #Defining the Docker Image
variables:
ANDROID_COMPILE_SDK: "28" #set compile SDK version
ANDROID_BUILD_TOOLS: "28.0.2" #set build tool version
ANDROID_SDK_TOOLS: "4333796" #set SDK tool build number you can find yous here https://developer.android.com/studio/releases/sdk-tools
before_script:
# Fetch the specified SDK tools version to build with
- wget --quiet --output-document=/tmp/sdk-tools-linux.zip https://dl.google.com/android/repository/sdk-tools-linux-${ANDROID_SDK_TOOLS}.zip
- unzip /tmp/sdk-tools-linux.zip -d .android
# Set up environment variables
- export ANDROID_HOME=$PWD/.android
- export PATH=$PATH:$PWD/.android/platform-tools/
# Install platform tools and Android SDK for the compile target
- echo y | .android/tools/bin/sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}"
- curl -sL https://deb.nodesource.com/setup_10.x | bash #Add Node Repo
- apt-get install -y nodejs #Install NOde JS
- npm install -g react-native-cli #Install React-Native CLI
- npm install #Install npm packages
- react-native link #Link the resources
- chmod +x android/gradlew #Provide permission for execution
# Define stages
stages:
- build_release_android
build_release_android:
stage: build_release_android
script:
- mkdir /PlayJson #make temp directory named PlayJson in root of project
- "echo $PLAY_STORE_JSON > /PlayJson/play-store-key.json" # copy git variable value to play-store-key.json file
- npm run android-bundle # bundle the app (Execute from package.json's script block)
- npm run android-release #create release app (Execute from package.json's script block)
- cd android && ./gradlew publishApkRelease # navigate to android dir & publish app on play store
only:
- master #set trigger for CICD if push or merge in master branch
artifacts:
paths:
- ./android/app/build/outputs/ # set artifact path which store your APK file
@seyedasfar
Copy link

any update?

@Kos-M
Copy link

Kos-M commented May 27, 2021

Is this working now?

@khuongphp
Copy link

@usama-asfar @Kos-M still work but old version :D

@rutvikbhatt9
Copy link
Author

@usama-asfar @Kos-M @khuongphp Will update it soon

@seyedasfar
Copy link

seyedasfar commented Nov 29, 2021

@khuongphp I created my own action to build and release to google play store.

name: Build Production
on:
  release:
    types:
      - created
jobs:
  build-android:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - uses: c-hive/gha-yarn-cache@v2

      - name: Setup Node.js
        uses: actions/setup-node@v2
        with:
          node-version: 16

      - name: Install dependencies
        run: yarn install

      - name: Setup Environment Variables
        run: |
          touch .env;
          echo "ENVIRONMENT=${{ secrets.PRODUCTION_ENVIRONMENT }}" >> .env;
          echo "END_POINT=${{ secrets.PRODUCTION_END_POINT }}" >> .env;
          echo "AWS_KEY=${{ secrets.PRODUCTION_AWS_KEY }}" >> .env;
          echo "AWS_SECRET=${{ secrets.PRODUCTION_AWS_SECRET }}" >> .env;
          echo "AWS_REGION=${{ secrets.PRODUCTION_AWS_REGION }}" >> .env;
          echo "AWS_BUCKET=${{ secrets.PRODUCTION_AWS_BUCKET }}" >> .env;
          echo "MAPBOX_KEY=${{ secrets.PRODUCTION_MAPBOX_KEY }}" >> .env;
          echo "SENTRY_DSN=${{ secrets.PRODUCTION_SENTRY_DSN }}" >> .env;
      - name: Setup Firebase Config
        env:
          FIREBASE_CONFIG: ${{ secrets.PRODUCTION_FIREBASE_CONFIG }}
        run: |
          rm -rf ./android/app/google-services.json
          echo $FIREBASE_CONFIG > ./android/app/google-services.json
      - name: Rename Production
        run: yarn production:rename

      - name: Cache Gradle Wrapper
        uses: actions/cache@v2
        with:
          path: ~/.gradle/wrapper
          key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}

      - name: Cache Gradle Dependencies
        uses: actions/cache@v2
        with:
          path: ~/.gradle/caches
          key: ${{ runner.os }}-gradle-caches-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
          restore-keys: |
            ${{ runner.os }}-gradle-caches-
      - name: Make Gradlew Executable
        run: cd android && chmod +x ./gradlew

      - name: Build Android App Bundle
        run: |
          cd android && ./gradlew bundleRelease --no-daemon
      - name: Signing App Bundle
        id: sign_app
        uses: r0adkll/sign-android-release@v1
        with:
          releaseDirectory: android/app/build/outputs/bundle/release
          signingKeyBase64: ${{ secrets.KEYSTORE }}
          alias: ${{ secrets.KEYSTORE_PASS }}
          keyStorePassword: ${{ secrets.KEYSTORE_PASS }}
          keyPassword: ${{ secrets.KEYSTORE_PASS }}

      - name: Deploy to Play Store
        uses: r0adkll/upload-google-play@v1.0.15
        with:
          serviceAccountJsonPlainText: ${{secrets.GOOGLE_SERVICE_ACCOUNT}}
          packageName: com.myapp
          releaseFiles: ${{steps.sign_app.outputs.signedReleaseFile}}
          track: production
          whatsNewDirectory: ./release/notes

Semantic release action file

name: Release
on:
  push:
    branches:
      - master
jobs:
  semantic-release:
    name: Semantic Release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - uses: c-hive/gha-yarn-cache@v2

      - name: Setup Node.js
        uses: actions/setup-node@v2
        with:
          node-version: 16

      - name: Install dependencies
        run: yarn install

      - name: Release
        env:
          GITHUB_TOKEN: ${{ secrets.GH_PAT }}
        run: npx semantic-release

When a new release is created the production action will run.

@khuongphp
Copy link

@usama-asfar ooh I see.
I think you are working with jenkin or circle CI but not gitlab ci :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment