diff --git a/.circleci/config.yml b/.circleci/config.yml index d8334f0b3..efca5acab 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 github-ci+cp@instabug.com - - 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)" diff --git a/scripts/snapshot-branch.sh b/scripts/snapshot-branch.sh deleted file mode 100755 index 652dd1bb9..000000000 --- a/scripts/snapshot-branch.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -pr_url="https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/pulls?head=$CIRCLE_PROJECT_USERNAME:$CIRCLE_BRANCH&state=open" -pr_response=$(curl --location --request GET "$pr_url" --header "Authorization: Bearer $RELEASE_GITHUB_TOKEN") - -if [ $(echo "$pr_response" | jq length) -eq 0 ]; then - echo "No PR found, proceeding with branch name instead" - - SNAPSHOT_BRANCH="snapshot/$CIRCLE_BRANCH" -else - pr_description=$(echo "$pr_response" | jq -r '.[].body') - - # The `sed "s/\r//g"` is used to remove the carriage return character \r from the end of the string - SNAPSHOT_BRANCH=$(echo -E "$pr_description" | grep 'Snapshot name:' | cut -d ':' -f 2 | xargs echo -n | sed "s/\r//g" || echo -n) - - if [ -z "$SNAPSHOT_BRANCH" ]; then - echo "No custom snapshot name found, proceeding with default snapshot naming convention" - - version=$(jq -r '.version' package.json) - jira_id=$(echo -E "$pr_description" | grep 'Jira ID:' | grep -Eo '[A-Z]+-[0-9]+' || echo -n) - - if [ -z "$jira_id" ]; then - echo "No Jira ID found, proceeding with branch name instead" - - SNAPSHOT_BRANCH="snapshot/$CIRCLE_BRANCH" - else - SNAPSHOT_BRANCH="snapshot/$version-$jira_id" - fi - fi -fi diff --git a/scripts/snapshot-comment.md b/scripts/snapshot-comment.md index 25ee16227..6acb6d726 100644 --- a/scripts/snapshot-comment.md +++ b/scripts/snapshot-comment.md @@ -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} ``` diff --git a/scripts/snapshot-version.sh b/scripts/snapshot-version.sh new file mode 100755 index 000000000..7ba0a0fd5 --- /dev/null +++ b/scripts/snapshot-version.sh @@ -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"