Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(FEC-10700): Improvement for CI/CD #101

Merged
merged 2 commits into from
Jun 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 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,19 +64,10 @@ 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 "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
Expand All @@ -75,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 "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)
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