Skip to content

Time: 0 ms (100%), Space: 55 MB (13.24%) - LeetHub #10

Time: 0 ms (100%), Space: 55 MB (13.24%) - LeetHub

Time: 0 ms (100%), Space: 55 MB (13.24%) - LeetHub #10

Workflow file for this run

name: Move LeetCode Solutions
permissions:
contents: write
on:
workflow_dispatch:
push:
paths:
- '[0-9][0-9][0-9][0-9]-*/**'
jobs:
move-files:
runs-on: ubuntu-latest
steps:
- name: Checkout repository (full history & creds)
uses: actions/checkout@v3
with:
fetch-depth: 0
persist-credentials: true
ref: ${{ github.ref_name }}
- name: Debug - show root
run: |
echo "### ROOT CONTENTS ###"
ls -la
- name: Wait briefly for LeetHub output (up to 45s)
run: |
set -euo pipefail
MAX_WAIT=45
INTERVAL=3
waited=0
echo "Waiting up to $MAX_WAIT seconds for folders (and possible README) ..."
while [ $waited -lt $MAX_WAIT ]; do
any=0
for d in [0-9][0-9][0-9][0-9]-*; do
if [ -d "$d" ]; then
any=1
# if README appears inside, we can break early
if [ -f "$d/README.md" ] || [ -f "$d/Readme.md" ] || [ -f "$d/readme.md" ]; then
echo "Found $d with README"
exit 0
fi
fi
done
if [ $any -eq 1 ]; then
echo "Found matching dir(s) but README not present yet. waited=${waited}s"
else
echo "No matching dirs yet. waited=${waited}s"
fi
sleep $INTERVAL
waited=$((waited + INTERVAL))
done
echo "Done waiting (may proceed even if README missing)."
ls -la
- name: Move LeetCode solutions (move + debug)
run: |
set -euo pipefail
mkdir -p LeetCode
found=0
for d in [0-9][0-9][0-9][0-9]-*; do
if [ -d "$d" ]; then
echo "==== Moving: $d ===="
ls -la "$d" || true
mv "$d" "LeetCode/" && found=1
echo "After move - LeetCode/$d:"
ls -la "LeetCode/$d" || true
fi
done
if [ $found -eq 0 ]; then
echo "No matching directories found to move"
fi
echo "LeetCode/ listing after move:"
ls -la LeetCode || true
- name: Commit & Push (rebase first; fallback to force-with-lease)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
BRANCH="${{ github.ref_name }}"
echo "Working on branch: $BRANCH"
if git status --porcelain | grep .; then
echo "Changes detected — committing"
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git add -A
git commit -m "chore: Move LeetCode solutions to LeetCode folder" || echo "Nothing to commit"
# 최신 원격 상태 가져오기
git fetch origin "$BRANCH" || true
# rebase가 가능하면 rebase 시도 (충돌 발생 시 중단)
if git rev-parse --verify "origin/$BRANCH" >/dev/null 2>&1; then
echo "Rebasing onto origin/$BRANCH..."
if ! git rebase "origin/$BRANCH"; then
echo "Rebase failed. Aborting rebase and will attempt force push."
git rebase --abort || true
fi
else
echo "origin/$BRANCH does not exist — skipping rebase"
fi
# 일반 푸시 시도
echo "Attempting regular push..."
if git push origin "HEAD:$BRANCH"; then
echo "Push succeeded"
exit 0
fi
# 일반 푸시 실패 시 안전한 강제 푸시 (혼자 쓰는 레포라서 허용)
echo "Regular push failed — attempting git push --force-with-lease"
git push --force-with-lease origin "HEAD:$BRANCH"
echo "Force-with-lease push succeeded"
else
echo "No changes to commit"
fi
- name: Final debug - show LeetCode dir & git status
run: |
echo "=== final LeetCode listing ==="
ls -la LeetCode || true
echo "=== git status ==="
git status --porcelain || true