Update README - Topic Tags #22
This file contains hidden or 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: LeetHub Move | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| move: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: true | |
| - name: Check LeetHub commit | |
| id: check | |
| run: | | |
| MSG=$(git log -1 --pretty=%B) | |
| if [[ "$MSG" == Time:* && "$MSG" == *"- LeetHub" ]]; then | |
| echo "is_leethub=true" >> $GITHUB_OUTPUT | |
| echo "commit_msg=$MSG" >> $GITHUB_OUTPUT | |
| else | |
| echo "is_leethub=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Detect package | |
| id: detect | |
| if: steps.check.outputs.is_leethub == 'true' | |
| run: | | |
| DIR=$(git diff --name-only HEAD~1 HEAD | awk -F/ 'NF==2 {print $1}' | head -n 1) | |
| echo "package=$DIR" >> $GITHUB_OUTPUT | |
| - name: Extract level | |
| id: level | |
| if: steps.check.outputs.is_leethub == 'true' | |
| run: | | |
| FILE="${{ steps.detect.outputs.package }}/README.md" | |
| if [ -f "$FILE" ]; then | |
| LEVEL=$(grep -oP '(?<=<h3>).*?(?=</h3>)' "$FILE" | head -n 1) | |
| [ -z "$LEVEL" ] && LEVEL="Unknown" | |
| else | |
| LEVEL="Unknown" | |
| fi | |
| echo "level=$LEVEL" >> $GITHUB_OUTPUT | |
| - name: Move to LeetCode folder | |
| if: steps.check.outputs.is_leethub == 'true' | |
| run: | | |
| PKG="${{ steps.detect.outputs.package }}" | |
| LEVEL="${{ steps.level.outputs.level }}" | |
| DEST="LeetCode/$LEVEL" | |
| mkdir -p "$DEST" | |
| mv "$PKG" "$DEST/" | |
| - name: Commit & Push | |
| if: steps.check.outputs.is_leethub == 'true' | |
| run: | | |
| git config user.name "codewith-MJ" | |
| git config user.email "minji.regina.kim@gmail.com" | |
| git add -A | |
| git commit -m "${{ steps.check.outputs.commit_msg }}" || exit 0 | |
| git push |