Skip to content

Commit 8aade48

Browse files
a7medevahmedAlaaInstabug
authored andcommitted
ci: publish snapshots to npm (#1274)
1 parent e77c2c5 commit 8aade48

File tree

4 files changed

+24
-56
lines changed

4 files changed

+24
-56
lines changed

.circleci/config.yml

+11-24
Original file line numberDiff line numberDiff line change
@@ -469,35 +469,22 @@ jobs:
469469
- run: yarn build
470470
- run: yarn remove @instabug/danger-plugin-coverage
471471
- run:
472-
name: Remove build files from .gitignore
473-
command: sed -i '/dist/d' .gitignore && sed -i '/bin/d' .gitignore
474-
- run:
475-
name: Get snapshot branch name
476-
command: |
477-
source scripts/snapshot-branch.sh
478-
echo "export SNAPSHOT_BRANCH=$SNAPSHOT_BRANCH" >> "$BASH_ENV"
479-
- run:
480-
name: Setup Git
481-
command: |
482-
git config --global user.name "Instabug-CP-CI"
483-
git config --global user.email [email protected]
484-
- run:
485-
name: Create snapshot branch
486-
command: git checkout -b $SNAPSHOT_BRANCH
487-
- run:
488-
name: Commit changes
472+
name: Get snapshot version
489473
command: |
490-
git add .
491-
git commit -m "chore: add generate files"
474+
source scripts/snapshot-version.sh
475+
echo "export SNAPSHOT_VERSION=$SNAPSHOT_VERSION" >> "$BASH_ENV"
492476
- run:
493-
name: Push snapshot
494-
command: git push --force origin $SNAPSHOT_BRANCH
477+
name: Authorize with NPM
478+
command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
479+
- run: npm version $SNAPSHOT_VERSION --no-git-tag-version
480+
- run: npm publish --tag snapshot
495481
- run:
496482
name: Install jq
497483
command: sudo apt-get update && sudo apt-get install -y jq
498-
- run:
499-
name: Replace snapshot branch in comment template
500-
command: sed -i "s|{BRANCH}|$SNAPSHOT_BRANCH|g" scripts/snapshot-comment.md
484+
- find_and_replace:
485+
files: scripts/snapshot-comment.md
486+
search: '{VERSION}'
487+
replace: $SNAPSHOT_VERSION
501488
- notify_github:
502489
data: "$(jq -Rcs '{ body: . }' scripts/snapshot-comment.md)"
503490

scripts/snapshot-branch.sh

-30
This file was deleted.

scripts/snapshot-comment.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ Your snapshot has been generated! :rocket:
55
You can install the snapshot through NPM:
66

77
```sh
8-
npm install https://github.com/Instabug/Instabug-React-Native\#{BRANCH}
8+
npm install instabug-reactnative@{VERSION}
99
```
1010

1111
or Yarn:
1212

1313
```sh
14-
yarn add https://github.com/Instabug/Instabug-React-Native\#{BRANCH}
14+
yarn add instabug-reactnative@{VERSION}
1515
```

scripts/snapshot-version.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
# Generates a snapshot version following the format {version}-{pr}{random-3-digit}-SNAPSHOT
4+
# Example: 13.3.0-502861-SNAPSHOT
5+
6+
pr=$(basename $CIRCLE_PULL_REQUEST)
7+
random=$(($RANDOM % 900 + 100))
8+
version=$(jq -r '.version' package.json)
9+
suffix="SNAPSHOT"
10+
11+
SNAPSHOT_VERSION="$version-$pr$random-$suffix"

0 commit comments

Comments
 (0)