Skip to content

ci: publish snapshots to npm #1274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 11 additions & 24 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -469,35 +469,22 @@ jobs:
- run: yarn build
- run: yarn remove @instabug/danger-plugin-coverage
- run:
name: Remove build files from .gitignore
command: sed -i '/dist/d' .gitignore && sed -i '/bin/d' .gitignore
- run:
name: Get snapshot branch name
command: |
source scripts/snapshot-branch.sh
echo "export SNAPSHOT_BRANCH=$SNAPSHOT_BRANCH" >> "$BASH_ENV"
- run:
name: Setup Git
command: |
git config --global user.name "Instabug-CP-CI"
git config --global user.email [email protected]
- run:
name: Create snapshot branch
command: git checkout -b $SNAPSHOT_BRANCH
- run:
name: Commit changes
name: Get snapshot version
command: |
git add .
git commit -m "chore: add generate files"
source scripts/snapshot-version.sh
echo "export SNAPSHOT_VERSION=$SNAPSHOT_VERSION" >> "$BASH_ENV"
- run:
name: Push snapshot
command: git push --force origin $SNAPSHOT_BRANCH
name: Authorize with NPM
command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
- run: npm version $SNAPSHOT_VERSION --no-git-tag-version
- run: npm publish --tag snapshot
- run:
name: Install jq
command: sudo apt-get update && sudo apt-get install -y jq
- run:
name: Replace snapshot branch in comment template
command: sed -i "s|{BRANCH}|$SNAPSHOT_BRANCH|g" scripts/snapshot-comment.md
- find_and_replace:
files: scripts/snapshot-comment.md
search: '{VERSION}'
replace: $SNAPSHOT_VERSION
- notify_github:
data: "$(jq -Rcs '{ body: . }' scripts/snapshot-comment.md)"

Expand Down
30 changes: 0 additions & 30 deletions scripts/snapshot-branch.sh

This file was deleted.

4 changes: 2 additions & 2 deletions scripts/snapshot-comment.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ Your snapshot has been generated! :rocket:
You can install the snapshot through NPM:

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

or Yarn:

```sh
yarn add https://github.com/Instabug/Instabug-React-Native\#{BRANCH}
yarn add instabug-reactnative@{VERSION}
```
11 changes: 11 additions & 0 deletions scripts/snapshot-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# Generates a snapshot version following the format {version}-{pr}{random-3-digit}-SNAPSHOT
# Example: 13.3.0-502861-SNAPSHOT

pr=$(basename $CIRCLE_PULL_REQUEST)
random=$(($RANDOM % 900 + 100))
version=$(jq -r '.version' package.json)
suffix="SNAPSHOT"

SNAPSHOT_VERSION="$version-$pr$random-$suffix"