Time: 0 ms (100.00%) | Memory: 51.1 MB (70.16%) - LeetSync #57
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: Processar Novas Soluções do LeetCode | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| process_and_generate: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout código | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| # --- PASSO 1: ORGANIZA NOVAS PASTAS DA RAIZ --- | |
| - name: Organizar novas soluções | |
| run: | | |
| echo "Procurando por novas soluções na raiz..." | |
| set -x # Ativa o modo debug | |
| for problem_dir in */; do | |
| # Ignora pastas que não são de problemas | |
| if [[ "$problem_dir" == ".git/" || "$problem_dir" == ".github/" || "$problem_dir" == "SQL/" || "$problem_dir" == "Python/" || "$problem_dir" == "CSharp/" ]]; then | |
| continue | |
| fi | |
| base_name=$(basename "$problem_dir") | |
| readme_file="${problem_dir}README.md" | |
| difficulty="" | |
| if [[ -f "$readme_file" ]]; then | |
| difficulty_line=$(grep -o 'Difficulty-Easy\|Difficulty-Medium\|Difficulty-Hard' "$readme_file" | head -n 1) | |
| if [[ -n "$difficulty_line" ]]; then | |
| difficulty=$(echo "$difficulty_line" | cut -d'-' -f2) | |
| else | |
| echo "Dificuldade não encontrada em $base_name. Pulando." | |
| continue | |
| fi | |
| else | |
| echo "README.md não encontrado em $base_name. Pulando." | |
| continue | |
| fi | |
| destination_path="" | |
| if ls "${problem_dir}"*.sql 1> /dev/null 2>&1; then | |
| destination_path="SQL/${difficulty}" | |
| elif ls "${problem_dir}"*.py 1> /dev/null 2>&1; then | |
| destination_path="Python/${difficulty}" | |
| elif ls "${problem_dir}"*.cs 1> /dev/null 2>&1; then | |
| destination_path="CSharp/${difficulty}" | |
| fi | |
| if [[ -n "$destination_path" ]]; then | |
| # Verifica se o diretório de destino JÁ EXISTE para mesclar os arquivos | |
| if [ -d "${destination_path}/${base_name}" ]; then | |
| echo "Solução existente encontrada. Mesclando arquivos para ${destination_path}/${base_name}/" | |
| # Move o CONTEÚDO da pasta de origem para a de destino. | |
| # O `*` garante que o README.md seja sobrescrito e novos arquivos de código sejam adicionados. | |
| git mv -f "${problem_dir}"* "${destination_path}/${base_name}/" | |
| # Remove a pasta de origem que agora está vazia | |
| rmdir "${problem_dir}" | |
| # Se NÃO EXISTE, apenas move a pasta inteira como antes | |
| else | |
| echo "Nova solução. Movendo ${base_name} para ${destination_path}/" | |
| mkdir -p "${destination_path}" | |
| git mv "${problem_dir}" "${destination_path}/" | |
| fi | |
| fi | |
| done | |
| # --- PASSO 2: GERA O README DINÂMICO --- | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.10' | |
| - name: Executar script para gerar o README | |
| run: python generate_readme.py | |
| # --- PASSO 3: FAZ O COMMIT DE TODAS AS ALTERAÇÕES --- | |
| - name: Commitar e fazer push das alterações | |
| uses: stefanzweifel/git-auto-commit-action@v5 | |
| with: | |
| commit_message: "chore(auto): Processa novas soluções e atualiza o README" | |
| commit_user_name: GitHub Actions Bot | |
| commit_user_email: actions-bot@github.com |