From 88f2d31855af67ed870840096af3e87951ba047b Mon Sep 17 00:00:00 2001 From: "yuval.keidar" Date: Thu, 3 Jun 2021 11:57:04 +0300 Subject: [PATCH 1/2] build(FEC-10700): Improvement for CI/CD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. add the number of commits from the master 2. handle two calls after deployment for each repo. 3. releases from the no-master branch won’t be taken to beta/latest release. 4. curl request check failure. 5. don't stop the release after conventional-github-releaser failed --- .travis.yml | 27 +++++++++++++-------------- scripts/after_deploy.sh | 38 +++++++++++++++++++++++++++++++++++++- scripts/travis.sh | 13 +++++++++---- 3 files changed, 59 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3aec2ecc..4a5cb781 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ cache: before_install: - export DISPLAY=:99.0 - chmod +x ./scripts/travis.sh + - chmod +x ./scripts/after_deploy.sh script: ./scripts/travis.sh @@ -25,11 +26,22 @@ stages: - Tests - Release canary - Release + - Deploy jobs: fast_finish: true include: # https://docs.travis-ci.com/user/build-stages/deploy-github-releases/ + - stage: Deploy + name: "Deploying a new version" + if: tag IS present + env: TRAVIS_MODE=deploy + deploy: + - provider: script + on: + tags: true + all_branches: true + script: bash ./scripts/after_deploy.sh "$JENKINS_TAG_TOKEN" - stage: Release name: 'Releasing a new version' if: tag IS present @@ -45,26 +57,16 @@ jobs: branch: master tags: true - provider: npm - edge: true api_key: $NPM_TOKEN email: $NPM_EMAIL skip_cleanup: true on: tags: true branch: master - after_deploy: - - currentVersion=$(npx -c 'echo "$npm_package_version"') - - chmod +x ./scripts/after_deploy.sh - - ./scripts/after_deploy.sh "kava" "$currentVersion" "$JENKINS_TAG_TOKEN" # publish canary package if on master - stage: Release canary if: (branch = master) AND (type != pull_request) AND commit_message !~ /^chore\(release\)/ env: TRAVIS_MODE=releaseCanary - before_script: - - yarn remove playkit-js-providers - - yarn add playkit-js-providers@https://github.com/kaltura/playkit-js-providers.git#master -P - - yarn add playkit-js-providers@https://github.com/kaltura/playkit-js-providers.git#master -D - - yarn install deploy: provider: npm api_key: $NPM_TOKEN @@ -75,10 +77,7 @@ jobs: tags: false branch: master after_deploy: - - currentVersion=$(npx -c 'echo "$npm_package_version"') - - echo $currentVersion - - chmod +x ./scripts/after_deploy.sh - - ./scripts/after_deploy.sh "kava" "$currentVersion" "$JENKINS_CANARY_TOKEN" + - ./scripts/after_deploy.sh "$JENKINS_CANARY_TOKEN" # Required tests - stage: Tests if: (branch = master) OR (tag IS present) OR (type = pull_request) diff --git a/scripts/after_deploy.sh b/scripts/after_deploy.sh index 7fd0b86c..33d2b150 100644 --- a/scripts/after_deploy.sh +++ b/scripts/after_deploy.sh @@ -1,2 +1,38 @@ #!/bin/bash -curl -k -d "{'name':$1, 'version':$2, 'source':'npm'}" -H "Content-Type: application/json" -X POST https://jenkins.ovp.kaltura.com/generic-webhook-trigger/invoke?token=$3 +set -x +curl ifconfig.me + +#!/bin/bash +REPO_PREFIX="@playkit-js/playkit-js-" +HTTP_SUCCESS=false + +currentVersion=$(npx -c 'echo "$npm_package_version"') +repoName=$(npx -c 'echo "$npm_package_name"') +packageName="playkit-${repoName#$REPO_PREFIX}" +echo "$packageName" +echo "$currentVersion" + +TAGGED_BRANCH=$(git ls-remote origin | sed -n "\|$TRAVIS_COMMIT\s\+refs/heads/|{s///p}") +UPDATE_SCHEMA=true +if [ "$TAGGED_BRANCH" != "master" ]; then + UPDATE_SCHEMA=false +fi + +for i in {1..3}; do + echo "Try number $i for pinging Jenkins...\n" + HTTP_CODE=$(curl -k -d "{'name': $packageName, 'version':$currentVersion, 'source':'npm', 'schema_type': 'playerV3Versions', 'update_schema': $UPDATE_SCHEMA}" -H "Content-Type: application/json" --silent --output /dev/stderr --write-out "%{http_code}" --fail -X POST https://jenkins-central.prod.ovp.kaltura.com/generic-webhook-trigger/invoke?token=$1) + STATUS_CODE=$? + echo "Request return with http code $HTTP_CODE and curl finished with status code $STATUS_CODE" + if [ "$HTTP_CODE" -eq 200 ] && [ "$STATUS_CODE" -eq 0 ]; then + HTTP_SUCCESS=true + break + fi +done + +echo "Jenkins ping success status - $HTTP_SUCCESS" + +if [ "$HTTP_SUCCESS" = true ]; then + exit 0 +else + exit 1 +fi diff --git a/scripts/travis.sh b/scripts/travis.sh index 7523d319..07c635de 100644 --- a/scripts/travis.sh +++ b/scripts/travis.sh @@ -1,8 +1,8 @@ #!/bin/sh # https://docs.travis-ci.com/user/customizing-the-build/#Implementing-Complex-Build-Steps set -ev - yarn install - if [ "${TRAVIS_MODE}" = "lint" ]; then +yarn install +if [ "${TRAVIS_MODE}" = "lint" ]; then yarn run eslint elif [ "${TRAVIS_MODE}" = "flow" ]; then yarn run flow @@ -14,9 +14,11 @@ elif [ "${TRAVIS_MODE}" = "release" ] || [ "${TRAVIS_MODE}" = "releaseCanary" ]; yarn run release --prerelease canary --skip.commit=true --skip.tag=true sha=$(git rev-parse --verify --short HEAD) echo "Current sha ${sha}" + commitNumberAfterTag=$(git rev-list `git rev-list --tags --no-walk --max-count=1`..HEAD --count) + echo "Number of commit from last tag ${commitNumberAfterTag}" currentVersion=$(npx -c 'echo "$npm_package_version"') echo "Current version ${currentVersion}" - newVersion=$(echo $currentVersion | sed -e "s/canary\.[[:digit:]]/canary.${sha}/g") + newVersion=$(echo $currentVersion | sed -e "s/canary\.[[:digit:]]/canary.${commitNumberAfterTag}-${sha}/g") echo "New version ${newVersion}" sed -iE "s/$currentVersion/$newVersion/g" package.json sed -iE "s/$currentVersion/$newVersion/g" CHANGELOG.md @@ -24,11 +26,14 @@ elif [ "${TRAVIS_MODE}" = "release" ] || [ "${TRAVIS_MODE}" = "releaseCanary" ]; rm CHANGELOG.mdE else echo "Run conventional-github-releaser" - conventional-github-releaser -p angular -t $GH_TOKEN + #ignore error to make sure release won't get stuck + conventional-github-releaser -p angular -t $GH_TOKEN || true fi echo "Building..." yarn run build echo "Finish building" +elif [ "${TRAVIS_MODE}" = "deploy" ]; then + echo "Deploy..." else echo "Unknown travis mode: ${TRAVIS_MODE}" 1>&2 exit 1 From 0fb4a7c2748bec3585a96144934172ccc62bf509 Mon Sep 17 00:00:00 2001 From: "yuval.keidar" Date: Sun, 6 Jun 2021 11:43:26 +0300 Subject: [PATCH 2/2] Update .travis.yml --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 4a5cb781..29f06889 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,6 +57,7 @@ jobs: branch: master tags: true - provider: npm + edge: true api_key: $NPM_TOKEN email: $NPM_EMAIL skip_cleanup: true