committed by
Karthik Satchitanand
parent
de971bb1fa
commit
e74a8be549
@@ -1,8 +1,10 @@
|
||||
sudo: required
|
||||
dist: xenial # ubuntu 16.04 distro
|
||||
script:
|
||||
# runs only when PR is merged
|
||||
- make versionmaker
|
||||
# Install dependencies
|
||||
- make deps
|
||||
# It will ignore if travis ci committed, else works as it is.
|
||||
- author=`git log -1 --pretty=format:'%an'` && if [[ "$author" != "Travis CI" ]]; then make versionmaker; fi
|
||||
- make combineExpCR
|
||||
after_success:
|
||||
# runs only when PR is merged and push the version file to master version
|
||||
|
19
Makefile
19
Makefile
@@ -1,10 +1,23 @@
|
||||
# Makefile for building Chaos Exporter
|
||||
# Makefile for building Chaos charts
|
||||
# Reference Guide - https://www.gnu.org/software/make/manual/make.html
|
||||
|
||||
.PHONY: deps
|
||||
deps:
|
||||
@echo "-----Install dependencies-----"
|
||||
sudo apt-get update
|
||||
sudo apt-get install python3
|
||||
sudo apt-get install python3-pip -y
|
||||
pip3 install packaging
|
||||
|
||||
.PHONY: versionmaker
|
||||
versionmaker:
|
||||
@echo "-----version maker-----"
|
||||
bash ./scripts/version_maker.sh
|
||||
bash ./scripts/version/version_maker.sh
|
||||
|
||||
.PHONY: combineExpCR
|
||||
combineExpCR:
|
||||
@echo "--------Combining Experiments CR-------"
|
||||
bash ./scripts/combine_all_cr.sh
|
||||
|
||||
.PHONY: combineExpCR
|
||||
combineExpCR:
|
||||
@@ -14,4 +27,4 @@ combineExpCR:
|
||||
.PHONY: push
|
||||
push:
|
||||
@echo "---------git push to master-------"
|
||||
bash ./scripts/push.sh
|
||||
bash ./scripts/version/push.sh
|
||||
|
@@ -5,8 +5,8 @@ description:
|
||||
Deletes a pod belonging to a deployment/statefulset/daemonset
|
||||
kind: ChaosExperiment
|
||||
metadata:
|
||||
name: kubernetes-state-pod-delete-v0.1.0
|
||||
version: v0.1.0
|
||||
name: kubernetes-state-pod-delete-0.1.0
|
||||
version: 0.1.0
|
||||
spec:
|
||||
definition:
|
||||
args:
|
||||
|
@@ -1,3 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "test the chart service version file for sanity.."
|
@@ -16,4 +16,3 @@ echo "validating combine charts for generic"
|
||||
cat ./charts/generic/experiments.yaml
|
||||
echo "validating combine charts for openebs"
|
||||
cat ./charts/openebs/experiments.yaml
|
||||
|
||||
|
@@ -1,13 +0,0 @@
|
||||
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
|
@@ -1,5 +1,4 @@
|
||||
#!/bin/sh
|
||||
|
||||
setup_git() {
|
||||
git config --global user.email "travis@travis-ci.org"
|
||||
git config --global user.name "Travis CI"
|
||||
@@ -20,5 +19,5 @@ upload_files() {
|
||||
}
|
||||
|
||||
setup_git
|
||||
commit_website_files
|
||||
commit_updated_changes
|
||||
upload_files
|
11
scripts/version/readme.md
Normal file
11
scripts/version/readme.md
Normal file
@@ -0,0 +1,11 @@
|
||||
## Version
|
||||
|
||||
## Implementation
|
||||
Whenever there is any commit in charts it will increment the patch version by one unit
|
||||
|
||||
Steps:
|
||||
1. version_maker.sh will take the second last commit because the latest commit is the changes which are done by the user by which Travis is triggered.
|
||||
|
||||
2. It compares the changes with the second last commit and stores the changed file to an array.
|
||||
|
||||
3. It will go through each file and increment a patch version to each changed file
|
78
scripts/version/version_maker.sh
Normal file
78
scripts/version/version_maker.sh
Normal file
@@ -0,0 +1,78 @@
|
||||
#! /bin/sh
|
||||
|
||||
# Retrive the last pushed commit from the repo
|
||||
second_last_commit_hash=`git log -n 2 --pretty=format:"%H" | tail -1`
|
||||
echo "Second Last commit hash: $second_last_commit_hash"
|
||||
|
||||
# # This function is used to parse the yaml file.
|
||||
function yaml_parser() {
|
||||
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);
|
||||
}
|
||||
}'
|
||||
}
|
||||
|
||||
# This function takes the old version from the last commit
|
||||
# and increments the existing version by one unit.
|
||||
versionInc(){
|
||||
echo "version inc"
|
||||
file=$1
|
||||
|
||||
eval $(yaml_parser $file)
|
||||
if [[ $? == 0 ]]
|
||||
then
|
||||
existing_version=$metadata_version
|
||||
echo "Existing version: $existing_version"
|
||||
|
||||
# stores the last pushed committed file as temp.yaml in the root directory
|
||||
# and will be deleted after the job
|
||||
temp_file=`git show $second_last_commit_hash:$1 >> temp.yaml`
|
||||
|
||||
eval $(yaml_parser './temp.yaml')
|
||||
if [[ $? == 0 ]]
|
||||
then
|
||||
oldversion=$metadata_version
|
||||
echo "Oldversion : $oldversion"
|
||||
sudo python3 scripts/version/version_validator.py $existing_version $oldversion
|
||||
ret_code=$?
|
||||
|
||||
if [[ $ret_code == 0 ]]; then
|
||||
echo "$file's version updated from $oldversion to $existing_version"
|
||||
elif [[ $ret_code == 2 ]]; then
|
||||
# storing version to an array
|
||||
versions=( ${oldversion//./ } )
|
||||
((versions[2]++)) # Increment the patch version by one unit
|
||||
newversion="${versions[0]}.${versions[1]}.${versions[2]}"
|
||||
|
||||
`sed -i "s/$existing_version/$newversion/" $file`
|
||||
echo "$file's version updated from $oldversion to $existing_version"
|
||||
fi
|
||||
fi
|
||||
# deleting the temporary file
|
||||
rm './temp.yaml'
|
||||
fi
|
||||
}
|
||||
|
||||
# compare and retrive the changed files
|
||||
check_diff=`git diff ${second_last_commit_hash} --name-only`
|
||||
files=$(echo $check_diff | tr " " "\n")
|
||||
|
||||
for file in $files
|
||||
do
|
||||
echo $file
|
||||
# For chart service version or experiment
|
||||
if [[ "$file" =~ \version.yaml$ ]] || [[ "$file" =~ \experiment.yaml$ ]]; then
|
||||
versionInc $file
|
||||
fi
|
||||
done
|
||||
|
22
scripts/version/version_validator.py
Normal file
22
scripts/version/version_validator.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import re
|
||||
import sys
|
||||
from packaging import version
|
||||
# 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-]+)*))?$"
|
||||
existing_version = sys.argv[1]
|
||||
old_version = sys.argv[2]
|
||||
result = re.search(regex, existing_version)
|
||||
|
||||
if result:
|
||||
if version.parse(existing_version) > version.parse(old_version):
|
||||
print("version validation successful")
|
||||
sys.exit(0) # on success
|
||||
elif version.parse(existing_version) == version.parse(old_version):
|
||||
print("versions are equal")
|
||||
sys.exit(2) # on success
|
||||
else:
|
||||
print("version validation failed")
|
||||
sys.exit(1) #on failure
|
||||
else:
|
||||
print("version validation failed")
|
||||
sys.exit(1) #on failure
|
@@ -1,80 +0,0 @@
|
||||
#! /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
|
Reference in New Issue
Block a user