-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve git deploy code, don't fail if there's nothing to commit
- Loading branch information
Showing
2 changed files
with
14 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,5 +44,3 @@ jobs: | |
run: | | ||
cd data | ||
python -u deploy.py | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -379,14 +379,14 @@ def update_readme_stats(): | |
|
||
|
||
def init_deploy(): | ||
args = ['git', 'remote', 'add', 'push-origin', f'https://{os.environ["GITHUB_TOKEN"]}@github.com/{os.environ["GITHUB_REPOSITORY"]}.git'] | ||
subprocess.run(args, check=True) | ||
|
||
|
||
def commit_deploy(pr_title): | ||
git_email = '[email protected]' | ||
git_name = 'winbindex-deploy-bot' | ||
|
||
subprocess.check_call(['git', 'config', '--global', 'user.email', git_email]) | ||
subprocess.check_call(['git', 'config', '--global', 'user.name', git_name]) | ||
|
||
|
||
def commit_deploy(pr_title): | ||
exclude_from_commit = [ | ||
'tools', | ||
'manifests', | ||
|
@@ -395,41 +395,18 @@ def commit_deploy(pr_title): | |
] | ||
|
||
# https://stackoverflow.com/a/51914162 | ||
extra_commit_params = [f':!{path}/*' for path in exclude_from_commit] | ||
exclude_params = [f':!{path}/*' for path in exclude_from_commit] | ||
|
||
commit_directly = True # pr_title.endswith('files from VirusTotal') | ||
if commit_directly: | ||
branch_name = 'gh-pages' | ||
checkout_params = [branch_name] | ||
else: | ||
branch_name = f'deploy-{time.time()}' | ||
checkout_params = ['-b', branch_name] | ||
|
||
commands = [ | ||
['git', 'config', '--global', 'user.email', git_email], | ||
['git', 'config', '--global', 'user.name', git_name], | ||
['git', 'checkout'] + checkout_params, | ||
['git', 'add', '-A', '--'] + extra_commit_params, | ||
['git', 'commit', '-m', pr_title], | ||
['git', 'push', 'push-origin', branch_name], | ||
] | ||
subprocess.check_call(['git', 'add', '-A', '--'] + exclude_params) | ||
|
||
for args in commands: | ||
subprocess.run(args, check=True) | ||
# https://stackoverflow.com/a/2659808 | ||
result = subprocess.run(['git', 'diff-index', '--quiet', '--cached', 'HEAD']) | ||
if result.returncode == 0: | ||
print('No changes to commit') | ||
return | ||
|
||
if not commit_directly: | ||
data = { | ||
'title': pr_title, | ||
'head': branch_name, | ||
'base': 'gh-pages' | ||
} | ||
headers = { | ||
'Accept': 'application/vnd.github.v3+json', | ||
'Authorization': f'token {os.environ["GITHUB_TOKEN"]}' | ||
} | ||
response = requests.post('https://api.github.com/repos/{os.environ["GITHUB_REPOSITORY"]}/pulls', data=json.dumps(data), headers=headers) | ||
#print(response.text) | ||
response.raise_for_status() | ||
subprocess.check_call(['git', 'commit', '-m', pr_title]) | ||
subprocess.check_call(['git', 'push']) | ||
|
||
|
||
def clean_deploy_files(): | ||
|