mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-28 09:40:07 +01:00
gitlab CI: add a local emulation mode to the gitlab CI script
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
902806c750
commit
9d996a0420
1 changed files with 33 additions and 6 deletions
|
|
@ -9,22 +9,44 @@ import git
|
|||
import os
|
||||
import pytest
|
||||
|
||||
# Environment variables set by gitlab
|
||||
CI_COMMIT_SHA = os.environ['CI_COMMIT_SHA']
|
||||
CI_MERGE_REQUEST_TARGET_BRANCH_NAME = 'master'
|
||||
CI_SERVER_HOST = os.environ['CI_SERVER_HOST']
|
||||
if os.environ.get('CI'):
|
||||
# Environment variables set by gitlab
|
||||
CI_COMMIT_SHA = os.environ['CI_COMMIT_SHA']
|
||||
CI_MERGE_REQUEST_TARGET_BRANCH_NAME = 'master'
|
||||
CI_SERVER_HOST = os.environ['CI_SERVER_HOST']
|
||||
UPSTREAM = 'upstream'
|
||||
else:
|
||||
# Local emulation mode when called directly
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(description='Commit message checker - local emulation mode')
|
||||
parser.add_argument('--sha', help='The commit message to start at (default: HEAD}',
|
||||
default='HEAD')
|
||||
parser.add_argument('--branch', help='The branch name to merge to (default: master)',
|
||||
default='master')
|
||||
parser.add_argument('--remote', help='The remote name (default: origin)',
|
||||
default='origin')
|
||||
args = parser.parse_args()
|
||||
|
||||
CI_COMMIT_SHA = args.sha
|
||||
CI_MERGE_REQUEST_TARGET_BRANCH_NAME = args.branch
|
||||
CI_SERVER_HOST = None
|
||||
UPSTREAM = 'origin'
|
||||
print(f'Running in local testing mode.')
|
||||
|
||||
print(f'Merging {CI_COMMIT_SHA} into {CI_MERGE_REQUEST_TARGET_BRANCH_NAME}')
|
||||
|
||||
# We need to add the real libinput as remote, our origin here is the user's
|
||||
# fork.
|
||||
repo = git.Repo('.')
|
||||
if 'upstream' not in repo.remotes:
|
||||
if UPSTREAM not in repo.remotes:
|
||||
upstream = repo.create_remote('upstream', f'https://{CI_SERVER_HOST}/libinput/libinput.git')
|
||||
upstream.fetch()
|
||||
|
||||
sha = CI_COMMIT_SHA
|
||||
branch = CI_MERGE_REQUEST_TARGET_BRANCH_NAME
|
||||
|
||||
commits = list(repo.iter_commits(f'upstream/{branch}..{sha}'))
|
||||
commits = list(repo.iter_commits(f'{UPSTREAM}/{branch}..{sha}'))
|
||||
|
||||
|
||||
def error(commit, message, long_message=''):
|
||||
|
|
@ -45,6 +67,7 @@ def error(commit, message, long_message=''):
|
|||
f'{info}\n\n')
|
||||
return msg
|
||||
|
||||
|
||||
@pytest.mark.parametrize('commit', commits)
|
||||
class TestCommits:
|
||||
def test_author_email(self, commit):
|
||||
|
|
@ -82,3 +105,7 @@ class TestCommits:
|
|||
error(commit, 'Second line in commit message must be emtpy')
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
pytest.main([__file__])
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue