Skip to content

Solvesql Solution

Solvesql Solution #13

name: Auto Update README
on:
push:
branches: [ master ]
paths:
- "BaekJoon/**"
- "LeetCode/**"
- "Solvesql/**"
permissions:
contents: write # Actions가 commit/push 가능
jobs:
update: # Job 이름
if: github.actor != 'github-actions[bot]' # Actions가 만든 커밋은 무시되도록 하여 무한루프 방지
runs-on: ubuntu-latest # GitHub가 제공하는 리눅스 VM (Python, git 기본 내장)
steps:
- uses: actions/checkout@v4 # 레포 체크아웃
with:
fetch-depth: 0 # before..after diff가 정확히 계산
- uses: actions/setup-python@v5 # Python 세팅
with:
python-version: "3.11"
- name: Detect changed areas
id: changes
env:
BEFORE: ${{ github.event.before }}
AFTER: ${{ github.sha }}
shell: bash
run: |
set -euo pipefail
echo "BEFORE=$BEFORE"
echo "AFTER=$AFTER"
# BEFORE가 all-zero면 fallback (첫 push/force push 대응)
if [[ "$BEFORE" =~ ^0+$ ]]; then
BEFORE="$(git rev-parse HEAD~1)"
echo "FALLBACK BEFORE=$BEFORE"
fi
files="$(git diff --name-only "$BEFORE" "$AFTER" || true)"
echo "CHANGED FILES:"
echo "$files"
echo "lc=false" >> "$GITHUB_OUTPUT"
echo "bj=false" >> "$GITHUB_OUTPUT"
echo "ss=false" >> "$GITHUB_OUTPUT"
if echo "$files" | grep -q '^LeetCode/'; then echo "lc=true" >> "$GITHUB_OUTPUT"; fi
if echo "$files" | grep -q '^BaekJoon/'; then echo "bj=true" >> "$GITHUB_OUTPUT"; fi
if echo "$files" | grep -q '^Solvesql/'; then echo "ss=true" >> "$GITHUB_OUTPUT"; fi
# 아래 step에서 fallback된 BEFORE를 쓰도록 outputs로 전달
echo "before=$BEFORE" >> "$GITHUB_OUTPUT"
echo "after=$AFTER" >> "$GITHUB_OUTPUT"
- name: Update BaekJoon README
if: steps.changes.outputs.bj == 'true'
env:
BEFORE: ${{ github.event.before }}
AFTER: ${{ github.sha }}
run: |
python scripts/update_baekjoon_readme.py --before "${{ steps.changes.outputs.before }}" --after "${{ steps.changes.outputs.after }}"
- name: Update LeetCode README
if: steps.changes.outputs.lc == 'true'
env:
BEFORE: ${{ github.event.before }}
AFTER: ${{ github.sha }}
run: |
python scripts/update_leetcode_readme.py --before "${{ steps.changes.outputs.before }}" --after "${{ steps.changes.outputs.after }}"
- name: Update Solvesql README
if: steps.changes.outputs.ss == 'true'
run: |
python scripts/update_solvesql_readme.py --before "${{ steps.changes.outputs.before }}" --after "${{ steps.changes.outputs.after }}"
- name: Commit & push if changed
run: |
if [ -n "$(git status --porcelain)" ]; then # README가 바뀌었을 때만 커밋
git config user.name "github-actions[bot]" # GitHub 공식 bot 계정으로 커밋
git config user.email "github-actions[bot]@users.noreply.github.com"
git add LeetCode/README.md BaekJoon/README.md Solvesql/README.md
git commit -m "chore: auto update READMEs"
git push
fi