GitHub Actions๋ก pushํ ๋๋ง๋ค README.md ์ ๋ฐ์ดํธํ๊ธฐ
๊ทธ๋์ ์ฝํ ๋ฌธ์ ๋ private ๋ ํฌ์ ์ ์ฅํ์๋๋ฐ
22๋ 12์๋ถํฐ public์ผ๋ก ์๊ณ ๋ฆฌ์ฆ ๋ฌธ์ ํ์ด ๋ ํฌ์ ์ฝ๋๋ฅผ ์ฌ๋ฆฌ๊ธฐ ์์ํ๋ค.
https://github.com/monzheld/Algorithms
GitHub - monzheld/Algorithms: ๐ ํ์ด์ฌ ์๊ณ ๋ฆฌ์ฆ ๋ฌธ์ ํ์ด ๐
๐ ํ์ด์ฌ ์๊ณ ๋ฆฌ์ฆ ๋ฌธ์ ํ์ด ๐. Contribute to monzheld/Algorithms development by creating an account on GitHub.
github.com
๋ ํฌ๋ฅผ ๊ณต๊ฐํ๋ค ๋ณด๋ ์ปค๋ฐํ ๋๋ง๋ค ํด๊ฒฐํ ๋ฌธ์ ๊ฐ์๋ฅผ ์นด์ดํธํด์ README.md๋ฅผ ์๋์ผ๋ก ์ ๋ฐ์ดํธํ๋ฉด ์ข์ ๊ฒ ๊ฐ์๋ค.
๊ทธ๋์ ์ฐพ์๋ณด๋ ์ค ์์ฃผ ์น์ ํ๊ฒ ์์ฑ๋ ๊ธ์ ๋ฐ๊ฒฌํด์ ์ด ๊ธ์ ์ฐธ๊ณ ํด์ ๋ง๋ค์ด๋ดค๋ค!
์๋์ผ๋ก ์นด์ดํธ ํด์ฃผ๋ ์ฝ๋ ์์ฑํ๊ธฐ
๊นํ๋ธ ๋ ํฌ์ utils ํด๋๋ฅผ ๋ง๋ ๋ค์
ํด๋น ํด๋์ ํด๊ฒฐํ ๋ฌธ์ ์๋ฅผ ์๋์ผ๋ก ์นด์ดํธํด์ฃผ๋ count_solved_problems.py๋ฅผ ์์ฑํ๋ค.
from collections import defaultdict
import os
import re
def count_solved_problems():
"""์ฌ์ดํธ๋ณ ํด๊ฒฐํ ๋ฌธ์ ๊ฐ์ ์นด์ดํธ
์ฝ๋ฉํ
์คํธ ์ฌ์ดํธ๋ณ๋ก ํด๊ฒฐํ ๋ฌธ์ ์ ๊ฐ์๋ฅผ ์ธ๋ ํจ์์
๋๋ค.
name_list (list): ๋๋ ํ ๋ฆฌ๋ช
์ด์ ์ฝ๋ฉํ
์คํธ ์ฌ์ดํธ๋ช
code_dict (collections.defaultdict): ์ฌ์ดํธ๋ณ๋ก ํด๊ฒฐํ ๋ฌธ์ ์ ipynb ํ์ผ๋ช
(default: list)
code_cnt_info (collections.defaultdict): ์ฌ์ดํธ๋ณ๋ก ํด๊ฒฐํ ๋ฌธ์ ์ ๊ฐ์ (default: 0)
total_code_num (int): ํด๊ฒฐํ ๋ฌธ์ ์ ์ด๊ฐ์
Returns:
total_code_num (int): ํด๊ฒฐํ ๋ฌธ์ ์ ์ด๊ฐ์
code_cnt_info (collections.defaultdict): ์ฌ์ดํธ๋ณ๋ก ํด๊ฒฐํ ๋ฌธ์ ์ ๊ฐ์ (default: 0)
"""
r = [re.findall(r"^[A-Z]+", dirctory) for dirctory in os.listdir("./")]
name_list = [dir_name[0].replace("[", "").replace("]", "") for dir_name in r if len(dir_name) > 0]
name_list.remove("README")
solved_problem_list = []
code_dict = defaultdict(list)
code_cnt_info = defaultdict(lambda:0)
for name in name_list:
code_list = [file for file in os.listdir(f"./{name}") if file.endswith(".ipynb")]
code_dict[name] = code_list
code_cnt_info[name] = len(code_list)
solved_problem_list += code_list
total_code_num = len(solved_problem_list)
return total_code_num, code_cnt_info
def make_count_info(total_code_num, code_cnt_info):
"""์ฌ์ดํธ๋ณ ํด๊ฒฐํ ๋ฌธ์ ๊ฐ์ ์ ๋ณด ์์ฑ
์ฝ๋ฉํ
์คํธ ์ฌ์ดํธ๋ณ๋ก ํด๊ฒฐํ ๋ฌธ์ ์ ๊ฐ์ ์ ๋ณด๋ฅผ ์์ฑํ๋ ํจ์์
๋๋ค.
Arguments:
total_code_num (int): ํด๊ฒฐํ ๋ฌธ์ ์ ์ด๊ฐ์
code_cnt_info (collections.defaultdict): ์ฌ์ดํธ๋ณ๋ก ํด๊ฒฐํ ๋ฌธ์ ์ ๊ฐ์ (default: 0)
Returns:
count_info (str): ์ฌ์ดํธ๋ณ ํด๊ฒฐํ ๋ฌธ์ ๊ฐ์ ์ ๋ณด ์์ฑ
"""
count_info = f"### ํด๊ฒฐํ ์ด ๋ฌธ์ ์ : {total_code_num}๊ฐ\n"
for k,v in code_cnt_info.items():
temp = f"- {k} - {v}๊ฐ\n"
count_info += temp
return count_info
def make_read_me(count_info):
"""README.md ํ์ผ ์์ฑ
README.md ํ์ผ์ ์์ฑํ๋ ํจ์์
๋๋ค.
Arguments:
count_info (str): ์ฌ์ดํธ๋ณ ํด๊ฒฐํ ๋ฌธ์ ๊ฐ์ ์ ๋ณด ์์ฑ
Returns:
README.md ํ์ผ์ ์์ฑ๋ ์ถ๋ ฅ๋ฌธ
"""
return f"""# Algorithms
ํ์ด์ฌ ์๊ณ ๋ฆฌ์ฆ ๋ฌธ์ ํ์ด
### Since 2022.12.13 ~
{count_info}
[์๊ณ ๋ฆฌ์ฆ ๋ฌธ์ ํ์ด ๋ธ๋ก๊ทธ](url)
#### ๋ชจ๋ ๋ฌธ์ ๋ Python3 ๋ก ํด๊ฒฐํ์ต๋๋ค.
"""
def update_readme_md():
"""README.md ํ์ผ ์
๋ฐ์ดํธ
README.md ํ์ผ์ ์
๋ฐ์ดํธํ๋ ํจ์์
๋๋ค.
Returns:
README.md ํ์ผ์ ์์ฑ๋ ์ถ๋ ฅ๋ฌธ
"""
total_code_num, code_cnt_info = count_solved_problems()
count_info = make_count_info(total_code_num=total_code_num, code_cnt_info=code_cnt_info)
readme = make_read_me(count_info=count_info)
return readme
if __name__ == "__main__":
readme = update_readme_md()
with open("./README.md", 'w', encoding='utf-8') as f:
f.write(readme)
์๋๋ PROGRAMMERS ํด๋ ์์ ๋ ๋ฒจ๋ณ๋ก ๋ฐ๋ก ํด๋๋ก ๊ตฌ๋ถํ์๋๋ฐ
์ด๋ ๊ฒ ํ๋ฉด ํด๊ฒฐํ ๋ฌธ์ ์ ipynb ํ์ผ๋ค์ ๊ฐ์ ธ์ค๊ธฐ๊ฐ ๋๋ฌด ๋ณต์กํด์ ธ์ ๋ ๋ฒจ ํด๋๋ ์์ ๊ณ ๊ทธ๋ฅ ์ฝ๋ฉํ ์คํธ ์ฌ์ดํธ๋ณ๋ก๋ง ๋๋ ํ ๋ฆฌ๋ฅผ ๋๋ด๋ค.
๊ทธ๋ฆฌ๊ณ ์ฐธ๊ณ ๋ก make_read_me() ํจ์๊ฐ returnํ ์ถ๋ ฅ๋ฌธ ๋ถ๋ถ์ ์ฝ๋์ ๋์์๋ ๋๋ก ๋ค์ฌ ์ฐ๊ธฐ๋ฅผ ํ์ง ์์์ผ
๋งํฌ๋ค์ด์ด ์ ๋๋ก ์ ์ฉ๋ผ์ README.md ํ์ผ์ ๋์จ๋ค!
GitHub Actions ์ค์ ํ๊ธฐ
Actions์ Python application์ ํ์ฉํด์ workflow ์ฝ๋๋ฅผ ์์ฑํ๋ฉด ๋๋ค.
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Python application
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Run count_solved_problems.py
run: |
python utils/count_solved_problems.py
- name: Update README.md file
run: |
git config --local user.email "{๋ฉ์ผ ์ฃผ์}"
git config --local user.name "{user name}"
git status
git add README.md
git diff
git commit -m "docs: Update README.md file"
git push
์ฝ๋ ์์ฒด๋ ๊ฐ๋จํ๋ฐ
์ฒ์์ ๊ณ์ ๊ฐ์ ์๋ฌ๋ก 7๋ฒ์ด๋ ์คํจํ์๋ค... ๐ (์์ ๋์จ ์ฝ๋๋ ์ฑ๊ณตํ ์ฝ๋!)
๊ณ์ Error: Process completed with exit code 128. ์๋ฌ๊ฐ ๋ฌ๋๋ฐ
The requested URL returned error: 403 ์ ํด๊ฒฐ ๋ฐฉ๋ฒ๋ ์๋ํด ๋ณด๊ณ ,
Personal access tokens์ scope๋ ๋ณ๊ฒฝํด๋ณด๊ณ ํ์ง๋ง ํด๊ฒฐ๋์ง ์์๋ค.
- ์ฐธ๊ณ ํ๋ The requested URL returned error: 403 ํด๊ฒฐ ๋ฐฉ๋ฒ
โ ๏ธ [GitHub] The requested URL returned error: 403
[GitHub] The requested URL returned error: 403 ์๋ฌ
velog.io
๋์ค์ ๋ค์ ๋ณด๋ ์ง์ง ๊ฐ๋จํ ๊ฒ ๋๋ฌธ์ ์๋ฌ๊ฐ ๋ฌ๋ ๊ฒ์ด์์
๋ด๊ฐ ๋งจ ์ฒ์ ์์ฑํ๋ workflow ์ฝ๋๋ ์๋์ ๊ฐ์๋ค
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Python application
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
- name: Run update python script
run: |
python utils/count_solved_problems.py
- name: Run update README.md file
run: |
git config --local user.email "{๋ฉ์ผ ์ฃผ์}"
git config --local user.name "{user name}"
git status
git add README.md
git diff
git commit -m "docs: Update README.md file"
git push
์ ๊ธฐ ์๋ 'permissions:' ๋ถ๋ถ ๋๋ฌธ์ ๊ณ์ ๊ฐ์ ์๋ฌ๊ฐ ๋ฌ๋ ๊ฒ์ด์๋ค...
๊ทธ๋์ ๊ณต์ ๋ฌธ์๋ฅผ ์ฐธ๊ณ ํด์ write๋ฅผ ์ถ๊ฐํด ๋ดค๋๋ฐ
permissions:
contents: read|write
Invalid workflow file ์๋ฌ๊ฐ ๋ด๋ค
Invalid workflow file
The workflow is not valid. .github/workflows/python-app.yml (Line: 13, Col: 13): Unexpected value 'read|write'
- ์ฐธ๊ณ ํ๋ ๊ณต์ ๋ฌธ์
https://docs.github.com/ko/actions/using-jobs/assigning-permissions-to-jobs
์์ ์ ๊ถํ ํ ๋น - GitHub Docs
๊ฐ์ permissions๋ฅผ ์ฌ์ฉํ์ฌ GITHUB_TOKEN์ ๋ถ์ฌ๋ ๊ธฐ๋ณธ ์ฌ์ฉ ๊ถํ์ ์์ ํ๋ฉด ํ์์ ๋ฐ๋ผ ์ก์ธ์ค๋ฅผ ์ถ๊ฐํ๊ฑฐ๋ ์ ๊ฑฐํ์ฌ ํ์ํ ์ต์ ์ก์ธ์ค๋ง ํ์ฉํ ์ ์์ต๋๋ค. ์์ธํ ๋ด์ฉ์ “์ํฌํ๋ก์
docs.github.com
๊ทธ๋์ ๊ทธ๋ฅ permissions ๋ถ๋ถ์ ์ญ์ ํ๋๋ ๋ง๋ํ๊ฒ ํด๊ฒฐ๋๋ค..!
! ์์ผ๋ก๋ actions๊ฐ ๋ณ๊ฒฝํด๋ ๋ด์ฉ์ ๋ก์ปฌ์๋ ๋ฐ์ํด์ผ ํ๊ธฐ ๋๋ฌธ์ ๋จผ์ pull์ ํ๊ณ push๋ฅผ ํด์ผ ํจ !
์ด๋ ๊ฒ ์ ๋ฆฌํ๊ณ ๋ณด๋ ์๋นํ ๊ฐ๋จํด ๋ณด์ด์ง๋ง
์ฑ๊ณตํ๊ธฐ๊น์ง ์๊ฐ๋ณด๋ค ํ๋ํ ๊ณผ์ ์ด์๋คใ ใ ใ
๊ทธ๋๋ ๋๋ถ์ ์ค๋๋ ๋ง์ ๊ฑธ ๋ฐฐ์ธ ์ ์์๋ค!