Skip to content

Commit

Permalink
Merge pull request #210 from egg528/main
Browse files Browse the repository at this point in the history
[🌎 Feature] github action을 활용한 글 개수 자동 UPDATE #209
  • Loading branch information
egg528 authored Jun 18, 2024
2 parents 3e31cbc + 7c7328f commit 49b25bb
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 167 deletions.
30 changes: 0 additions & 30 deletions .github/workflows/auto-pr-for-count-files.yml

This file was deleted.

44 changes: 44 additions & 0 deletions .github/workflows/md-file-counter.yml
Original file line number Diff line number Diff line change
@@ -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 "[email protected]"
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
41 changes: 0 additions & 41 deletions .github/workflows/python-app.yml

This file was deleted.

7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.next
node_modules

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 자유 주제 스터디
### 전체 아티클 갯수: 61개
### 전체 아티클 갯수: 96개

<br>

Expand Down
Empty file added counter/__init__.py
Empty file.
26 changes: 26 additions & 0 deletions counter/__main__.py
Original file line number Diff line number Diff line change
@@ -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}")
95 changes: 0 additions & 95 deletions utils/count_files.py

This file was deleted.

0 comments on commit 49b25bb

Please sign in to comment.