-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Edited: flake8.yml, pytest.yml. Created: create_release.yml, scripts …
…for GH Actions.
- Loading branch information
Showing
6 changed files
with
240 additions
and
60 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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
name: Upload Release Asset | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
workflow_run: | ||
workflows: | ||
- "tests.yml" | ||
types: | ||
- completed | ||
|
||
jobs: | ||
build-project: | ||
name: Upload Release Asset | ||
runs-on: windows-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.9 | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
pip install requests | ||
- name: Build zip file | ||
run: scripts/build_zip_file.py | ||
|
||
- name: Print a message | ||
run: echo "Starting the Python release process." | ||
|
||
- name: Create Release | ||
id: create_release | ||
run: | | ||
scripts/create_release.py || exit 1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.TOKEN }} | ||
|
||
- name: Print another message | ||
run: echo "Python release process completed." | ||
|
||
- name: Create and Upload Release Asset | ||
id: upload-release-asset | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.TOKEN }} | ||
UPLOAD_URL: ${{ steps.create_release.outputs.upload_url }} | ||
with: | ||
upload_url: ${{ env.UPLOAD_URL }} | ||
asset_path: ./Overwatch Rank Tracker.zip | ||
asset_name: Overwatch Rank Tracker.zip | ||
asset_content_type: application/zip |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
linters: | ||
name: Run Flake8 | ||
runs-on: windows-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.9 | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
pip install flake8 | ||
- name: Run Flake8 | ||
run: flake8 --config config.flake8 || exit 1 | ||
|
||
pytest: | ||
name: Run Pytest | ||
runs-on: windows-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.9 | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
pip install pytest | ||
- name: Run Pytest | ||
run: pytest || exit 1 |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import os | ||
import shutil | ||
import subprocess | ||
|
||
temporarily_folder_name = "Overwatch Rank Tracker" | ||
|
||
os.chdir("..") | ||
|
||
# paths | ||
project_path = os.getcwd() | ||
dist_path = os.path.join(project_path, "dist") | ||
zip_file_path = os.path.join(project_path, "Overwatch_Rank_Tracker.zip") | ||
temporary_folder = os.path.join(project_path, temporarily_folder_name) | ||
|
||
# there is an old archive - delete it | ||
if os.path.exists(zip_file_path): | ||
os.remove(zip_file_path) | ||
|
||
# executing the pyinstaller command to create an exe file inside the dist folder | ||
subprocess.run(["pyinstaller", "Overwatch Rank Tracker.spec"]) | ||
|
||
# make a duplicate of the dist folder to create an archive with a folder with the desired name Overwatch Rank Tracker inside it | ||
shutil.copytree(dist_path, temporarily_folder_name) | ||
|
||
# creating archive | ||
shutil.make_archive(temporary_folder, "zip") | ||
|
||
# deleting the "Overwatch Rank Tracker" temporary folder | ||
shutil.rmtree(temporary_folder) |
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 |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import subprocess | ||
import requests | ||
|
||
|
||
def increment_version(tag): | ||
"""Version Increase | ||
Example: v0.0.1 > v0.0.2""" | ||
|
||
tag = tag[1:] | ||
parts = tag.split('.') | ||
major = int(parts[0]) | ||
minor = int(parts[1]) | ||
patch = int(parts[2]) | ||
|
||
if patch < 9: | ||
patch += 1 | ||
elif minor < 9: | ||
minor += 1 | ||
patch = 0 | ||
else: | ||
major += 1 | ||
minor = 0 | ||
patch = 0 | ||
|
||
new_version = f"v{major}.{minor}.{patch}" | ||
return new_version | ||
|
||
|
||
def generate_release_description(tag: str): | ||
"""Takes the message of the last commit and edits it to fit the Release description""" | ||
|
||
# getting the name of the last commit | ||
command = ["git", "log", "-1", "--pretty=format:%s"] | ||
last_commit_message = subprocess.check_output(command, stderr=subprocess.STDOUT).decode("utf-8").strip().split(". ") | ||
|
||
changes_formatted = "\n".join(f"> * {change.strip('.')}." for change in last_commit_message) | ||
description = f"> **{tag}**:\n>\n{changes_formatted}\n>\n> Download below" | ||
return description | ||
|
||
|
||
# datas | ||
owner = 'enexety' | ||
repo = 'Overwatch_Rank_Tracker' | ||
# github_token = os.environ.get('TOKEN') | ||
github_token = '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' | ||
headers = { | ||
"Authorization": f"Bearer {github_token}" | ||
} | ||
|
||
# urls | ||
create_release_url = f"https://api.github.com/repos/{owner}/{repo}/releases" | ||
get_tag_url = f"https://api.github.com/repos/{owner}/{repo}/tags" | ||
|
||
|
||
# get new-next tag | ||
response_get_last_tag = requests.get(url=get_tag_url, headers=headers) | ||
if response_get_last_tag.status_code == 200: | ||
tags = response_get_last_tag.json() | ||
latest_tag = tags[0]['name'] | ||
new_tag = increment_version(tag=latest_tag) | ||
|
||
# create release | ||
data = { | ||
"owner": owner, | ||
"repo": repo, | ||
"tag_name": new_tag | ||
} | ||
response = requests.post(url=create_release_url, json=data, headers=headers) | ||
|
||
# was created | ||
if response.status_code == 201: | ||
|
||
# get the upload_url from the response | ||
upload_url = response.json()["upload_url"] | ||
|
||
# get the id of the created release | ||
release_id = response.json()["id"] | ||
|
||
# describe this release | ||
update_data = {"body": generate_release_description(tag=new_tag)} | ||
update_release_url = f"https://api.github.com/repos/{owner}/{repo}/releases/{release_id}" | ||
requests.patch(update_release_url, json=update_data, headers=headers) | ||
|
||
# create release title | ||
edit_release_url = f"https://api.github.com/repos/{owner}/{repo}/releases/{release_id}" | ||
inf = { | ||
"name": new_tag | ||
} | ||
headers_release_title = { | ||
"Authorization": f"Bearer {github_token}", | ||
"Accept": "application/vnd.github.v3+json" | ||
} | ||
response_release_title = requests.patch(edit_release_url, json=inf, headers=headers_release_title) | ||
if response_release_title.status_code != 200: | ||
raise Exception(f"Response when changing release title - {response_release_title.status_code}") | ||
|
||
else: | ||
raise Exception(f"Response to get latest tag - {response.status_code}") | ||
|
||
else: | ||
raise Exception(f"Response to get latest tag - {response_get_last_tag.status_code}") |