We store our configurations on the vault and during the Github action workflow we pull this and intend to use this for the app during build time.
This is our workflow
- name: Get app configs from vault
env:
ENVIRONMENT: development
run: |
chmod +x scripts/ci/get-app-configs.sh
scripts/ci/get-app-configs.sh
echo "action_state=yellow" >> $GITHUB_ENV
- name: Set .env to process.env of github actions
uses: cardinalby/export-env-action#v1
with:
envFile: '.env'
expand: 'true'
- name: Generate APK
env:
EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }}
run: |
echo "${{ env.action_state }}"
echo ${{ env.FIREBASE }}
eas build --platform android --local --profile development --non-interactive
The Get app configs from vault step creates an .env file with the following contents
FIREBASE={firebase_config_string}
And then inside firebase.ts we do this.
const firebaseConfig = JSON.parse(process.env.FIREBASE as string) as FirebaseOptions;
The app works fine when testing on an emulator but when testing the actual APK on a physical device, it always crashes. And in the logcat I keep seeing this error E AndroidRuntime: com.facebook.react.common.JavascriptException: SyntaxError: JSON Parse error: Unexpected identifier "undefined", stack:.
I've already narrowed it down to the firebase.ts process.env since the app doesn't crash when the config is hard coded.
I can see the env.FIREBASE as an env variable inside the Generate APK step so it's being passed to other steps fine. And the echo also prints out the value fine.
Is it not possible to access the env variables of Github action within the code during build time? Or are there other ways to achieve this?
Kept the github workflow as it is.
Fixed by using expo-constants.
Renaming the app.json to app.config.js to be able to add the following lines:
import 'dotenv/config';
export default {
expo: {
extra: {
ENV_VAR: process.env.ENV_VAR,
},
},
};
And access the said variable from the app by
import Constants from 'expo-constants';
const ENV_VAR = Constants.manifest?.extra?.ENV_VAR
Related
I have made github actions and written code for react native in .yml file
I need to pass security secret actions but I am not able to access Repository secrets appid and password and I need to pass that in action script but I m not able to access that
Created action script and getting error like:
What went wrong:
A problem occurred evaluating root project '***'.
Could not get unknown property 'application_id' for Credentials [username: null] of type org.gradle.internal.credentials.DefaultPasswordCredentials_Decorated.
can someone guide me right method to pass repository secrets
help will be much appreciated
I have already added secrets in actions secrets but unable to fetch in action script,
- run: |
cd project_name && yarn
cd android
./gradlew clean build
-PAPPLICATION_ID=$APPLICATION_ID // name from action secrets ID
-PPASSWORD=$PASSWORD // name from action secrets Password
an easy way to set secrets value as environment variables, you could simply do:
- name: build
env:
APPLICATION_ID: ${{ secrets. APPLICATION_ID }}
PASSWORD: ${{ secrets. PASSWORD }}
run: |
cd project_name && yarn
cd android
./gradlew clean build
-PAPPLICATION_ID=$APPLICATION_ID // name from action secrets ID
-PPASSWORD=$PASSWORD // name from action secrets Password
I'm trying to deploy my static site to Azure storage but have been having issues getting the site open correctly even though the github action executes without errors and the files seem to be in place. In the browser, index.html seems to load along with the css and js.... but the site does not run properly. The console shows a failure in the js:
The odd thing is that I don't have any issues using the azure storage extension in vscode or using the azure cli:
az storage blob upload-batch --account-name <ACCOUNT_NAME> -d '$web' -s ./dist --connection-string '<CONNECTION_STRING>'
when I deploy from my laptop.
My github action looks like this:
name: Blob storage website CI
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: npm install
run: |
npm install
- name: npm build
run: |
npm run build
- name: Azure Login
uses: azure/login#v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Azure CLI script
uses: azure/CLI#v1
with:
azcliversion: latest
inlineScript: |
az storage blob upload-batch --account-name <ACCOUNT_NAME> -d '$web' -s ./dist --connection-string '${{ secrets.BLOB_STORAGE_CONNECTION_STRING }}'
# Azure logout
- name: logout
run: |
az logout
based on this article here.
I thought that it might be due to the azure cli version, but none of the versions I've tried have made a difference.
Any ideas why my site broken using github action and azure cli to deploy?
For anyone interested - I was missing environment variables during the build process in the GitHub Action. I was able to pass these without checking in the .env files using github secrets.
There's now a step in the action to create a .env,
- name: Set Environment Variables
run: |
touch .env
echo ENVIRONMENT_VARIABLE=${{secrets.ENVIRONMENT_VARIABLE}} >> .env
and another to remove it:
- name: Remove Environment Variables
run: |
rm .env
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!
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/github-script#0.9.0
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 }}
I am trying to execute my packer build into a Gitlab pipeline, i didn't find examples on the internet but i have seen there is a docker image, so i was hoping this yaml would do the job:
image: hashicorp/packer
stages:
- build
build:
stage: build
script:
- echo "Hello world"
- packer build ./definition.json
only:
- master
But i don't understand the behavior, the CI pull the image, clone the repo, then it ends up like this:
Skipping Git submodules setup
Usage: packer [--version] [--help] <command> [<args>]
Available commands are:
build build image(s) from template
console creates a console for testing variable interpolation
fix fixes templates from old versions of packer
inspect see components of a template
validate check that a template is valid
version Prints the Packer version
Usage: packer [--version] [--help] <command> [<args>]
Available commands are:
build build image(s) from template
console creates a console for testing variable interpolation
fix fixes templates from old versions of packer
inspect see components of a template
validate check that a template is valid
version Prints the Packer version
ERROR: Job failed: exit code 127
It doesn't even print my echo Hello World, and it prints 2 times how i should iterract with the CLI, why this behavior?
I found how to fix it, i had to change:
image: hashicorp/packer
into:
image:
name: hashicorp/packer
entrypoint:
- '/usr/bin/env'
- 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
I can't seem to figure this out. Can someone please help me troubleshoot this? I'm using CodePush to upload my app and I want Sentry to handle my errors since the appcenter diagnostics are not very good.
I have this in a root component of my app...
if (process.env.NODE_ENV === 'production') {
Sentry.config('****',{
deactivateStacktraceMerging: false
}).install();
codePush.getUpdateMetadata().then((update) => {
if (update) {
Sentry.setVersion(update.appVersion + '-codepush:' + update.label);
}
});
}
And I have a deploy package script that will deploy to codepush and also run the sentry commands found in their docs
appcenter codepush release-react -a account/project --output-dir ./build && export SENTRY_PROPERTIES=./ios/sentry.properties && sentry-cli react-native appcenter account/project ios ./build/codePush
Everytime I get an error caught or one that I've captured I lack actual information on what file threw the error and I see the There was 1 error encountered while processing this event at the top which says Source code was not found for app:///main.jsbundle when I expand it.
I feel that this has to be something with sentry not properly connecting to codepush to get my source maps?
Finally got the sourcemap to work for both iOS and Android with AppCenter codepush after some trial and failure (since the Sentry doc is misleading), following these steps in bash script:
MY_APP_NAME="e.g. Sentry account/project"
MY_BUNDLE_ID="e.g. com.company.superapp"
MY_APP_ENV="e.g. development, staging or production"
NATIVE_VERSION="e.g. 1.2.3"
PLATFORM="e.g. ios or android"
# Build and release to appcenter
appcenter codepush release-react \
-a "$MY_APP_NAME" \
-d "$MY_APP_ENV" \
-m -t "$NATIVE_VERSION" \
--sourcemap-output \
--output-dir "./build/$PLATFORM"
export SENTRY_PROPERTIES="./$PLATFORM/sentry.properties"
# Get label and name of latest release
LABEL=$(appcenter codepush deployment history $MY_APP_ENV -a $MY_APP_NAME --output json | jq '.[-1][0]' -r)
RELEASE_NAME="$MY_BUNDLE_ID#$NATIVE_VERSION+codepush:$LABEL"
# Upload sourcemap
sentry-cli react-native appcenter \
"$MY_APP_NAME" "$PLATFORM" "./build/$PLATFORM/CodePush" \
--deployment "$MY_APP_ENV" \
--release-name "$RELEASE_NAME" \
--dist "$LABEL"
And doing this initialization in app.ts (or similar):
Sentry.init({...});
codePush.getUpdateMetadata().then(update => {
if (update) {
if (MY_APP_ENV === 'production')) {
Sentry.setRelease(
`${MY_BUNDLE_ID}#${update.appVersion}+codepush:${update.label}`,
);
} else {
Sentry.setRelease(
`${MY_BUNDLE_ID}.${MY_APP_ENV}#${update.appVersion}+codepush:${update.label}`,
);
}
Sentry.setDist(update.label);
}
});
Environment:
appcenter version: 2.7.3
#sentry/react-native: 2.5.1
You need to call Sentry.init with release and dist options and pass the same values as flags when you upload your sourcemaps via the CLI.
As per the Sentry Docs
If you want to use Sentry together with CodePush you will have to pass release and dist to Sentry.init. Our suggestion is to store them in an app.json, or you can just use the package.json. These values need to be unique to each version of your codebase and match the version on the source maps exactly, or they might not be symbolicated.
For example:
Sentry.init({
dsn: YOUR_DSN,
release: '1.0',
dist: 'v1',
});
And then when you want to upload your source maps:
export SENTRY_PROPERTIES=./ios/sentry.properties
sentry-cli react-native appcenter \
account/project \
ios ./build/codePush \
--release-name "1.0" \
--dist "v1"
Your release and dist can be arbitrary strings, but Sentry recommends the following format:
${BUNDLE_ID}#${APP_VERSION}+codepush:${DIST}
I've had the same issue - everything gets uploaded to Sentry and attached into a Release, but Issues show this warning.
Issue for me was that bundle ID was different in the app and in Sentry Release, syncing this solved the issue.