diff --git a/CHANGES.txt b/CHANGES.txt index ec143d8..3a512f0 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,7 @@ +## 1.0.3 - 2017-05-12 + +Made the creation of the tar archive on build an option with the --tar flag. + ## 1.0.2 - 2017-05-04 Enabled the URNs for the "commentary" type to be found in the metadata files and, thus, to show up in the inventory diff --git a/HookTest/build.py b/HookTest/build.py index e8e5d10..5e9895d 100644 --- a/HookTest/build.py +++ b/HookTest/build.py @@ -15,7 +15,7 @@ class Build(object): :type dest: str """ - def __init__(self, path, dest): + def __init__(self, path, dest, tar=False): if path.endswith('/'): self.path = path @@ -25,6 +25,7 @@ def __init__(self, path, dest): self.dest = dest else: self.dest = dest + '/' + self.tar = tar def repo_file_list(self): """ Build the list of XML files for the source repo represented by self.path @@ -86,10 +87,11 @@ def run(self): if len(passing) == 0: return False, 'The manifest file is empty.\nStopping build.' self.remove_failing(self.repo_file_list(), passing) - to_zip = [x for x in glob('{}*'.format(self.dest))] - with tarfile.open("{}release.tar.gz".format(self.dest), mode="w:gz") as f: - for file in sorted(to_zip): - f.add(file) + if self.tar is True: + to_zip = [x for x in glob('{}*'.format(self.dest))] + with tarfile.open("{}release.tar.gz".format(self.dest), mode="w:gz") as f: + for file in sorted(to_zip): + f.add(file) return True, 'Build successful.' @@ -102,7 +104,7 @@ def cmd(**kwargs): :rtype: """ if kwargs['travis'] is True: - status, message = Travis(path=kwargs['path'], dest=kwargs['dest']).run() + status, message = Travis(path=kwargs['path'], dest=kwargs['dest'], tar=kwargs['tar']).run() return status, message else: return False, 'You cannot run build on the base class' \ No newline at end of file diff --git a/HookTest/cmd.py b/HookTest/cmd.py index 02cbe59..55405f8 100644 --- a/HookTest/cmd.py +++ b/HookTest/cmd.py @@ -114,6 +114,7 @@ def parse_args_build(args): default='./' ) parser.add_argument("--travis", help="Run build on Travis or similar CI environment", action="store_true", default=False) + parser.add_argument("--tar", help="Build a tar archive of the passing files", action="store_true", default=False) args = parser.parse_args(args) return args diff --git a/README.rst b/README.rst index a0ee33c..64b9b92 100644 --- a/README.rst +++ b/README.rst @@ -121,7 +121,7 @@ Once you have done this, you will need to add a `.travis.yml` file to root folde - '3.5' install: - pip3 install HookTest - script: hooktest --scheme epidoc --workers 3 --verbose --manifest --console --countword --allowfailure ./ + script: hooktest ./ --console table --scheme epidoc --workers 3 --verbose 5 --manifest --countword --allowfailure ./ before_deploy: - hooktest-build --travis ./ - results=$(cat manifest.txt) @@ -129,15 +129,15 @@ Once you have done this, you will need to add a `.travis.yml` file to root folde - git config --global user.email "builds@travis-ci.com" - git config --global user.name "Travis CI" - export GIT_TAG=$major_version.$minor_version.$TRAVIS_BUILD_NUMBER + - git add -A + - git rm --cached =* - git tag $GIT_TAG -a -m "$DATE" -m "PASSING FILES" -m "$results" - git push -q https://$GITPERM@github.com/YOUR_REPOSITORY_NAME --tags - ls -R deploy: provider: releases - api_key: - secure: YOUR_SECURE_GITHUB_OATH_TOKEN - file: release.tar.gz + api_key: $GITPERM skip_cleanup: true on: repo: YOUR_REPOSITORY_NAME @@ -177,6 +177,8 @@ This line runs HookTest. The parameters are those described in the parameter tab - git config --global user.email "builds@travis-ci.com" - git config --global user.name "Travis CI" - export GIT_TAG=$major_version.$minor_version.$TRAVIS_BUILD_NUMBER + - git add -A + - git rm --cached =* - git tag $GIT_TAG -a -m "$DATE" -m "PASSING FILES" -m "$results" - git push -q https://$GITPERM@github.com/YOUR_REPOSITORY_NAME --tags - ls -R @@ -189,9 +191,7 @@ The second important change to this line is to replace the string "YOUR_REPOSITO deploy: provider: releases - api_key: - secure: YOUR_SECURE_GITHUB_OATH_TOKEN - file: release.tar.gz + api_key: $GITPERM skip_cleanup: true on: repo: YOUR_REPOSITORY_NAME @@ -202,7 +202,7 @@ The second important change to this line is to replace the string "YOUR_REPOSITO major_version: 0 minor_version: 0 -These lines define the deployment and release of your repository to Github. They will zip all of the passing files into the `release.tar.gz` file and then create a release on Github that has as its lable the major_version.minor_version.$TRAVIS_BUILD_NUMBER. You should set the major_version and minor_version environment variables to match the release status of your repository. Besides the major_version and minor_version environment variables, there are two other changes that you should make to these lines for each individual repository. The first is to replace the string "YOUR_SECURE_GITHUB_OATH_TOKEN" with an encrypted Github OAuth token that is produced by Travis for precisely this purpose. See the documentation at https://docs.travis-ci.com/user/deployment/releases/#Authenticating-with-an-Oauth-token to find out how to produce such an encrypted OAuth token. We suggest that you first remove the `deploy` section from your `.travis.yml` file, then use the `travis setup releases` command to produce a `deploy` section that is tailored to your repository, and then add the missing lines from the `deploy` code block above to finish the file off. +These lines define the deployment and release of your repository to Github. They will create a release on Github that has as its lable the major_version.minor_version.$TRAVIS_BUILD_NUMBER. You should set the major_version and minor_version environment variables to match the release status of your repository. Once you have created and tailored this `.travis.yml` file to your repository, you should then push it to your Github corpus repository. If you have set up Travis to test with repository, as described above, then Travis should read this `.travis.yml` file and automatically run HookTest and, if appropriate, build your first automatic release for the repository. diff --git a/setup.py b/setup.py index 77dd01b..0d0a87b 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( name='HookTest', - version="1.0.2", + version="1.0.3", description='Hook Test Script for GitHub/CapiTainS repositories', long_description=long_description, url='http://github.com/Capitains/HookTest', diff --git a/tests/test_build.py b/tests/test_build.py index 5a2168f..8d10e93 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -212,10 +212,17 @@ def test_remove_failing_all(self): def test_tar_contents(self): """ Compares the contents of the release.tar.gz file produced to the expected contents""" self.createTestDir('tests/100PercentRepo') - HookTest.build.Travis(path=self.TESTDIR, dest=self.TESTDIR).run() + HookTest.build.Travis(path=self.TESTDIR, dest=self.TESTDIR, tar=True).run() + self.assertTrue(os.path.isfile(self.TESTDIR + 'release.tar.gz')) with tarfile.open(self.TESTDIR + 'release.tar.gz', mode='r:gz') as f: self.assertCountEqual(f.getnames(), self.tar_contents) + def test_no_tar(self): + """ Tests to make sure no tar file for the repo is created if tar is False""" + self.createTestDir('tests/100PercentRepo') + HookTest.build.Travis(path=self.TESTDIR, dest=self.TESTDIR, tar=False).run() + self.assertFalse(os.path.isfile(self.TESTDIR + 'release.tar.gz')) + def test_base_class(self): """ Tests to make sure a build run on the base class returns and error""" self.createTestDir('tests/emptyDir')