Merge pull request #3 from kesslermaximilian/testbranch
Better building and deployment
This commit is contained in:
commit
2fcf4e2f5f
3 changed files with 40 additions and 26 deletions
|
@ -15,6 +15,7 @@ install:
|
||||||
- pip install GitPython
|
- pip install GitPython
|
||||||
|
|
||||||
script:
|
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/")'
|
- python3 -c 'from build import build; build("build/LatexPackages/")'
|
||||||
- cd build
|
- cd build
|
||||||
- zip -r LatexPackages.zip LatexPackages
|
- zip -r LatexPackages.zip LatexPackages
|
||||||
|
@ -45,10 +46,8 @@ deploy:
|
||||||
repo: kesslermaximilian/LatexPackagesBuild
|
repo: kesslermaximilian/LatexPackagesBuild
|
||||||
commiter_from_gh: true
|
commiter_from_gh: true
|
||||||
allow_empty_commit: true
|
allow_empty_commit: true
|
||||||
target_branch: $TRAVIS_BRANCH
|
target_branch: $TRAVIS_BRANCH-build
|
||||||
commit_message: "%{git_commit_msg}\n\nBuilt commit %{git_sha} from %{repo}:%{git_branch}"
|
commit_message: $COMMIT_MSG
|
||||||
on:
|
on:
|
||||||
branches:
|
all_branches: true
|
||||||
only:
|
|
||||||
- /.*/
|
|
||||||
condition: $TRAVIS_PULL_REQUEST = false
|
condition: $TRAVIS_PULL_REQUEST = false
|
||||||
|
|
21
build.py
21
build.py
|
@ -2,11 +2,12 @@ from pathlib import *
|
||||||
import sys
|
import sys
|
||||||
import git
|
import git
|
||||||
from datetime import *
|
from datetime import *
|
||||||
|
|
||||||
sys.path.insert(0, 'PyTeX/')
|
sys.path.insert(0, 'PyTeX/')
|
||||||
|
|
||||||
from package_formatter import PackageFormatter
|
from package_formatter import PackageFormatter
|
||||||
from replacements import make_default_commands
|
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 = [
|
||||||
"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():
|
def build_details():
|
||||||
repo = git.Repo()
|
repo = git.Repo()
|
||||||
repo_description = git_describe(get_latest_commit(repo))
|
repo_description = git_describe(get_latest_commit(repo))
|
||||||
|
@ -34,27 +28,28 @@ def build_details():
|
||||||
pytex_commit_hash=get_latest_commit(pytex_repo).hexsha[0:7],
|
pytex_commit_hash=get_latest_commit(pytex_repo).hexsha[0:7],
|
||||||
packages_version=repo_description,
|
packages_version=repo_description,
|
||||||
packages_commit_hash=get_latest_commit(repo).hexsha[0:7]
|
packages_commit_hash=get_latest_commit(repo).hexsha[0:7]
|
||||||
), BUILD_DETAILS))
|
), BUILD_DETAILS)), repo_description
|
||||||
|
|
||||||
|
|
||||||
def build(build_dir: str):
|
def build(build_dir: str):
|
||||||
input_root = Path('./packages').resolve()
|
input_root = Path('./packages').resolve()
|
||||||
output = input_root / build_dir
|
output = input_root / build_dir
|
||||||
print('[PyTeX] Getting git repository information...')
|
print('[PyTeX] Getting git repository information...')
|
||||||
extra_header = build_details()
|
extra_header, repo_description = build_details()
|
||||||
print('[PyTeX] ..done.')
|
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():
|
if git.Repo().is_dirty():
|
||||||
extra_header += ['WARNING: Local changes to git repository detected.',
|
extra_header += ['WARNING: Local changes to git repository detected.',
|
||||||
' The build will not be reproducible (!)']
|
' The build will not be reproducible (!)']
|
||||||
num_files = 0
|
num_files = 0
|
||||||
for file in input_root.rglob('*.pysty'):
|
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)
|
formatter = PackageFormatter(package_name=file.with_suffix('').name, extra_header=extra_header)
|
||||||
print('[PyTeX] Writing file {}'.format(formatter.file_name))
|
print('[PyTeX] Writing file {}'.format(formatter.file_name))
|
||||||
make_default_commands(formatter)
|
make_default_commands(formatter)
|
||||||
formatter.format_package(file, Path('./').resolve() / build_dir / str(file.parent.relative_to(input_root)))
|
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}/')
|
print(f'[PyTeX] Successfully built {num_files} packages in {build_dir}/')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
build('build')
|
build('build')
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,25 @@
|
||||||
import git
|
import git
|
||||||
from typing import Dict
|
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:
|
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:
|
try:
|
||||||
if len(commit.parents) > 0:
|
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:]:
|
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:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
return commit_history
|
return commit_history
|
||||||
|
|
Loading…
Reference in a new issue