Skip to content

Commit cf134cf

Browse files
authored
Merge pull request #1187 from Instabug/ci/fix-injazat-release
2 parents 70e349c + 968df53 commit cf134cf

File tree

3 files changed

+112
-72
lines changed

3 files changed

+112
-72
lines changed

.circleci/config.yml

Lines changed: 63 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,20 @@ commands:
5050
key: v1-pods-{{ checksum "<< parameters.working_directory >>/Podfile.lock" }}
5151
paths:
5252
- << parameters.working_directory >>/Pods
53-
search_and_replace:
53+
find_and_replace:
5454
parameters:
55-
file:
55+
files:
56+
description: A space-separated list of files to search and replace in.
5657
type: string
57-
replace-pattern:
58+
search:
59+
type: string
60+
replace:
5861
type: string
5962
steps:
6063
- run:
61-
name: Search and Replace in << parameters.file >>
62-
command: sed -i '<< parameters.replace-pattern >>' << parameters.file >>
64+
name: Find and Replace in << parameters.files >>
65+
command: node ~/project/scripts/replace.js << parameters.search >> << parameters.replace >> << parameters.files >>
66+
6367
notify_github:
6468
parameters:
6569
data:
@@ -258,37 +262,14 @@ jobs:
258262
working_directory: examples/default
259263
command: detox test -c android.emu.release
260264

261-
# Automate the enterprise NN sdk changes
262-
release_nn:
263-
working_directory: ~/project
264-
executor:
265-
name: node/default
266-
steps:
267-
- advanced-checkout/shallow-checkout
268-
- install_node_modules
269-
- run:
270-
name: Remove README.md file
271-
command: rm README.md
272-
- search_and_replace:
273-
file: package.json
274-
replace-pattern: 's/instabug-reactnative/@instabug\/react-native-nn/g'
275-
- search_and_replace:
276-
file: cli/UploadSourcemaps.ts
277-
replace-pattern: 's/api.instabug.com\/api\/sdk/st001009nn.instabug.com\/api\/sdk/g'
278-
- search_and_replace:
279-
file: android/native.gradle
280-
replace-pattern: 's/com\.instabug\.library:instabug:/com.instabug.library-nn:instabug:/g'
281-
- run:
282-
name: Build the SDK
283-
command: yarn build
284-
- run:
285-
name: Authorize with npm
286-
command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
287-
- run:
288-
name: Publish new enterprise version
289-
command: npm publish
290-
# Automate the enterprise injazat sdk changes
291-
release_injazat:
265+
release_custom_package:
266+
parameters:
267+
npm_package:
268+
type: string
269+
android_package:
270+
type: string
271+
api_endpoint:
272+
type: string
292273
working_directory: ~/project
293274
executor:
294275
name: node/default
@@ -298,24 +279,28 @@ jobs:
298279
- run:
299280
name: Remove README.md file
300281
command: rm README.md
301-
- search_and_replace:
302-
file: package.json
303-
replace-pattern: 's/instabug-reactnative/@instabug\/react-native-injazat/g'
304-
- search_and_replace:
305-
file: cli/UploadSourcemaps.ts
306-
replace-pattern: 's/api.instabug.com\/api\/sdk/st001013mec1.instabug.com\/api\/sdk/g'
307-
- search_and_replace:
308-
file: android/native.gradle
309-
replace-pattern: 's/com\.instabug\.library:instabug:/com.instabug.library-injazat:instabug:/g'
282+
- find_and_replace:
283+
files: package.json android/sourcemaps.gradle ios/sourcemaps.sh
284+
search: instabug-reactnative
285+
replace: << parameters.npm_package >>
286+
- find_and_replace:
287+
files: cli/UploadSourcemaps.ts cli/UploadSoFiles.ts
288+
search: api.instabug.com
289+
replace: << parameters.api_endpoint >>
290+
- find_and_replace:
291+
files: android/native.gradle
292+
search: 'com.instabug.library:instabug:'
293+
replace: 'com.instabug.library-<< parameters.android_package >>:instabug:'
310294
- run:
311295
name: Build the SDK
312296
command: yarn build
313297
- run:
314-
name: Authorize with npm
298+
name: Authorize with NPM
315299
command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
316300
- run:
317301
name: Publish new enterprise version
318302
command: npm publish
303+
319304
# Automate the enterprise D11 sdk changes
320305
release_d11:
321306
working_directory: ~/project
@@ -327,15 +312,18 @@ jobs:
327312
- run:
328313
name: Remove README.md file
329314
command: rm README.md
330-
- search_and_replace:
331-
file: package.json
332-
replace-pattern: 's/instabug-reactnative/@instabug\/instabug-reactnative-dream11/g'
333-
- search_and_replace:
334-
file: cli/UploadSourcemaps.ts
335-
replace-pattern: 's/api.instabug.com\/api\/sdk/st001012dream11.instabug.com\/api\/sdk/g'
336-
- search_and_replace:
337-
file: android/native.gradle
338-
replace-pattern: 's/com\.instabug\.library:instabug:/com.instabug.library-dream11:instabug:/g'
315+
- find_and_replace:
316+
files: package.json ios/sourcemaps.sh android/sourcemaps.gradle
317+
search: instabug-reactnative
318+
replace: '@instabug/instabug-reactnative-dream11'
319+
- find_and_replace:
320+
files: cli/UploadSourcemaps.ts cli/UploadSoFiles.ts
321+
search: api.instabug.com
322+
replace: st001012dream11.instabug.com
323+
- find_and_replace:
324+
files: android/native.gradle
325+
search: com.instabug.library:instabug
326+
replace: 'com.instabug.library-dream11:instabug:'
339327
- run:
340328
name: give exec permssion to d11 script
341329
command: chmod +x ./scripts/dream-11-delete-unused-features.sh
@@ -381,9 +369,10 @@ jobs:
381369
working_directory: '~'
382370
steps:
383371
- advanced-checkout/shallow-checkout
384-
- search_and_replace:
385-
file: package.json
386-
replace-pattern: 's/instabug-reactnative/@instabug\/react-native/g'
372+
- find_and_replace:
373+
files: package.json
374+
search: instabug-reactnative
375+
replace: '@instabug/react-native'
387376
- run: git clone [email protected]:Instabug/Escape.git
388377
- run:
389378
working_directory: Escape
@@ -469,15 +458,6 @@ workflows:
469458
filters:
470459
branches:
471460
only: master
472-
- hold_release_nn:
473-
requires: *release_dependencies
474-
type: approval
475-
filters:
476-
branches:
477-
only: master
478-
- hold_release_injazat:
479-
requires: *release_dependencies
480-
type: approval
481461
- hold_publish_new_namespace:
482462
requires: *release_dependencies
483463
type: approval
@@ -499,15 +479,26 @@ workflows:
499479
filters:
500480
branches:
501481
only: master
502-
- release_nn:
482+
- hold_release_nn:
483+
requires: *release_dependencies
484+
type: approval
485+
- release_custom_package:
486+
name: release_nn
503487
requires:
504488
- hold_release_nn
505-
filters:
506-
branches:
507-
only: master
508-
- release_injazat:
489+
npm_package: '@instabug/react-native-nn'
490+
android_package: nn
491+
api_endpoint: st001009nn.instabug.com
492+
- hold_release_injazat:
493+
requires: *release_dependencies
494+
type: approval
495+
- release_custom_package:
496+
name: release_injazat
509497
requires:
510498
- hold_release_injazat
499+
npm_package: '@instabug/react-native-injazat'
500+
android_package: injazat
501+
api_endpoint: st001013mec1.instabug.com
511502
- release_d11:
512503
requires:
513504
- hold_release_d11

.eslintrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ module.exports = {
1212
'jest/globals': true,
1313
},
1414
},
15+
{
16+
// Node Scripts Overrides
17+
files: ['scripts/**'],
18+
env: {
19+
node: true,
20+
},
21+
},
1522
{
1623
// Detox Overrides
1724
files: ['examples/default/e2e/**.js'],

scripts/replace.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* A script to replace all occurrences of a string in a file, this is built as a
3+
* replacement for the `sed` command to make it easier to replace strings with
4+
* special characters without the hassle of escaping them, this is important
5+
* when we are replacing strings that aren't known in advance like parameters
6+
* from files.
7+
*
8+
* Usage: node replace.js <search> <replace> <file>
9+
*/
10+
11+
const fs = require('fs');
12+
const path = require('path');
13+
14+
const [search, replace, ...files] = process.argv.slice(2);
15+
16+
if (!search || !replace || !files.length) {
17+
// The path of the script relative to the directory where the user ran the
18+
// script to be used in the error message demonstrating the usage.
19+
const scriptPath = path.relative(process.cwd(), __filename);
20+
21+
console.error('Missing arguments.');
22+
console.table({ search, replace, files });
23+
24+
console.error(`Usage: node ${scriptPath} <search> <replace> <files...>`);
25+
process.exit(1);
26+
}
27+
28+
for (const file of files) {
29+
try {
30+
const filePath = path.resolve(process.cwd(), file);
31+
32+
const fileContent = fs.readFileSync(filePath, 'utf8');
33+
34+
const newContent = fileContent.replaceAll(search, replace);
35+
36+
fs.writeFileSync(filePath, newContent);
37+
} catch (error) {
38+
console.error(`An error occurred while replacing the content of the file: ${file}.`);
39+
console.error(error);
40+
process.exit(1);
41+
}
42+
}

0 commit comments

Comments
 (0)