Skip to content

Commit

Permalink
Merge f63e393 into d835b91
Browse files Browse the repository at this point in the history
  • Loading branch information
james-monkeyshines committed Sep 6, 2018
2 parents d835b91 + f63e393 commit 2761d7f
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 11 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,14 @@
# ensembl-datacheck
Code for checking Ensembl data
* [Framework details](framework.md)

## Using git hooks to synchronise the datacheck index
It's easy to get out of sync between datachecks and the index. There's a
test for this, so it would eventually get detected, but we can proactively
avoid the problem with a git hook that automatically updates the index.

To configure this, in your local repository do:
`ln -s ../../hooks/pre-commit.sh .git/hooks/pre-commit`

Then, whenever you commit, the index will be checked, and updated if
necessary. To skip the checking, use the `--no-verify` flag.
30 changes: 30 additions & 0 deletions hooks/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh
#
# Most commits in this repository will be adding or updating datachecks.
# It is important to keep the index in-sync with the datacheck metadata;
# this is simple to do, but easy to forget, so an ideal candidate for
# automation...

EXIT_STATUS=0

# Stash any changes that aren't part of this commit, otherwise
# the index would be synced with things we're not committing!
git stash -q --keep-index

echo "CHECKING INDEX..."
if !(perl t/index.t)
then
echo "UPDATING INDEX..."
if (perl scripts/create_index.pl)
then
git add lib/Bio/EnsEMBL/DataCheck/index.json
else
echo "COMMIT REJECTED: failed to update index."
echo "Force the commit with the --no-verify flag (not recommended)."
EXIT_STATUS=1
fi
fi

git stash pop -q

exit $EXIT_STATUS
11 changes: 0 additions & 11 deletions t/Manager.t
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,6 @@ subtest 'Default attributes', sub {
is_deeply($manager->datacheck_types, [], 'Default datacheck_types correct (empty list)');
};

subtest 'Datacheck index', sub {
my $manager = $module->new();
my $index_1 = $manager->read_index();

my $tmp_index_file = Path::Tiny->tempfile();
$manager = $module->new(index_file => "$tmp_index_file");
my $index_2 = $manager->write_index();

is_deeply($index_1, $index_2, 'Index file is up-to-date');
};

subtest 'TestChecks directory', sub {
my $manager = $module->new(
datacheck_dir => $datacheck_dir,
Expand Down
34 changes: 34 additions & 0 deletions t/index.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright [2018] EMBL-European Bioinformatics Institute
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

use strict;
use warnings;
use feature 'say';

use Bio::EnsEMBL::DataCheck::Manager;

use Path::Tiny;
use Test::More;

my $module = 'Bio::EnsEMBL::DataCheck::Manager';

my $manager = $module->new();
my $index_1 = $manager->read_index();
my $tmp_index_file = Path::Tiny->tempfile();
$manager = $module->new(index_file => "$tmp_index_file");
my $index_2 = $manager->write_index();

is_deeply($index_1, $index_2, 'Index file is up-to-date');

done_testing();

0 comments on commit 2761d7f

Please sign in to comment.