better commit msg on build

This commit is contained in:
Maximilian Keßler 2021-10-08 09:17:56 +02:00
parent f97e7eec3f
commit 6101618f6b
3 changed files with 38 additions and 22 deletions

View file

@ -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
@ -46,7 +47,7 @@ deploy:
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}"
commit_message: $COMMIT_MSG
on:
all_branches: true
condition: $TRAVIS_PULL_REQUEST = false

View file

@ -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,13 +17,6 @@ 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))
@ -34,15 +28,16 @@ def build_details():
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_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 (!)']
@ -55,6 +50,6 @@ def build(build_dir: str):
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')

View file

@ -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: