Update move-images.yml

This commit is contained in:
Felipe Santana Soares Silva 2025-11-17 17:38:02 -03:00 committed by GitHub
parent 482e28d904
commit 004838d318
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,47 +6,56 @@ on:
jobs: jobs:
move-images: move-images:
# evita loop: o commit do próprio bot não dispara o job de novo
if: github.actor != 'github-actions[bot]' if: github.actor != 'github-actions[bot]'
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v5 uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Detectar e mover imagens - name: Detectar e mover imagens
run: | run: |
# Arquivos adicionados ou modificados neste push set -e
CHANGED_FILES=$(git diff --name-status HEAD^ HEAD | awk '$1=="A" || $1=="M"{print $2}')
BEFORE_SHA="${{ github.event.before }}"
AFTER_SHA="${{ github.sha }}"
# Se for o primeiro commit da branch, não existe "before":
if [ "$BEFORE_SHA" = "0000000000000000000000000000000000000000" ]; then
echo "Primeiro push da branch, pegando todos os arquivos trackeados."
CHANGED_FILES=$(git ls-files)
else
echo "Diff entre $BEFORE_SHA e $AFTER_SHA"
CHANGED_FILES=$(git diff --name-status "$BEFORE_SHA" "$AFTER_SHA" | awk '$1=="A" || $1=="M"{print $2}')
fi
echo "Arquivos alterados:" echo "Arquivos alterados:"
echo "$CHANGED_FILES" echo "$CHANGED_FILES"
# Filtrar só imagens dentro de content/trilhas # Pega imagens em QUALQUER pasta de content, exceto as que já estão em content/imagens
IMAGES=$(echo "$CHANGED_FILES" | grep -E '^content/trilhas/.*\.(png|jpe?g|gif|svg)$' || true) IMAGES=$(echo "$CHANGED_FILES" | grep -Ei '^content/(?!imagens/).*\.(png|jpe?g|gif|svg)$' || true)
if [ -z "$IMAGES" ]; then if [ -z "$IMAGES" ]; then
echo "Nenhuma imagem em content/trilhas para mover." echo "Nenhuma imagem fora de content/imagens para mover."
exit 0 exit 0
fi fi
for FILE in $IMAGES; do for FILE in $IMAGES; do
# Remove prefixo 'content/' -> fica 'trilhas/02-ia/2025-s1/...' # Remove prefixo 'content/' -> ex: 'trilhas/01-finquant/2025-s1/img.png'
REL_PATH=${FILE#content/} REL_PATH=${FILE#content/}
# Pasta de destino: content/imagens/<mesmo caminho da imagem, sem o nome do arquivo>
# Pasta de destino: content/imagens/trilhas/02-ia/2025-s1/...
DEST_DIR="content/imagens/${REL_PATH%/*}" DEST_DIR="content/imagens/${REL_PATH%/*}"
BASENAME=$(basename "$FILE")
echo "Movendo $FILE -> $DEST_DIR/" echo "Movendo $FILE -> $DEST_DIR/$BASENAME"
mkdir -p "$DEST_DIR" mkdir -p "$DEST_DIR"
git mv "$FILE" "$DEST_DIR/" git mv "$FILE" "$DEST_DIR/$BASENAME"
done done
- name: Commit e push se houve mudança - name: Commit e push se houve mudança
run: | run: |
# Verifica se git mv gerou mudanças no index
if git diff --cached --quiet; then if git diff --cached --quiet; then
echo "Nenhuma alteração para commitar." echo "Nenhuma alteração para commitar."
exit 0 exit 0
@ -54,6 +63,5 @@ jobs:
git config user.name "github-actions[bot]" git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com" git config user.email "github-actions[bot]@users.noreply.github.com"
git commit -m "chore: mover imagens para content/imagens" git commit -m "chore: mover imagens para content/imagens"
git push git push