Skip to content

feat: Leet_11_Container_With_Most_Water #29

feat: Leet_11_Container_With_Most_Water

feat: Leet_11_Container_With_Most_Water #29

Workflow file for this run

name: Update README
on:
push:
branches: [main]
paths:
- 'src/ver2/**'
jobs:
update-readme:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: code checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: run update_readme.py
run: python scripts/update_readme.py
- name: commit to algorithm repo
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .
git diff --staged --quiet || git commit -m "docs: update README.md"
git push
- name: get latest problem info
id: problem_info
run: |
README_PATH=$(git diff-tree --no-commit-id --name-only -r HEAD | grep "^src/ver2/.*/README.md$" | head -1)
if [ -z "$README_PATH" ]; then
echo "No README found"
exit 0
fi
# 디렉토리 경로 추출
LATEST_DIR=$(dirname "$README_PATH")
if [ ! -d "$LATEST_DIR" ]; then
echo "Directory not found: $LATEST_DIR"
exit 0
fi
README_FILE="$LATEST_DIR/README.md"
if [ ! -f "$README_FILE" ]; then
echo "README file not found: $README_FILE"
exit 0
fi
PROBLEM_TITLE=$(grep -m 1 "^# " "$README_FILE" | sed 's/# //')
FIRST_CATEGORY=$(grep -A 1 "## 카테고리" "$README_FILE" | tail -1 | sed 's/.*`\([^`]*\)`.*/\1/')
ALL_CATEGORIES=$(grep -A 1 "## 카테고리" "$README_FILE" | tail -1 | grep -o '`[^`]*`' | sed 's/`//g')
cat "$README_FILE" > /tmp/problem_readme.md
echo "problem_name=$PROBLEM_TITLE" >> $GITHUB_OUTPUT
echo "first_category=$FIRST_CATEGORY" >> $GITHUB_OUTPUT
echo "all_categories<<EOF" >> $GITHUB_OUTPUT
echo "$ALL_CATEGORIES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "readme_exists=true" >> $GITHUB_OUTPUT
- name: checkout blog repo
if: steps.problem_info.outputs.readme_exists == 'true'
uses: actions/checkout@v4
with:
repository: choijw1004/choijw1004.github.io
token: ${{ secrets.BLOG_PAT }}
path: blog-repo
- name: create blog post with incremental number
if: steps.problem_info.outputs.readme_exists == 'true'
run: |
DATE=$(date +%Y-%m-%d)
DATETIME=$(date +"%Y-%m-%d %H:%M:%S +0900")
cd blog-repo/_posts
LAST_NUM=$(ls ${DATE}-*.md 2>/dev/null | \
sed "s/${DATE}-\([0-9]*\)\.md/\1/" | \
sort -n | \
tail -1)
if [ -z "$LAST_NUM" ]; then
NEXT_NUM=0
else
NEXT_NUM=$((LAST_NUM + 1))
fi
FILENAME="${DATE}-${NEXT_NUM}.md"
cd ../..
cat > blog-repo/_posts/${FILENAME} << EOF
---
layout: post
title: "[Algorithm] ${{ steps.problem_info.outputs.problem_name }}"
description: "${{ steps.problem_info.outputs.problem_name }} 접근방식"
date: ${DATETIME}
tags:
- Algorithm
EOF
echo "${{ steps.problem_info.outputs.all_categories }}" | while IFS= read -r category; do
if [ ! -z "$category" ]; then
echo " - ${category}" >> blog-repo/_posts/${FILENAME}
fi
done
cat >> blog-repo/_posts/${FILENAME} << EOF
author: choijangwoo
toc: true
published: true
categories: [Algorithm, ${{ steps.problem_info.outputs.first_category }}]
---
EOF
cat /tmp/problem_readme.md >> blog-repo/_posts/${FILENAME}
echo "Created: ${FILENAME}"
- name: commit to blog repo
if: steps.problem_info.outputs.readme_exists == 'true'
run: |
cd blog-repo
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .
if git diff --staged --quiet; then
echo "No changes to commit"
else
git pull --rebase origin main # 추가: push 전에 최신 변경사항 가져오기
git commit -m "docs: add algorithm problem post"
git push
fi