Skip to content

Commit

Permalink
build(FEC-10700): Improvement for CI/CD (#389)
Browse files Browse the repository at this point in the history
1. add the number of commits from the master.
2. releases from the no-master branch won’t be taken to beta/latest release.
3. curl request check failure.
4. don't stop the release after conventional-github-releaser failed. 
5. update dependencies before tests so they'll be included
  • Loading branch information
Yuvalke committed Jun 6, 2021
1 parent e7920f3 commit 8937aea
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 38 deletions.
58 changes: 22 additions & 36 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ cache:

before_install:
- export DISPLAY=:99.0
- chmod +x ./scripts/travis.sh
- chmod +x ./scripts/after_deploy.sh

script:
- set -ev
- yarn install
script: bash ./scripts/travis.sh

stages:
- Tests
Expand All @@ -31,50 +31,36 @@ jobs:
fast_finish: true
include:
# https://docs.travis-ci.com/user/build-stages/deploy-github-releases/
# publish canary package if on master
- stage: Release
if: (tag IS present)
name: 'Release'
script:
- conventional-github-releaser -p angular -t $GH_TOKEN
- currentVersion=$(npx -c 'echo "$npm_package_version"')
- chmod +x ./scripts/after_deploy.sh
- ./scripts/after_deploy.sh "$currentVersion" "$JENKINS_TAG_TOKEN"
# https://docs.travis-ci.com/user/build-stages/deploy-github-releases/
env: TRAVIS_MODE=release
deploy:
- provider: script
on:
tags: true
all_branches: true
script: bash ./scripts/after_deploy.sh "$JENKINS_TAG_TOKEN"
# publish canary package if on master
- stage: Release canary
if: (branch = master) AND (type != pull_request) AND commit_message !~ /^chore\(release\)/ AND commit_message !~ /^(chore).*(update dist)$/
name: 'Release canary'
script:
- git checkout master
- echo "Run standard-version"
- sha=$(git rev-parse --verify --short HEAD)
- commitNumberAfterTag=$(git rev-list `git rev-list --tags --no-walk --max-count=1`..HEAD --count)
- yarn run release --prerelease canary-${commitNumberAfterTag}-${sha} --skip.commit=true --skip.tag=true
- yarn upgrade @playkit-js/playkit-js@canary
- yarn upgrade @playkit-js/playkit-js-dash@canary
- yarn upgrade @playkit-js/playkit-js-hls@canary
- yarn upgrade @playkit-js/playkit-js-ui@canary
- yarn upgrade playkit-js-providers@https://github.com/kaltura/playkit-js-providers.git#master
- yarn install
- yarn run build:ovp && yarn run build:ott && npm run commit:dist
- git push https://$GH_TOKEN@github.com/kaltura/kaltura-player-js "master" > /dev/null 2>&1
- currentVersion=$(npx -c 'echo "$npm_package_version"')
- chmod +x ./scripts/after_deploy.sh
- ./scripts/after_deploy.sh "${currentVersion}" "$JENKINS_CANARY_TOKEN"
env: TRAVIS_MODE=releaseCanary
deploy:
- provider: script
on:
all_branches: true
script: bash ./scripts/after_deploy.sh "$JENKINS_CANARY_TOKEN"
# Required tests
- stage: Tests
if: (branch = master) OR (tag IS present) OR (type = pull_request)
name: 'Running lint'
script:
- yarn run eslint
name: "Running lint"
env: TRAVIS_MODE=lint
- stage: Tests
if: (branch = master) OR (tag IS present) OR (type = pull_request)
name: 'Running Flow type check'
script:
- yarn run flow
name: "Running Flow type check"
env: TRAVIS_MODE=flow
- stage: Tests
if: (branch = master) OR (tag IS present) OR (type = pull_request)
name: 'Running unit tests'
script:
- yarn run test
name: "Running unit tests"
env: TRAVIS_MODE=unitTests
35 changes: 33 additions & 2 deletions scripts/after_deploy.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
#!/bin/bash
curl -k -d "{'version':$1}" -H "Content-Type: application/json" -X POST https://jenkins.ovp.kaltura.com/generic-webhook-trigger/invoke?token=$2
curl -k -d "{'version':$1}" -H "Content-Type: application/json" -X POST https://jenkins-central.prod.ovp.kaltura.com/generic-webhook-trigger/invoke?token=$2
set -x
curl ifconfig.me

#!/bin/bash
HTTP_SUCCESS=false

currentVersion=$(npx -c 'echo "$npm_package_version"')
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 "{'version':$currentVersion, '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
50 changes: 50 additions & 0 deletions scripts/travis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
# https://docs.travis-ci.com/user/customizing-the-build/#Implementing-Complex-Build-Steps
set -ev
yarn install

if [[ "$TRAVIS_BRANCH" = "master" ]] && [[ "$TRAVIS_EVENT_TYPE" != "pull_request" ]] && [[ ! "$TRAVIS_COMMIT_MESSAGE" =~ ^(chore).*(update dist)$ ]] && [[ ! "$TRAVIS_COMMIT_MESSAGE" =~ ^chore\(release\) ]]; then
echo "Prepare Canary"
yarn upgrade @playkit-js/playkit-js@canary
yarn upgrade @playkit-js/playkit-js-dash@canary
yarn upgrade @playkit-js/playkit-js-hls@canary
yarn upgrade @playkit-js/playkit-js-ui@canary
yarn upgrade playkit-js-providers@https://github.com/kaltura/playkit-js-providers.git#master
fi

if [ "${TRAVIS_MODE}" = "lint" ]; then
yarn run eslint
elif [ "${TRAVIS_MODE}" = "flow" ]; then
yarn run flow
elif [ "${TRAVIS_MODE}" = "unitTests" ]; then
yarn run test
elif [ "${TRAVIS_MODE}" = "release" ] || [ "${TRAVIS_MODE}" = "releaseCanary" ]; then
if [ "${TRAVIS_MODE}" = "releaseCanary" ]; then
echo "Run standard-version"
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.${commitNumberAfterTag}-${sha}/g")
echo "New version ${newVersion}"
sed -iE "s/$currentVersion/$newVersion/g" package.json
sed -iE "s/$currentVersion/$newVersion/g" CHANGELOG.md
rm package.jsonE
rm CHANGELOG.mdE
echo "Building..."
yarn run build:ovp && yarn run build:ott && npm run commit:dist
echo "Finish building"
git push https://$GH_TOKEN@github.com/kaltura/kaltura-player-js "master" > /dev/null 2>&1
echo "Push Build to origin"
else
echo "Run conventional-github-releaser"
#ignore error to make sure release won't get stuck
conventional-github-releaser -p angular -t $GH_TOKEN || true
fi
else
echo "Unknown travis mode: ${TRAVIS_MODE}" 1>&2
exit 1
fi

0 comments on commit 8937aea

Please sign in to comment.