|
| 1 | +#!/bin/bash |
| 2 | +# shellcheck source=/dev/null |
| 3 | + |
| 4 | +set -euo pipefail |
| 5 | + |
| 6 | +source "$(dirname "$0")"/includes/git_utils |
| 7 | +source "$(dirname "$0")"/includes/version_util |
| 8 | +source "$(dirname "$0")"/analyze |
| 9 | +source "$(dirname "$0")"/npm_deploy |
| 10 | +source "$(dirname "$0")"/npm_version_utils |
| 11 | + |
| 12 | + |
| 13 | +if is_master_branch && ! is_pull_request; then |
| 14 | + echo "On master branch and not a pull request." |
| 15 | + |
| 16 | + git fetch origin "${GITHUB_BRANCH}" |
| 17 | + echo "Fetched origin ${GITHUB_BRANCH}." |
| 18 | + |
| 19 | + CURRENT_VERSION=$(get_current_version) |
| 20 | + echo "Current version: $CURRENT_VERSION" |
| 21 | + |
| 22 | + set_npm_version_with_build_id "$BUILD_NUMBER" |
| 23 | + echo "Set yarn version with build ID: $BUILD_NUMBER." |
| 24 | + |
| 25 | + check_version_format "$PROJECT_VERSION" |
| 26 | + echo "Checked version format: $PROJECT_VERSION." |
| 27 | + |
| 28 | + echo "Installing yarn dependencies..." |
| 29 | + yarn install --immutable |
| 30 | + |
| 31 | + echo "Running tests..." |
| 32 | + yarn test |
| 33 | + |
| 34 | + echo "Running Sonar Scanner..." |
| 35 | + run_sonar_scanner \ |
| 36 | + -Dsonar.projectVersion="$CURRENT_VERSION" |
| 37 | + |
| 38 | + echo "Building project..." |
| 39 | + yarn build |
| 40 | + |
| 41 | + echo "Publishing to JFrog..." |
| 42 | + jfrog_npm_publish "$@" |
| 43 | + |
| 44 | +elif is_maintenance_branch && not_pull_request; then |
| 45 | + git fetch origin "${GITHUB_BRANCH}" |
| 46 | + |
| 47 | + CURRENT_VERSION=$(get_current_version) |
| 48 | + |
| 49 | + if [[ $CURRENT_VERSION =~ "-SNAPSHOT" ]]; then |
| 50 | + echo "======= Found SNAPSHOT version =======" |
| 51 | + # Do not deploy a SNAPSHOT version but the release version related to this build |
| 52 | + set_npm_version_with_build_id "$BUILD_NUMBER" |
| 53 | + check_version_format "$CURRENT_VERSION" |
| 54 | + else |
| 55 | + echo "======= Found RELEASE version =======" |
| 56 | + echo "======= Deploy $CURRENT_VERSION =======" |
| 57 | + check_version_format "$CURRENT_VERSION" |
| 58 | + fi |
| 59 | + |
| 60 | + yarn install --immutable |
| 61 | + yarn test |
| 62 | + run_sonar_scanner \ |
| 63 | + -Dsonar.branch.name="$GITHUB_BRANCH" |
| 64 | + |
| 65 | + yarn build |
| 66 | + jfrog_npm_publish "$@" |
| 67 | + |
| 68 | +elif is_pull_request; then |
| 69 | + # Do not deploy a SNAPSHOT version but the release version related to this build and PR |
| 70 | + set_npm_version_with_build_id "$BUILD_NUMBER" |
| 71 | + |
| 72 | + if [ "${DEPLOY_PULL_REQUEST:-}" == "true" ]; then |
| 73 | + echo '======= with deploy =======' |
| 74 | + |
| 75 | + check_version_format "$PROJECT_VERSION" |
| 76 | + |
| 77 | + yarn install --immutable |
| 78 | + |
| 79 | + yarn test |
| 80 | + run_sonar_scanner \ |
| 81 | + -Dsonar.analysis.prNumber="$PULL_REQUEST" |
| 82 | + |
| 83 | + yarn build |
| 84 | + jfrog_npm_publish "$@" |
| 85 | + |
| 86 | + else |
| 87 | + echo '======= no deploy =======' |
| 88 | + |
| 89 | + yarn install --immutable |
| 90 | + |
| 91 | + run_sonar_scanner \ |
| 92 | + -Dsonar.analysis.prNumber="$PULL_REQUEST" |
| 93 | + |
| 94 | + yarn build |
| 95 | + fi |
| 96 | + |
| 97 | +elif is_dogfood_branch && not_pull_request; then |
| 98 | + echo '======= Build dogfood branch =======' |
| 99 | + |
| 100 | + CURRENT_VERSION=$(get_current_version) |
| 101 | + |
| 102 | + set_npm_version_with_build_id "$BUILD_NUMBER" |
| 103 | + check_version_format "$PROJECT_VERSION" |
| 104 | + |
| 105 | + yarn install --immutable |
| 106 | + yarn build |
| 107 | + jfrog_npm_publish "$@" |
| 108 | + |
| 109 | +elif is_long_lived_feature_branch && not_pull_request; then |
| 110 | + yarn install --immutable |
| 111 | + |
| 112 | + yarn test |
| 113 | + run_sonar_scanner \ |
| 114 | + -Dsonar.branch.name="$GITHUB_BRANCH" |
| 115 | + |
| 116 | + yarn build |
| 117 | + |
| 118 | +else |
| 119 | + yarn install --immutable |
| 120 | + yarn test |
| 121 | + yarn build |
| 122 | +fi |
0 commit comments