Merge pull request #12 from rajdas98/master

(feat): Add functionality to validate version and upated the provided version
This commit is contained in:
Karthik Satchitanand
2019-09-26 13:51:38 +05:30
committed by GitHub
19 changed files with 153 additions and 16 deletions

8
.travis.yml Normal file
View File

@@ -0,0 +1,8 @@
sudo: required
dist: xenial # ubuntu 16.04 distro
script:
# runs only when PR is merged
- make versionmaker
after_success:
# runs only when PR is merged and push the version file to master version
- if [[ $TRAVIS_PULL_REQUEST == 'false' ]]; then make push; fi

12
Makefile Normal file
View File

@@ -0,0 +1,12 @@
# Makefile for building Chaos Exporter
# Reference Guide - https://www.gnu.org/software/make/manual/make.html
.PHONY: versionmaker
versionmaker:
@echo "-----version maker-----"
bash ./scripts/version_maker.sh
.PHONY: push
push:
@echo "---------git push to master-------"
bash ./scripts/push.sh

View File

@@ -20,7 +20,7 @@ spec:
keywords:
- Kubernetes
- Container
version: v0.1.0
version: 0.1.0
maturity: alpha
maintainers:
- name: ksatchit

View File

@@ -6,7 +6,7 @@ description:
kind: ChaosExperiment
metadata:
name: kubernetes-network-pod-nw-delay-v0.1.0
version: v0.1.0
version: 0.1.0
spec:
definition:
args:

View File

@@ -5,7 +5,7 @@ description:
kind: ChaosExperiment
metadata:
name: kubernetes-network-pod-nw-delay-v0.1.0
version: v0.1.0
version: 0.1.0
spec:
definition:
args:

View File

@@ -16,7 +16,7 @@ spec:
keywords:
- Kubernetes
- Network
version: v0.1.0
version: 0.1.0
maturity: alpha
maintainers:
- name: ksatchit

View File

@@ -4,7 +4,7 @@ description:
kind: ChaosExperiment
metadata:
name: kubernetes-state-container-kill-v0.1.0
version: v0.1.0
version: 0.1.0
spec:
definition:
args:

View File

@@ -6,7 +6,7 @@ description:
kind: ChaosExperiment
metadata:
name: kubernetes-state-pod-delete-v0.1.0
version: v0.1.0
version: 0.1.0
spec:
definition:
args:
@@ -35,7 +35,7 @@ description:
kind: ChaosExperiment
metadata:
name: kubernetes-state-container-kill-v0.1.0
version: v0.1.0
version: 0.1.0
spec:
definition:
args:

View File

@@ -5,7 +5,7 @@ description:
kind: ChaosExperiment
metadata:
name: kubernetes-state-pod-delete-v0.1.0
version: v0.1.0
version: 0.1.0
spec:
definition:
args:

View File

@@ -17,7 +17,7 @@ spec:
keywords:
- Kubernetes
- State
version: v0.1.0
version: 0.1.0
maturity: alpha
maintainers:
- name: ksatchit

View File

@@ -6,7 +6,7 @@ description:
kind: ChaosExperiment
metadata:
name: kubernetes-state-pod-delete-v0.1.0
version: v0.1.0
version: 0.1.0
spec:
definition:
args:

View File

@@ -1,7 +1,7 @@
apiVersion: litmuchaos.io/v1alpha1
kind: ChartServiceVersion
metadata:
name: openebs-network-v0.1.0
name: openebs-network-v0.1.0
annotations:
categories: "OpenEBS"
vendor: "CNCF"
@@ -16,7 +16,7 @@ spec:
- Kubernetes
- Network
- OpenEBS
version: v0.1.0
version: 0.1.0
maturity: alpha
maintainers:
- name: ksatchit

View File

@@ -22,7 +22,7 @@ spec:
- OpenEBS
- CAS
- Storage
version: v0.1.0
version: 0.1.0
maturity: alpha
maintainers:
- name: ksatchit

View File

@@ -6,7 +6,7 @@ description:
kind: ChaosExperiment
metadata:
name: kubernetes-state-pod-delete-v0.1.0
version: v0.1.0
version: 0.1.0
spec:
definition:
args:

View File

@@ -5,7 +5,7 @@ description:
kind: ChaosExperiment
metadata:
name: kubernetes-state-pod-delete-v0.1.0
version: v0.1.0
version: 0.1.0
spec:
definition:
args:

View File

@@ -18,7 +18,7 @@ spec:
- Kubernetes
- State
- OpenEBS
version: v0.1.0
version: 0.1.0
maturity: alpha
maintainers:
- name: ksatchit

24
scripts/push.sh Normal file
View File

@@ -0,0 +1,24 @@
#!/bin/sh
setup_git() {
git config --global user.email "travis@travis-ci.org"
git config --global user.name "Travis CI"
git remote set-url origin https://${GITHUB_TOKEN}@github.com/litmuschaos/community-charts.git > /dev/null 2>&1
}
commit_updated_changes() {
git checkout master
git status
git add .
git commit --message " $TRAVIS_BUILD_NUMBER: version upgraded for chaos-charts"
git status
}
upload_files() {
git remote -v
git push origin master
}
setup_git
commit_website_files
upload_files

View File

@@ -0,0 +1,13 @@
import re
import sys
# semantic version regex
regex = "^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"
result = re.search(regex, sys.argv[1])
if result:
print("version validation successful")
sys.exit(0) # on success
else:
print("version validation failed")
sys.exit(1) #on failure

80
scripts/version_maker.sh Normal file
View File

@@ -0,0 +1,80 @@
#! /bin/bash
# parsing yaml file
function yaml() {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\):|\1|" \
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
}
}'
}
# find files ended with chartserviceversion.yaml
FIND_CMD=`find ./charts -type f -name "*basetemplate.yaml"`
# add all the files to an array called files
files=$(echo $FIND_CMD | tr " " "\n")
# looping from all the files
for file in $files
do
# get the latest version from the template file
eval $(yaml $file)
if [[ $? == 0 ]]; then
kind=$kind
# check if kind is chaosexperiment or ChartServiceVersion
if [[ $kind == "ChaosExperiment" ]]; then
newversion=$metadata_version
elif [[ $kind == "ChartServiceVersion" ]]; then
newversion=$spec_version
fi
echo $newversion
# if version is interger or float (semversion)
sudo python scripts/validate_version.py $newversion
if [[ $? == 0 ]]; then
temp=$(echo ${file::-18})
if [[ $kind == "ChartServiceVersion" ]]; then
# echo $temp
oldversionfile=$temp'.yaml'
echo $oldversionfile
eval $(yaml $oldversionfile)
echo $?
if [[ $? == 0 ]]; then
oldversion=$spec_version
echo $oldversion
`sed -i "s/$oldversion/$newversion/" $oldversionfile` &&
`sed -i "s/version:[[:space:]]*$newversion/version: {{ VERSION }}/" $file`
fi
elif [ $kind == "ChaosExperiment" ]; then
# echo $temp
oldversionfile=$temp'.version.yaml'
echo $oldversionfile
eval $(yaml $oldversionfile)
if [[ $? == 0 ]]; then
oldversion=$metadata_version
echo $oldversion
`sed -i "s/$oldversion/$newversion/" $oldversionfile`
`sed -i "s/version:[[:space:]]*$newversion/version: {{ VERSION }}/" $file`
fi
fi
fi
fi
done