Copy Files from TIL #466
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Copy Files from TIL | |
on: | |
schedule: | |
- cron: "0 15 * * *" # 매일 KST 기준 자정에 실행 (UTC 기준 15:00) | |
push: | |
branches: [ main ] | |
jobs: | |
copy_files: | |
env: | |
destination: src/content/docs/TIL | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Clone repository | |
run: | | |
git clone --branch main https://github.com/rlaisqls/TIL.git | |
- name: Add labels | |
run: | | |
add_labels_to_files() { | |
local dir="$1" | |
echo "$dir" | |
cd "$dir" || exit | |
for file in *; do | |
if [ -f "$file" ]; then | |
# title, lastUpdated 속성 추가 | |
echo "---" > tmpfile | |
echo "title: '${file%.*}'" >> tmpfile | |
echo "lastUpdated: $(git log --reverse --format=%cd --date=format:%Y-%m-%dT%H:%M:%S $file | head -n 1)" >> tmpfile | |
echo "---" >> tmpfile | |
cat "$file" >> tmpfile | |
mv tmpfile "$file" | |
elif [ -d "$file" ]; then | |
add_labels_to_files "$dir/$file" | |
cd "$dir" | |
fi | |
done | |
} | |
add_labels_to_files $(pwd)/TIL | |
- name: Copy files | |
run: | | |
rm -rf ${{ env.destination }} | |
mkdir ${{ env.destination }} | |
cp -r TIL/* ${{ env.destination }} | |
rm ${{ env.destination }}/README.md | |
rm ${{ env.destination }}/*.json | |
rm -rf TIL | |
- name: Set current date as env | |
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_ENV | |
- name: Commit and push | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
commit_message: "${{ env.date }} TIL 문서 복사" | |
repository: . | |
branch: main | |
file_pattern: "." | |
push_options: "--force" |