mirror of
https://github.com/ArtemSBulgakov/buildozer-action.git
synced 2024-08-16 10:09:52 +02:00
parent
abad880b7e
commit
9f94e8ca9a
2 changed files with 57 additions and 32 deletions
|
@ -14,6 +14,7 @@ directory = sys.argv[4]
|
||||||
os.chdir(master_repository_directory)
|
os.chdir(master_repository_directory)
|
||||||
|
|
||||||
filename = os.path.basename(binary_filename)
|
filename = os.path.basename(binary_filename)
|
||||||
|
# Include commit subject and hash to the new commit
|
||||||
commit_hash = (
|
commit_hash = (
|
||||||
subprocess.check_output(["git", "rev-parse", "--verify", "--short", "HEAD"])
|
subprocess.check_output(["git", "rev-parse", "--verify", "--short", "HEAD"])
|
||||||
.decode("utf-8")
|
.decode("utf-8")
|
||||||
|
@ -28,42 +29,66 @@ commit_subject = (
|
||||||
is_tag = env["GITHUB_EVENT_NAME"] == "push" and env["GITHUB_REF"].startswith(
|
is_tag = env["GITHUB_EVENT_NAME"] == "push" and env["GITHUB_REF"].startswith(
|
||||||
"refs/tags"
|
"refs/tags"
|
||||||
)
|
)
|
||||||
if not is_tag:
|
is_pr = env["GITHUB_REF"].startswith("refs/pull")
|
||||||
is_pr = env["GITHUB_REF"].startswith("refs/pull")
|
|
||||||
if is_pr:
|
|
||||||
# Pull Request - prN (pr1)
|
|
||||||
middle = "pr" + env["GITHUB_REF"].split("/")[2]
|
|
||||||
else:
|
|
||||||
# Latest commit - short hash (20f2448)
|
|
||||||
middle = commit_hash
|
|
||||||
filename_split = filename.split("-")
|
|
||||||
filename = "-".join([*filename_split[:2], middle, *filename_split[2:]])
|
|
||||||
|
|
||||||
# Set author info to the latest commit author
|
filename_split = filename.split("-")
|
||||||
author_name = subprocess.check_output(
|
if is_tag:
|
||||||
["git", "log", "-1", "--pretty=format:%an"]
|
new_commit_message = (
|
||||||
).decode("utf-8")
|
f'Add binary for {filename_split[1]} {commit_hash}: "{commit_subject}"'
|
||||||
author_email = subprocess.check_output(
|
)
|
||||||
["git", "log", "-1", "--pretty=format:%ae"]
|
elif is_pr:
|
||||||
).decode("utf-8")
|
# Pull Request - prN (pr1)
|
||||||
|
pr_number = env["GITHUB_REF"].split("/")[2]
|
||||||
|
filename = "-".join(
|
||||||
|
[*filename_split[:2], f"pr{pr_number}", *filename_split[2:]]
|
||||||
|
)
|
||||||
|
directory = os.path.join(directory, "prs")
|
||||||
|
new_commit_message = (
|
||||||
|
f'Add binary for #{pr_number} {commit_hash}: "{commit_subject}"'
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
# Latest commit - short hash (20f2448)
|
||||||
|
filename = "-".join([*filename_split[:2], commit_hash, *filename_split[2:]])
|
||||||
|
new_commit_message = f'Add binary for {commit_hash}: "{commit_subject}"'
|
||||||
|
|
||||||
# Move file
|
# Prepare for pushing
|
||||||
os.chdir(data_repository_directory)
|
os.chdir(data_repository_directory)
|
||||||
os.makedirs(directory, exist_ok=True)
|
os.makedirs(directory, exist_ok=True)
|
||||||
shutil.copy(binary_filename, os.path.join(directory, filename))
|
# Ensure that there is no changes
|
||||||
|
subprocess.check_call(["git", "pull", "origin", data_repository, "--ff-only"])
|
||||||
|
|
||||||
# Push changes
|
# Try to push several times
|
||||||
subprocess.check_call(["git", "config", "user.name", author_name])
|
for i in range(3):
|
||||||
subprocess.check_call(["git", "config", "user.email", author_email])
|
shutil.copy(binary_filename, os.path.join(directory, filename))
|
||||||
subprocess.check_call(
|
# Push changes
|
||||||
["git", "pull", "--ff-only"]
|
subprocess.check_call(["git", "add", os.path.join(directory, filename)])
|
||||||
) # Ensure that there is no changes
|
subprocess.check_call(
|
||||||
subprocess.check_call(["git", "add", os.path.join(directory, filename)])
|
["git", "commit", "--amend", "-m", new_commit_message]
|
||||||
subprocess.check_call(
|
)
|
||||||
["git", "commit", "-m", f'Add binary for {commit_hash}: "{commit_subject}"']
|
try:
|
||||||
|
subprocess.check_call(
|
||||||
|
["git", "push", "origin", data_repository, "--force"]
|
||||||
|
)
|
||||||
|
except subprocess.CalledProcessError: # There are changes in repository
|
||||||
|
# Undo local changes
|
||||||
|
subprocess.check_call(
|
||||||
|
["git", "reset", f"origin/{data_repository}", "--hard"]
|
||||||
|
)
|
||||||
|
# Pull new changes
|
||||||
|
subprocess.check_call(
|
||||||
|
["git", "pull", "origin", data_repository, "--force", "--ff-only"]
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
break # Exit loop if there is no errors
|
||||||
|
else:
|
||||||
|
raise Exception("Cannot push binary")
|
||||||
|
|
||||||
|
new_commit_hash = (
|
||||||
|
subprocess.check_output(["git", "rev-parse", "--verify", "--short", "HEAD"])
|
||||||
|
.decode("utf-8")
|
||||||
|
.strip()
|
||||||
)
|
)
|
||||||
subprocess.check_call(["git", "push"])
|
|
||||||
|
|
||||||
print(
|
print(
|
||||||
f"Binary file: {env['GITHUB_SERVER_URL']}/{env['GITHUB_REPOSITORY']}/blob/{data_repository}/{directory}/{filename}"
|
f"Binary file: {env['GITHUB_SERVER_URL']}/{env['GITHUB_REPOSITORY']}/blob/"
|
||||||
|
f"{new_commit_hash}/{directory}/{filename}"
|
||||||
)
|
)
|
||||||
|
|
|
@ -241,7 +241,7 @@ add this to your workflow:
|
||||||
architecture: x64
|
architecture: x64
|
||||||
|
|
||||||
- name: Push binary to data branch
|
- name: Push binary to data branch
|
||||||
run: python master/.ci/move_binary.py "${{ steps.buildozer.outputs.filename }}" master data
|
run: python master/.ci/move_binary.py "${{ steps.buildozer.outputs.filename }}" master data bin
|
||||||
```
|
```
|
||||||
|
|
||||||
Also you need to create `data` branch:
|
Also you need to create `data` branch:
|
||||||
|
|
Loading…
Reference in a new issue