Skip to content

Commit

Permalink
Merge pull request #1187 from Instabug/ci/fix-injazat-release
Browse files Browse the repository at this point in the history
  • Loading branch information
mzelzoghbi authored Apr 19, 2024
2 parents 70e349c + 968df53 commit cf134cf
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 72 deletions.
135 changes: 63 additions & 72 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,20 @@ commands:
key: v1-pods-{{ checksum "<< parameters.working_directory >>/Podfile.lock" }}
paths:
- << parameters.working_directory >>/Pods
search_and_replace:
find_and_replace:
parameters:
file:
files:
description: A space-separated list of files to search and replace in.
type: string
replace-pattern:
search:
type: string
replace:
type: string
steps:
- run:
name: Search and Replace in << parameters.file >>
command: sed -i '<< parameters.replace-pattern >>' << parameters.file >>
name: Find and Replace in << parameters.files >>
command: node ~/project/scripts/replace.js << parameters.search >> << parameters.replace >> << parameters.files >>

notify_github:
parameters:
data:
Expand Down Expand Up @@ -258,37 +262,14 @@ jobs:
working_directory: examples/default
command: detox test -c android.emu.release

# Automate the enterprise NN sdk changes
release_nn:
working_directory: ~/project
executor:
name: node/default
steps:
- advanced-checkout/shallow-checkout
- install_node_modules
- run:
name: Remove README.md file
command: rm README.md
- search_and_replace:
file: package.json
replace-pattern: 's/instabug-reactnative/@instabug\/react-native-nn/g'
- search_and_replace:
file: cli/UploadSourcemaps.ts
replace-pattern: 's/api.instabug.com\/api\/sdk/st001009nn.instabug.com\/api\/sdk/g'
- search_and_replace:
file: android/native.gradle
replace-pattern: 's/com\.instabug\.library:instabug:/com.instabug.library-nn:instabug:/g'
- run:
name: Build the SDK
command: yarn build
- run:
name: Authorize with npm
command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
- run:
name: Publish new enterprise version
command: npm publish
# Automate the enterprise injazat sdk changes
release_injazat:
release_custom_package:
parameters:
npm_package:
type: string
android_package:
type: string
api_endpoint:
type: string
working_directory: ~/project
executor:
name: node/default
Expand All @@ -298,24 +279,28 @@ jobs:
- run:
name: Remove README.md file
command: rm README.md
- search_and_replace:
file: package.json
replace-pattern: 's/instabug-reactnative/@instabug\/react-native-injazat/g'
- search_and_replace:
file: cli/UploadSourcemaps.ts
replace-pattern: 's/api.instabug.com\/api\/sdk/st001013mec1.instabug.com\/api\/sdk/g'
- search_and_replace:
file: android/native.gradle
replace-pattern: 's/com\.instabug\.library:instabug:/com.instabug.library-injazat:instabug:/g'
- find_and_replace:
files: package.json android/sourcemaps.gradle ios/sourcemaps.sh
search: instabug-reactnative
replace: << parameters.npm_package >>
- find_and_replace:
files: cli/UploadSourcemaps.ts cli/UploadSoFiles.ts
search: api.instabug.com
replace: << parameters.api_endpoint >>
- find_and_replace:
files: android/native.gradle
search: 'com.instabug.library:instabug:'
replace: 'com.instabug.library-<< parameters.android_package >>:instabug:'
- run:
name: Build the SDK
command: yarn build
- run:
name: Authorize with npm
name: Authorize with NPM
command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
- run:
name: Publish new enterprise version
command: npm publish

# Automate the enterprise D11 sdk changes
release_d11:
working_directory: ~/project
Expand All @@ -327,15 +312,18 @@ jobs:
- run:
name: Remove README.md file
command: rm README.md
- search_and_replace:
file: package.json
replace-pattern: 's/instabug-reactnative/@instabug\/instabug-reactnative-dream11/g'
- search_and_replace:
file: cli/UploadSourcemaps.ts
replace-pattern: 's/api.instabug.com\/api\/sdk/st001012dream11.instabug.com\/api\/sdk/g'
- search_and_replace:
file: android/native.gradle
replace-pattern: 's/com\.instabug\.library:instabug:/com.instabug.library-dream11:instabug:/g'
- find_and_replace:
files: package.json ios/sourcemaps.sh android/sourcemaps.gradle
search: instabug-reactnative
replace: '@instabug/instabug-reactnative-dream11'
- find_and_replace:
files: cli/UploadSourcemaps.ts cli/UploadSoFiles.ts
search: api.instabug.com
replace: st001012dream11.instabug.com
- find_and_replace:
files: android/native.gradle
search: com.instabug.library:instabug
replace: 'com.instabug.library-dream11:instabug:'
- run:
name: give exec permssion to d11 script
command: chmod +x ./scripts/dream-11-delete-unused-features.sh
Expand Down Expand Up @@ -381,9 +369,10 @@ jobs:
working_directory: '~'
steps:
- advanced-checkout/shallow-checkout
- search_and_replace:
file: package.json
replace-pattern: 's/instabug-reactnative/@instabug\/react-native/g'
- find_and_replace:
files: package.json
search: instabug-reactnative
replace: '@instabug/react-native'
- run: git clone git@github.com:Instabug/Escape.git
- run:
working_directory: Escape
Expand Down Expand Up @@ -469,15 +458,6 @@ workflows:
filters:
branches:
only: master
- hold_release_nn:
requires: *release_dependencies
type: approval
filters:
branches:
only: master
- hold_release_injazat:
requires: *release_dependencies
type: approval
- hold_publish_new_namespace:
requires: *release_dependencies
type: approval
Expand All @@ -499,15 +479,26 @@ workflows:
filters:
branches:
only: master
- release_nn:
- hold_release_nn:
requires: *release_dependencies
type: approval
- release_custom_package:
name: release_nn
requires:
- hold_release_nn
filters:
branches:
only: master
- release_injazat:
npm_package: '@instabug/react-native-nn'
android_package: nn
api_endpoint: st001009nn.instabug.com
- hold_release_injazat:
requires: *release_dependencies
type: approval
- release_custom_package:
name: release_injazat
requires:
- hold_release_injazat
npm_package: '@instabug/react-native-injazat'
android_package: injazat
api_endpoint: st001013mec1.instabug.com
- release_d11:
requires:
- hold_release_d11
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ module.exports = {
'jest/globals': true,
},
},
{
// Node Scripts Overrides
files: ['scripts/**'],
env: {
node: true,
},
},
{
// Detox Overrides
files: ['examples/default/e2e/**.js'],
Expand Down
42 changes: 42 additions & 0 deletions scripts/replace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* A script to replace all occurrences of a string in a file, this is built as a
* replacement for the `sed` command to make it easier to replace strings with
* special characters without the hassle of escaping them, this is important
* when we are replacing strings that aren't known in advance like parameters
* from files.
*
* Usage: node replace.js <search> <replace> <file>
*/

const fs = require('fs');
const path = require('path');

const [search, replace, ...files] = process.argv.slice(2);

if (!search || !replace || !files.length) {
// The path of the script relative to the directory where the user ran the
// script to be used in the error message demonstrating the usage.
const scriptPath = path.relative(process.cwd(), __filename);

console.error('Missing arguments.');
console.table({ search, replace, files });

console.error(`Usage: node ${scriptPath} <search> <replace> <files...>`);
process.exit(1);
}

for (const file of files) {
try {
const filePath = path.resolve(process.cwd(), file);

const fileContent = fs.readFileSync(filePath, 'utf8');

const newContent = fileContent.replaceAll(search, replace);

fs.writeFileSync(filePath, newContent);
} catch (error) {
console.error(`An error occurred while replacing the content of the file: ${file}.`);
console.error(error);
process.exit(1);
}
}

0 comments on commit cf134cf

Please sign in to comment.