DEV Community

Aashish Karki
Aashish Karki

Posted on

Building and uploading a non signed react-native apk to slack using github action

Building an apk takes huge amount of time and resource this can hog your local machine too much and make it a bit difficult to work on it. Also when working in react-native we can build a debug free apk without signing it, this comes in handy before rolling an authentic release. So to tackle the resource we use github action which uses a linux image to build our app for us and then send it to slack channel. For that add a devDependency @slack/bolt, and we move forward.

Github Action:

name: Push to slack channel
     - master
    name: Push to slack
    runs-on: ubuntu-latest
      - uses: actions/checkout@v2
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
          node-version: '14.x.x'
      - name: Build android apk and send to slack
        run: |
          yarn package:android
          cd android && ./gradlew wrapper --gradle-version 5.5 && ./gradlew assembleRelease -x bundleReleaseJsAndAssets
          cd ..
          yarn shipit:android
          SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}

Enter fullscreen mode Exit fullscreen mode

We use node 14 version as a package @slack/bolt (which will be used to send apk to slack) uses node version > 10.

In build step here yarn package:android is run which in returns packages react-native assets in android for us the corresponding script for this will be written in root package.json as :

"scripts": {
    "android": "react-native run-android",
    "test": "jest",
    "package:android": " react-native bundle --platform android --dev false --entry-file index.ts --bundle-output android/app/src/main/assets/ --assets-dest android/app/src/main/res",

Enter fullscreen mode Exit fullscreen mode

Currently the latest image of ubuntu and even macos use gradle version 6 or higher, this might be an issue for us as most of react native app 0.63.* version are mostly based on gradle 5, this is an issue as using gradle 6 or higher doesn't resolve dependencies issue for us. So we use gradle-version 5.5 and then apk is built and placed inside android/app/build/outputs/apk/release/app-release.apk

so we send this to our slack channel, to do that we can create a simple bit with file write and channel join access after giving the bot access we need to grab token which we receive after creating access to bot and signing secrets which is available in general information screen. We set that in github environments and then, yarn shipit:android command to send the file to slack channel, the corresponding script for this will be written in root as:

"scripts": {
    "android": "react-native run-android",
    "package:android": ...,
    "build:android": "yarn && node ./shipit.js",
Enter fullscreen mode Exit fullscreen mode

Contents of shipit.js will be something as.

// Require the Bolt for JavaScript package (
const { App } = require("@slack/bolt");
// For Node.JS, you need to import the fs (file system) module
const { createReadStream } = require('fs');
const path = require('path');

const token = process.env.SLACK_TOKEN 
const slackBot = new App({
  signingSecret: process.env.SLACK_SIGNING_SECRET 

async function sendApk() {
  const fileName = path.resolve(__dirname, '..', 'android', 'app', 'build', 'outputs', 'apk', 'release','app-release.apk');

  try {
    // Call the files.upload method using the built-in WebClient
    const result =  await slackBot.client.files.upload({
      // The token you used to initialize your app is stored in the `context` object
      channels: '#general',
      initial_comment: "Here\'s new updated build :smile:",
      // Include your filename in a ReadStream here
      file: createReadStream(fileName)
    console.log('Sucessfully sent')
  catch (error) {
    console.error('oops: ', error);



Enter fullscreen mode Exit fullscreen mode

And in each trigger of our action apk is sent to slack, but be sure to mention bot to that channel first and is part of the channel

Top comments (2)

aashishshrestha5532 profile image
Ashish Shrestha

This one is cool brother.
Waiting for github action for testflight too

karkipy profile image
Aashish Karki

sure man, will be working on that sooner i am heading in that direction as well