Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolCoderCarl committed May 17, 2022
2 parents 1363f9d + a4def01 commit be174c4
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 31 deletions.
98 changes: 98 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: CI

on:
pull_request:
branches: [ main ]

jobs:

build:
name: Build packages
runs-on: ${{ matrix.os }}
outputs:
get_current_tag: ${{ steps.set_current_tag_id.outputs.current_tag }}
strategy:
matrix:
include:
- os: windows-latest
TARGET: windows
CMD_BUILD: python -m PyInstaller --workpath /tmp/build --specpath /tmp -F butler.py
OUT_FILE_NAME: butler.exe
ASSET_MIME: application/vnd.microsoft.portable-executable
- os: ubuntu-latest
TARGET: ubuntu
CMD_BUILD: python -m PyInstaller --workpath /tmp/build --specpath /tmp -F butler.py
OUT_FILE_NAME: butler
ASSET_MIME: application/x-binary

steps:
- uses: actions/checkout@v2
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/github-tag-action@v6.0
with:
github_token: ${{ secrets.REPOS_TOKEN }}

- name: Set up Python 3.9
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
- name: Build with pyinstaller for ${{ matrix.TARGET }}
run: ${{ matrix.CMD_BUILD }}

- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.OUT_FILE_NAME }}
path: ./dist/${{ matrix.OUT_FILE_NAME }}
retention-days: 1

- name: Set tag version to output
id: set_current_tag_id
run: echo "::set-output name=current_tag::${{ steps.tag_version.outputs.new_tag }}"

- name: Step To run on failure
if: ${{ failure() }}
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_CHAT }}
token: ${{ secrets.TELEGRAM_TOKEN }}
format: html
message: |
<b>!!! FAILED !!!</b>
<b>Failed job:</b> https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
telegram:
runs-on: ubuntu-latest
name: Notification
needs: [ build ]

steps:
- name: Notify telegram message after Packaging
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_CHAT }}
token: ${{ secrets.TELEGRAM_TOKEN }}
format: html
message: |
${{ github.actor }} created commit:
<b>WorkFlows:</b> <a href="https://github.com/${{ github.repository }}/actions">ActionsList</a>
Commit with tag: ${{ needs.build.outputs.get_current_tag }}
Repository: ${{ github.repository }}
Branch: ${{ github.ref }}
<b>Artifacts:</b> https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
40 changes: 40 additions & 0 deletions .github/workflows/code_quality.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Code Quality

on:
push:
branches: [ develop ]

jobs:
code_quality:
runs-on: ubuntu-latest
name: Checks with blacks, isort
container: python:3.9

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Run script
run: |
pip install -r requirements.txt
ls -la
- name: Black check
run:
black --check .

- name: Isort check
run:
isort --check .

- name: Step To run on failure
if: ${{ failure() }}
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_CHAT }}
token: ${{ secrets.TELEGRAM_TOKEN }}
format: html
message: |
<b>!!! FAILED !!!</b>
<b>Failed job:</b> https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
27 changes: 3 additions & 24 deletions .github/workflows/ci.yaml → .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,10 @@ on:
branches: [ main ]

jobs:
code_quality:
runs-on: ubuntu-latest
name: Checks with blacks, isort
container: python:3.9

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Run script
run: |
pip install -r requirements.txt
ls -la
- name: Black check
run:
black --check .

- name: Isort check
run:
isort --check .


release:
name: Create Release
runs-on: ubuntu-latest
needs: code_quality
outputs:
get_release_url: ${{ steps.set_release_url.outputs.release_url }}
get_current_tag: ${{ steps.set_current_tag_id.outputs.current_tag }}
Expand Down Expand Up @@ -102,10 +79,12 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Build with pyinstaller for ${{ matrix.TARGET }}
run: ${{ matrix.CMD_BUILD }}

- uses: actions/upload-artifact@v3
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.OUT_FILE_NAME }}
path: ./dist/${{ matrix.OUT_FILE_NAME }}
Expand Down
41 changes: 34 additions & 7 deletions butler.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import argparse
import os
import shutil
from datetime import datetime
from os.path import basename
from zipfile import ZipFile

files_extension = [
".txt",
".doc",
".docx",
".pdf",
".xlsx",
".zip",
".bmp",
".jpg",
".rtf",
Expand All @@ -22,16 +26,19 @@
target_dir_name = "ALL"


def clean_the_dir(directory_path):
def clean_the_dir(directory_path: str):
for files in os.listdir(directory_path):
path = os.path.join(directory_path, files)
try:
shutil.rmtree(path)
except OSError:
os.remove(path)
if "butler" in (path.split("/")[-1]):
print("Skipped " + path.split("/")[-1])
else:
try:
shutil.rmtree(path)
except OSError:
os.remove(path)


def group_up_files(new_dir_name):
def group_up_files(new_dir_name: str):
print(new_dir_name)
for file in os.listdir(args.dir):
for ext in files_extension:
Expand All @@ -47,20 +54,38 @@ def group_up_files(new_dir_name):
shutil.move(file_path, new_dir_path)


def create_archive(dir_to_archive: str):
now = datetime.now()
date_time = now.strftime("%m.%d.%Y_%H.%M.%S")
with ZipFile(str(date_time) + ".zip", "w") as zip_obj:
for folder_name, sub_folders, filenames in os.walk(dir_to_archive):
for filename in filenames:
if ".zip" in filename:
pass
else:
zip_path = os.path.join(folder_name, filename)
zip_obj.write(zip_path, basename(zip_path))


parser = argparse.ArgumentParser(
prog="butler",
description="""The Butler helps keep the castle clean and tidy""",
epilog="""(c) CoolCoderCarl""",
)


parser.add_argument(
"--clean", help="Clean target directory. Example /tmp/, both slash required"
)

parser.add_argument(
"--dir", help="Dir to group up the files. Example /tmp/, both slash required"
)

parser.add_argument(
"--archive",
help="Create archive from target directory. Example /tmp/, both slash required",
)

args = parser.parse_args()


Expand All @@ -69,3 +94,5 @@ def group_up_files(new_dir_name):
clean_the_dir(args.clean)
elif args.dir:
group_up_files(target_dir_name)
elif args.archive:
create_archive(args.archive)

0 comments on commit be174c4

Please sign in to comment.