Skip to content

Commit

Permalink
feat: Add ci_checks for Frigg CI
Browse files Browse the repository at this point in the history
  • Loading branch information
relekang committed Jan 10, 2016
1 parent 8f5dd02 commit 577c374
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/automatic-releases/index.rst
Expand Up @@ -11,6 +11,14 @@ Environment checks
On publish, a few environment checks will run. Below are descriptions of what the different checks
do and under what condition they will run.

frigg
^^^^^
*Condition:* Environment variable ``FRIGG`` is ``'true'``

Checks for frigg to ensure that the build is not a pull-request and on the correct branch.
The branch check, checks against the branch that frigg said it checked out, not the current
branch.

semaphore
^^^^^^^^^
*Condition:* Environment variable ``SEMAPHORE`` is ``'true'``
Expand Down
14 changes: 14 additions & 0 deletions semantic_release/ci_checks.py
Expand Up @@ -48,6 +48,18 @@ def semaphore(branch):
assert os.environ.get('SEMAPHORE_THREAD_RESULT') != 'failed'


@checker
def frigg(branch):
"""
Performs necessary checks to ensure that the frigg build is one
that should create releases.
:param branch: The branch the environment should be running against.
"""
assert os.environ.get('FRIGG_BUILD_BRANCH') == branch
assert not os.environ.get('FRIGG_PULL_REQUEST')


def check(branch='master'):
"""
Detects the current CI environment, if any, and performs necessary
Expand All @@ -60,3 +72,5 @@ def check(branch='master'):
return travis(branch)
elif os.environ.get('SEMAPHORE') == 'true':
return semaphore(branch)
elif os.environ.get('FRIGG') == 'true':
return frigg(branch)
37 changes: 37 additions & 0 deletions tests/test_ci_checks.py
Expand Up @@ -18,6 +18,13 @@ def test_check_should_call_semaphore_with_correct_env_variable(mocker, monkeypat
mock_semaphore.assert_called_once_with('master')


def test_check_should_call_frigg_with_correct_env_variable(mocker, monkeypatch):
mock_frigg = mocker.patch('semantic_release.ci_checks.frigg')
monkeypatch.setenv('FRIGG', 'true')
ci_checks.check('master')
mock_frigg.assert_called_once_with('master')


def test_travis_should_pass_if_branch_is_master_and_no_pr(monkeypatch):
monkeypatch.setenv('TRAVIS_BRANCH', 'master')
monkeypatch.setenv('TRAVIS_PULL_REQUEST', 'false')
Expand Down Expand Up @@ -78,3 +85,33 @@ def test_semaphore_should_raise_ci_verification_error_if_pull_request_number_is_

with pytest.raises(CiVerificationError):
ci_checks.semaphore('master')


def test_frigg_should_pass_if_branch_is_master_and_no_pr(monkeypatch):
monkeypatch.setenv('FRIGG_BUILD_BRANCH', 'master')
monkeypatch.delenv('FRIGG_PULL_REQUEST', raising=False)

assert ci_checks.frigg('master')


def test_frigg_should_pass_if_branch_is_correct_and_no_pr(monkeypatch):
monkeypatch.setenv('FRIGG_BUILD_BRANCH', 'other-branch')
monkeypatch.delenv('FRIGG_PULL_REQUEST', raising=False)

assert ci_checks.frigg('other-branch')


def test_frigg_should_raise_ci_verification_error_for_wrong_branch(monkeypatch):
monkeypatch.setenv('FRIGG_BUILD_BRANCH', 'other-branch')
monkeypatch.delenv('FRIGG_PULL_REQUEST', raising=False)

with pytest.raises(CiVerificationError):
ci_checks.frigg('master')


def test_frigg_should_raise_ci_verification_error_for_pr(monkeypatch):
monkeypatch.setenv('FRIGG_BUILD_BRANCH', 'other-branch')
monkeypatch.setenv('FRIGG_PULL_REQUEST', '42')

with pytest.raises(CiVerificationError):
ci_checks.frigg('master')

0 comments on commit 577c374

Please sign in to comment.