Skip to content

Commit

Permalink
build(FEC-10700): Improvement for CI/CD (#73)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Yuvalke authored Jun 6, 2021
1 parent fcc12e7 commit 704a4d1
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 13 deletions.
21 changes: 13 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,30 @@ cache:
before_install:
- export DISPLAY=:99.0
- chmod +x ./scripts/travis.sh
- chmod +x ./scripts/after_deploy.sh

script: ./scripts/travis.sh

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
Expand All @@ -52,10 +64,6 @@ jobs:
on:
tags: true
branch: master
after_deploy:
- currentVersion=$(npx -c 'echo "$npm_package_version"')
- chmod +x ./scripts/after_deploy.sh
- ./scripts/after_deploy.sh "ima-dai" "$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\)/
Expand All @@ -70,10 +78,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 "ima-dai" "$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)
Expand Down
38 changes: 37 additions & 1 deletion scripts/after_deploy.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 9 additions & 4 deletions scripts/travis.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,21 +14,26 @@ 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
rm package.jsonE
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
Expand Down

0 comments on commit 704a4d1

Please sign in to comment.