Skip to content

Commit

Permalink
Add binary for e2d23bd: "updated tests"
Browse files Browse the repository at this point in the history
  • Loading branch information
Nneji123 committed Jul 13, 2022
0 parents commit 160589e
Show file tree
Hide file tree
Showing 22 changed files with 937 additions and 0 deletions.
121 changes: 121 additions & 0 deletions .ci/move_binary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#!/bin/python3
import os
import shutil
import subprocess
import sys
from os import environ as env

binary_filename = os.path.abspath(sys.argv[1])
master_repository_directory = os.path.abspath(sys.argv[2])
data_repository = sys.argv[3]
data_repository_directory = os.path.abspath(data_repository)
directory = sys.argv[4]

os.chdir(master_repository_directory)

filename = os.path.basename(binary_filename)
# Include commit subject and hash to the new commit
commit_hash = (
subprocess.check_output(["git", "rev-parse", "--verify", "--short", "HEAD"])
.decode("utf-8")
.strip()
)
commit_subject = (
subprocess.check_output(["git", "log", "-1", "--pretty=format:%s"])
.decode("utf-8")
.strip()
)

is_tag = env["GITHUB_EVENT_NAME"] == "push" and env["GITHUB_REF"].startswith(
"refs/tags"
)
is_pr = env["GITHUB_REF"].startswith("refs/pull")

filename_split = filename.split("-")
if is_tag:
new_commit_message = (
f'Add binary for {filename_split[1]} {commit_hash}: "{commit_subject}"'
)
elif is_pr:
# 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}"'

# Set author info to the latest commit author
author_name = subprocess.check_output(
["git", "log", "-1", "--pretty=format:%an"]
).decode("utf-8")
author_email = subprocess.check_output(
["git", "log", "-1", "--pretty=format:%ae"]
).decode("utf-8")

# Prepare for pushing
os.chdir(data_repository_directory)
os.makedirs(directory, exist_ok=True)
subprocess.check_call(["git", "config", "user.name", author_name])
subprocess.check_call(["git", "config", "user.email", author_email])
# Ensure that there are no changes
subprocess.check_call(
[
"git",
"pull",
"origin",
data_repository,
"--ff-only",
"--allow-unrelated-histories",
]
)

# Try to push several times
for i in range(3):
shutil.copy(binary_filename, os.path.join(directory, filename))
# Push changes
subprocess.check_call(["git", "add", os.path.join(directory, filename)])
subprocess.check_call(
["git", "commit", "--amend", "-m", new_commit_message]
)
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",
"--allow-unrelated-histories",
]
)
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()
)
print(
f"Binary file: {env['GITHUB_SERVER_URL']}/{env['GITHUB_REPOSITORY']}/blob/"
f"{new_commit_hash}/{directory}/{filename}"
)
54 changes: 54 additions & 0 deletions .github/workflows/buildapp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Build
on:
push:
branches-ignore:
- data
- gh-pages
tags:
- '**'
pull_request:
branches-ignore:
- data
- gh-pages

jobs:
# Build job. Builds app for Android with Buildozer
build-android:
name: Build for Android
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
with:
path: master

- name: Build with Buildozer
uses: ArtemSBulgakov/buildozer-action@v1
id: buildozer
with:
repository_root: master
workdir: androidapp
buildozer_version: stable

- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: package
path: ${{ steps.buildozer.outputs.filename }}

- name: Checkout
uses: actions/checkout@v2
with:
path: data
ref: data # Branch name

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.7
architecture: x64

- name: Push binary to data branch
if: github.event_name == 'push'
run: python master/.ci/move_binary.py "${{ steps.buildozer.outputs.filename }}" master data bin
14 changes: 14 additions & 0 deletions .github/workflows/codecount.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
on: [push]

jobs:
scc_job:
runs-on: ubuntu-latest
name: A job to count the lines of code.
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Get the lines of code.
id: scc
uses: iryanbell/[email protected]
with:
args: ${{ env.workspace }} -i js,go,html,css,python
11 changes: 11 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: black-action
on: [push, pull_request]
jobs:
linter_name:
name: runner / black formatter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: rickstaa/action-black@v1
with:
black_args: ". --check"
18 changes: 18 additions & 0 deletions .github/workflows/heroku.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Deploy

on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: akhileshns/[email protected] # This is the action
with:
appdir: flaskapp
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: carflaskpred #Must be unique in Heroku
heroku_email: [email protected]
Empty file added README.md
Empty file.
Binary file added androidapp/__pycache__/main.cpython-38.pyc
Binary file not shown.
Loading

0 comments on commit 160589e

Please sign in to comment.