diff --git a/.travis.yml b/.travis.yml index c65f1ba..1fd2351 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ install: - pip install GitPython script: + - export COMMIT_MSG=$(python3 -c 'from git_version import get_deploy_message; print(get_deploy_message())') - python3 -c 'from build import build; build("build/LatexPackages/")' - cd build - zip -r LatexPackages.zip LatexPackages @@ -45,10 +46,8 @@ deploy: repo: kesslermaximilian/LatexPackagesBuild commiter_from_gh: true allow_empty_commit: true - target_branch: $TRAVIS_BRANCH - commit_message: "%{git_commit_msg}\n\nBuilt commit %{git_sha} from %{repo}:%{git_branch}" + target_branch: $TRAVIS_BRANCH-build + commit_message: $COMMIT_MSG on: - branches: - only: - - /.*/ + all_branches: true condition: $TRAVIS_PULL_REQUEST = false diff --git a/build.py b/build.py index 5784192..962a773 100644 --- a/build.py +++ b/build.py @@ -2,11 +2,12 @@ from pathlib import * import sys import git from datetime import * + sys.path.insert(0, 'PyTeX/') from package_formatter import PackageFormatter from replacements import make_default_commands -from git_version import git_describe +from git_version import git_describe, get_latest_commit BUILD_DETAILS = [ "Build details:", @@ -16,45 +17,39 @@ BUILD_DETAILS = [ ] -def get_latest_commit(repo): - if repo.head.is_detached: - return repo.head.commit - else: - return repo.head.ref.commit - - def build_details(): repo = git.Repo() repo_description = git_describe(get_latest_commit(repo)) pytex_repo = repo.submodule('PyTeX').module() pytex_repo_description = git_describe(get_latest_commit(pytex_repo)) return list(map(lambda line: line.format( - build_time=datetime.now().strftime('%Y/%m/%d %H:%M'), - pytex_version=pytex_repo_description, - pytex_commit_hash=get_latest_commit(pytex_repo).hexsha[0:7], - packages_version=repo_description, - packages_commit_hash=get_latest_commit(repo).hexsha[0:7] - ), BUILD_DETAILS)) + build_time=datetime.now().strftime('%Y/%m/%d %H:%M'), + pytex_version=pytex_repo_description, + pytex_commit_hash=get_latest_commit(pytex_repo).hexsha[0:7], + packages_version=repo_description, + packages_commit_hash=get_latest_commit(repo).hexsha[0:7] + ), BUILD_DETAILS)), repo_description def build(build_dir: str): input_root = Path('./packages').resolve() output = input_root / build_dir print('[PyTeX] Getting git repository information...') - extra_header = build_details() - print('[PyTeX] ..done.') + extra_header, repo_description = build_details() + print('[PyTeX] Building version {version} of LatexPackages'.format(version=repo_description)) + print('[PyTeX] Latest commit message: ' + get_latest_commit(git.Repo()).message.strip()) if git.Repo().is_dirty(): extra_header += ['WARNING: Local changes to git repository detected.', - ' The build will not be reproducible (!)'] + ' The build will not be reproducible (!)'] num_files = 0 for file in input_root.rglob('*.pysty'): - num_files+=1 + num_files += 1 formatter = PackageFormatter(package_name=file.with_suffix('').name, extra_header=extra_header) print('[PyTeX] Writing file {}'.format(formatter.file_name)) make_default_commands(formatter) formatter.format_package(file, Path('./').resolve() / build_dir / str(file.parent.relative_to(input_root))) print(f'[PyTeX] Successfully built {num_files} packages in {build_dir}/') + if __name__ == "__main__": build('build') - diff --git a/git_version.py b/git_version.py index e6da79c..08965b9 100644 --- a/git_version.py +++ b/git_version.py @@ -1,5 +1,25 @@ import git from typing import Dict +import os + + +def get_latest_commit(repo): + if repo.head.is_detached: + return repo.head.commit + else: + return repo.head.ref.commit + + +def get_deploy_message(): + repo = git.Repo() + old_msg = get_latest_commit(repo).message + return "{old_msg}\n" \ + "\n" \ + "Build branch {branch} ({hexsha}) from {repo_name}" \ + .format(old_msg=old_msg, + branch=os.environ['TRAVIS_BRANCH'], + hexsha=get_latest_commit(repo).hexsha[0:7], + repo_name='kesslermaximilian/LatexPackages') def get_history(commit: git.objects.commit.Commit, priority=0, depth=0) -> Dict: @@ -9,9 +29,9 @@ def get_history(commit: git.objects.commit.Commit, priority=0, depth=0) -> Dict: }} try: if len(commit.parents) > 0: - commit_history.update(get_history(commit.parents[0], priority, depth+1)) + commit_history.update(get_history(commit.parents[0], priority, depth + 1)) for parent in commit.parents[1:]: - commit_history.update(get_history(parent, priority+1, depth+1)) + commit_history.update(get_history(parent, priority + 1, depth + 1)) except ValueError: pass return commit_history