diff --git a/.github/workflows/auto-pr-for-count-files.yml b/.github/workflows/auto-pr-for-count-files.yml deleted file mode 100644 index 21da73e..0000000 --- a/.github/workflows/auto-pr-for-count-files.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Auto PR to main - -on: - push: - branches: - - "bot/count-files" - -jobs: - build-and-pr: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Create Pull Request - uses: repo-sync/pull-request@v2 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - destination_branch: "main" - source_branch: "bot/count-files" - pr_title: "Automated PR to Main" - pr_body: "Please review updates from bot/count-files." - # steps: - # - uses: actions/checkout@v2 - # - name: Create Pull Request - # uses: repo-sync/pull-request@v2 - # with: - # github_token: ${{ secrets.GITHUB_TOKEN }} - # destination_branch: "main" - # source_branch: "bot/count-files" - # pr_title: "Automated PR to Main" - # pr_body: "Update main branch with changes from develop." diff --git a/.github/workflows/md-file-counter.yml b/.github/workflows/md-file-counter.yml new file mode 100644 index 0000000..da923dd --- /dev/null +++ b/.github/workflows/md-file-counter.yml @@ -0,0 +1,44 @@ +name: 10000-bagger Auto Markdown File Count Workflow + +on: + push: + branches: + - main + pull_request: + types: + - closed + branches: + - main + +jobs: + build: + if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true) + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.8' + + - name: count files + run: | + python3 -m counter + + - name: Commit changes + run: | + git config --local user.email "dfghcvb11@naver.com" + git config --local user.name "binary-ho" + git add -u + if git diff --cached --quiet; then + echo "No changes to commit" + else + git commit -m "10000-bagger auto md file counter" + fi + + + - name: Push changes + run: | + git push origin main diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml deleted file mode 100644 index 2287b6e..0000000 --- a/.github/workflows/python-app.yml +++ /dev/null @@ -1,41 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - -name: Python application - -on: - push: - branches: [ main ] - # pull_request: - # branches: [ main ] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 # 모든 이력을 가져오도록 설정 - persist-credentials: true # 자격증명을 지속 - - 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 - - name: Run Update Python Script - run: | - python utils/count_files.py - - name: Checkout to bot/count-files branch - run: | - git fetch - git checkout bot/count-files || git checkout -b bot/count-files - - name: Run Update README.md File and Push - run: | - git config --local user.email "dfghcvb11@naver.com" - git config --local user.name "binary-ho" - git add . - git commit -m "Automatically Update README.md file" - git push origin bot/count-files diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..855e676 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.next +node_modules + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class \ No newline at end of file diff --git a/README.md b/README.md index 9be8fe8..ce57f8d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # 자유 주제 스터디 -### 전체 아티클 갯수: 61개 +### 전체 아티클 갯수: 96개
diff --git a/counter/__init__.py b/counter/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/counter/__main__.py b/counter/__main__.py new file mode 100644 index 0000000..3a55aa8 --- /dev/null +++ b/counter/__main__.py @@ -0,0 +1,26 @@ +import os + +def count_md_files(directory): + md_count = 0 + for root, dirs, files in os.walk(directory): + md_count += sum(1 for file in files if file.endswith('.md')) + return md_count + + +if __name__ == "__main__": + root = os.getcwd() + md_file_count = count_md_files(root) - 1 # README.md 파일 제외 + readme_path = os.path.join(root, 'README.md') + + with open(readme_path, 'r', encoding='utf-8') as file: + readme_contents = file.readlines() + + for i, line in enumerate(readme_contents): + if line.startswith("### 전체 아티클 갯수:"): + readme_contents[i] = f"### 전체 아티클 갯수: {md_file_count}개\n" + break + + with open(readme_path, 'w', encoding='utf-8') as file: + file.writelines(readme_contents) + + print(f"Updated the README.md with total article count: {md_file_count}") \ No newline at end of file diff --git a/utils/count_files.py b/utils/count_files.py deleted file mode 100644 index e4790c8..0000000 --- a/utils/count_files.py +++ /dev/null @@ -1,95 +0,0 @@ -from collections import Counter -from datetime import datetime -import os - - -# def count_files(): -# files_info = [] -# total_file_count = 0 -# directory_list = [directory for directory in os.listdir("./") if "Folder" in directory] -# for directory in directory_list: -# file_list = os.listdir(f"./{directory}") -# file_count = len(file_list) -# temp = [directory, file_count] -# files_info.append(temp) -# total_file_count += file_count -# return files_info, total_file_count - -# def count_files(): -# files_info = [] -# total_file_count = 0 -# # "jin", "hong", "joon", "new", "woo" 중 하나라도 포함된 폴더 이름을 찾습니다. -# directory_list = [directory for directory in os.listdir("./") if any(name in directory for name in ["jin", "hong", "joon", "new", "woo"])] -# for directory in directory_list: -# file_list = os.listdir(f"./{directory}") -# file_count = len(file_list) -# temp = [directory, file_count] -# files_info.append(temp) -# total_file_count += file_count -# return files_info, total_file_count - -def count_files_recursive(directory): - total_file_count = 0 - # 현재 디렉토리의 내용을 나열합니다. - for entry in os.scandir(directory): - if entry.is_file() and entry.name.endswith('.md'): - # .md 확장자를 가진 파일이면 카운트를 증가합니다. - total_file_count += 1 - elif entry.is_dir(): - # 디렉토리(폴더)면 재귀적으로 이 함수를 호출합니다. - total_file_count += count_files_recursive(entry.path) - return total_file_count - -def count_files(): - files_info = [] - directory_list = [directory for directory in os.listdir("./") if os.path.isdir(directory) and directory not in [".github", "utils"]] - for directory in directory_list: - file_count = count_files_recursive(f"./{directory}") - temp = [directory, file_count] - files_info.append(temp) - return files_info, sum(info[1] for info in files_info) - - -def make_info(files_info, total_file_count): - info = f"### 전체 아티클 갯수: {total_file_count}개 (자동 업데이트)" - # for directory_files_info in files_info: - # temp = f"- {directory_files_info[0]}: {directory_files_info[1]}\n" - # info += temp - return info - -def make_read_me(info): - return f"""# 자유 주제 스터디 -{info} - -
- -### 진행 방식 -- 각자 이름의 branch에서 각자 이름의 폴더에 공부 내용을 정리하여 한다. -- 일주일에 5번 main branch를 향하는 PR을 올린다. - - 새벽 6시 전까지 올린 PR은 전날 올린 건으로 간주된다. (출근길 글 읽기를 위해) -- 매일 낮 12시 이전까지 스터디원이 올린 PR에 승인, 질문 등의 피드백을 남긴다. -- PR에 꼭 완성된 글을 올리지 않아도 된다. - -
- -### 누적 벌금 : 370,013 원 -""" - -# return f"""# Self-Updating-Readme -# Push할 때마다 폴더 별 파일 수를 리드미에 자동으로 업데이트
-# Automatically update the number of files per folder to Readme whenever you push.

-# {info} -# """ - - -def update_readme(): - files_info, total_file_count = count_files() - info = make_info(files_info, total_file_count) - readme = make_read_me(info) - return readme - - -if __name__ == "__main__": - readme = update_readme() - with open("./README.md", 'w', encoding='utf-8') as f: - f.write(readme)