Merge pull request #3764 from rishwanth1995/setupsleuthkitbranch_ci

added python script to setup sleuthkit branch in appveyor and travis
This commit is contained in:
Brian Carrier 2018-05-11 11:22:42 -04:00 committed by GitHub
commit a0dba7a232
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 117 additions and 17 deletions

View File

@ -6,17 +6,20 @@ os:
env:
global:
- TSK_HOME=$TRAVIS_BUILD_DIR/sleuthkit/sleuthkit
python:
- "2.7"
jdk:
- oraclejdk8
before_install:
- git clone https://github.com/sleuthkit/sleuthkit.git sleuthkit/sleuthkit
- git clone https://github.com/sleuthkit/sleuthkit.git sleuthkit/sleuthkit
- python setupSleuthkitBranch.py
install:
- sudo apt-get install testdisk
- cd sleuthkit/sleuthkit
- cd sleuthkit/sleuthkit
- sh travis_build.sh
script:
- set -e
- echo "building autopsy..." && echo -en 'travis_fold:start:script.build\\r'
- echo "building autopsy..." && echo -en 'travis_fold:start:script.build\\r'
- cd $TRAVIS_BUILD_DIR/
- ant -q build
- echo -en 'travis_fold:end:script.build\\r'

View File

@ -1,21 +1,18 @@
version: 4.6.0.{build}
cache:
- C:\Users\appveyor\.ant -> appveyor.yml
- C:\Users\appveyor\.ivy2 -> appveyor.yml
- C:\ProgramData\chocolatey\bin -> appveyor.yml
- C:\ProgramData\chocolatey\lib -> appveyor.yml
- C:\Users\appveyor\.ant
- C:\ProgramData\chocolatey\bin
- C:\ProgramData\chocolatey\lib
- C:\libewf_64bit
- C:\libvhdi_64bit
- C:\libvmdk_64bit
- C:\zlib
- '%APPVEYOR_BUILD_FOLDER%\Core\test\qa-functional\data'
branches:
only:
- develop
image: Visual Studio 2015
platform: x64
init:
- ps: choco install ant --ignore-dependencies
- ps: $env:Path="C:\Program Files\Java\jdk1.8.0\bin;$($env:Path);C:\ProgramData\chocolatey\lib\ant"
- set PATH=C:\Python36-x64\';%PATH%
environment:
global:
TSK_HOME: "C:\\sleuthkit"
@ -27,10 +24,14 @@ environment:
PYTHON: "C:\\Python36-x64"
install:
- ps: pushd C:\
- ps: choco install ant --ignore-dependencies
- git clone https://github.com/sleuthkit/sleuthkit
- ps: popd
- ps: $env:Path="C:\Program Files\Java\jdk1.8.0\bin;$($env:Path);C:\ProgramData\chocolatey\lib\ant"
- set PATH=C:\Python36-x64\';%PATH%
- cd C:\
- git clone https://github.com/sleuthkit/sleuthkit
- cd %APPVEYOR_BUILD_FOLDER%
- python setupSleuthkitBranch.py
services:
- postgresql95

96
setupSleuthkitBranch.py Normal file
View File

@ -0,0 +1,96 @@
# This python script is used to automatically set the branch in The Sleuth Kit repository
# for use in automated build environments.
#
# Basic idea is that it determines what Autopsy branch is being used and then checksout
# a corresponding TSK branch.
#
# TSK_HOME environment variable must be set for this to work.
import os
import sys
import subprocess
import xml.etree.ElementTree as ET
TSK_HOME=os.getenv("TSK_HOME",False)
passed = 1
def getSleuthkitBranchList():
# Returns the list of sleuthkit branches
cmd = ['git','branch','-a']
retdir = os.getcwd()
os.chdir(TSK_HOME)
output = subprocess.check_output(cmd)
branches = []
for branch in output.strip().split():
if branch.startswith('remotes/origin'):
branches.append(branch.split('/')[2])
os.chdir(retdir)
return branches
def gitSleuthkitCheckout(branch):
'''
Checksout sleuthkit branch
Args:
branch: String, which branch to checkout
'''
# passed is a global variable that gets set to non-zero integer
# When an error occurs
global passed
cmd = ['git','checkout',branch]
passed = subprocess.call(cmd,stdout=sys.stdout,cwd=TSK_HOME)
def parseXML(xmlFile):
'''
parses the TSKVersion.xml file for sleuthkit version
Args:
xmlFile: String, xml file to parse
'''
tree = ET.parse(xmlFile)
root = tree.getroot()
for child in root:
if child.attrib['name']=='TSK_VERSION':
return child.attrib['value']
return None
def main():
global passed
if not TSK_HOME:
sys.exit(1)
print('Please set TSK_HOME env variable')
# Get the Autopsy branch being used. Travis and Appveyor
# will tell us where a pull request is directed
TRAVIS=os.getenv("TRAVIS",False)
APPVEYOR=os.getenv("APPVEYOR",False)
if TRAVIS == "true":
CURRENT_BRANCH=os.getenv("TRAVIS_BRANCH",False)
elif APPVEYOR:
CURRENT_BRANCH=os.getenv("APPVEYOR_REPO_BRANCH",False)
else:
cmd=['git','rev-parse','--abbrev-ref','HEAD']
output = subprocess.check_output(cmd)
CURRENT_BRANCH=output.strip()
# If we are in an Autopsy release branch, then use the
# info in TSKVersion.xml to find the corresponding TSK
# release branch. For other branches, we don't always
# trust that TSKVersion has been updated.
if CURRENT_BRANCH.startswith('release'):
version = parseXML('TSKVersion.xml')
RELEASE_BRANCH = "release-"+version
gitSleuthkitCheckout(RELEASE_BRANCH)
# Check if the same branch exists in TSK (develop->develop, custom1->custom1, etc.)
elif CURRENT_BRANCH in getSleuthkitBranchList():
gitSleuthkitCheckout(CURRENT_BRANCH)
# Otherwise, default to develop
if passed != 0:
gitSleuthkitCheckout('develop')
if passed != 0:
print('Error checking out a Sleuth Kit branch')
sys.exit(1)
if __name__ == '__main__':
main()