Search code examples
react-nativebuildenvironment-variablesapkexpo

Using React-Native Expo in Github Actions without committing 'env' js file


I'm trying to achieve building an APK for each time there's a push to master. But I'm using an 'env' file and Expo needs it to build the APK (importing it in some places in the code). I don't wish to commit the 'env' file, and trying to avoid it.

Is there any workaround or do I have to commit the 'env' file?

Thanks!


Solution

  • SOLVED: I found a solution. I kept the entire file as a Github Secret and then added a script to create the env file from the secret.

    - name: Create env.js file
    uses: actions/[email protected]
    with:
      script: |
        const fs = require('fs');
        if (!fs.existsSync('env.js')) {
          fs.writeFileSync('env.js', process.env.ENV_FILE);
        }
    env:
      ENV_FILE: ${{ secrets.ENV_FILE }}