diff --git a/.gitea/workflows/simplesbentocreation.yml b/.gitea/workflows/simplesbentocreation.yml index 8db9104..f9bd63a 100644 --- a/.gitea/workflows/simplesbentocreation.yml +++ b/.gitea/workflows/simplesbentocreation.yml @@ -13,7 +13,7 @@ jobs: image: catthehacker/ubuntu:act-latest permissions: - contents: read + contents: write # Precisa de write para commitar o manifest.json packages: write steps: @@ -21,59 +21,93 @@ jobs: run: | apt-get update && apt-get install -y curl jq git + # 1. Baixa SEU repositório para ter acesso ao manifest.json e poder commitar depois + - name: Checkout My Repo (SimpleBentoPDF) + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # 2. Verifica o SHA mais recente no GitHub - name: Check Upstream Latest Commit - id: check + id: upstream run: | UPSTREAM_SHA=$(curl -s https://api.github.com/repos/alam00000/bentopdf/commits/main | jq -r .sha | head -c 7) echo "Latest upstream SHA: $UPSTREAM_SHA" echo "sha=$UPSTREAM_SHA" >> $GITHUB_OUTPUT + # 3. Compara com o manifest.json local + - name: Compare with Local Manifest + id: compare + run: | + FILE="manifest.json" + + # Se o arquivo não existir, cria um vazio + if [ ! -f "$FILE" ]; then + echo "{}" > $FILE + fi + + LOCAL_SHA=$(jq -r '.upstream_sha // empty' $FILE) + UPSTREAM_SHA="${{ steps.upstream.outputs.sha }}" + + echo "Local SHA: $LOCAL_SHA" + echo "Remote SHA: $UPSTREAM_SHA" + + if [ "$LOCAL_SHA" == "$UPSTREAM_SHA" ]; then + echo "Versions match. No build required." + echo "skip=true" >> $GITHUB_OUTPUT + else + echo "Versions differ. Build required." + echo "skip=false" >> $GITHUB_OUTPUT + fi + + # 4. Se for diferente, baixa o código original em uma PASTA SEPARADA + - name: Clone Upstream Code (Into Subfolder) + if: steps.compare.outputs.skip == 'false' + run: | + rm -rf upstream_src + git clone --depth 1 --branch main https://github.com/alam00000/bentopdf.git upstream_src + + # 5. Login no Registry - name: Login to Gitea Container Registry + if: steps.compare.outputs.skip == 'false' uses: docker/login-action@v3 with: registry: git.icc.gg username: ${{ gitea.actor }} password: ${{ secrets.CR_PAT }} - - name: Check if Image Already Exists - id: exists - run: | - if docker manifest inspect git.icc.gg/${{ gitea.repository }}:${{ steps.check.outputs.sha }} > /dev/null 2>&1; then - echo "Image for commit ${{ steps.check.outputs.sha }} already exists." - echo "skip=true" >> $GITHUB_OUTPUT - else - echo "New update found (or image missing). Proceeding to build." - echo "skip=false" >> $GITHUB_OUTPUT - fi - - # --- MUDANÇA AQUI: Usamos git clone manual para evitar erro de credencial --- - - name: Clone Upstream Code Manually - if: steps.exists.outputs.skip == 'false' - run: | - # Limpa o diretório atual caso tenha lixo - rm -rf * .git - # Clona o repo público do GitHub sem tentar usar tokens do Gitea - git clone --depth 1 --branch main https://github.com/alam00000/bentopdf.git . - ls -la # Lista para confirmar que baixou - - - name: Inject SIMPLE_MODE into Dockerfile - if: steps.exists.outputs.skip == 'false' - run: | - echo "" >> Dockerfile - echo "ENV SIMPLE_MODE=true" >> Dockerfile - echo "Custom ENV injected successfully." - tail -n 5 Dockerfile - + # 6. Configura Docker Buildx - name: Set up Docker Buildx - if: steps.exists.outputs.skip == 'false' + if: steps.compare.outputs.skip == 'false' uses: docker/setup-buildx-action@v3 + # 7. Build e Push (CORRIGIDO: Usando build-args e context correto) - name: Build and Push Docker Image - if: steps.exists.outputs.skip == 'false' + if: steps.compare.outputs.skip == 'false' uses: docker/build-push-action@v5 with: - context: . + # Aponta para a pasta onde baixamos o código original + context: ./upstream_src push: true + # AQUI ESTÁ A CORREÇÃO DO MODO SIMPLES: + build-args: | + SIMPLE_MODE=true tags: | git.icc.gg/${{ gitea.repository }}:latest - git.icc.gg/${{ gitea.repository }}:${{ steps.check.outputs.sha }} \ No newline at end of file + git.icc.gg/${{ gitea.repository }}:${{ steps.upstream.outputs.sha }} + + # 8. Atualiza o manifest.json e faz Commit de volta no seu repo + - name: Update Manifest and Push Changes + if: steps.compare.outputs.skip == 'false' + run: | + # Configura git para o commit + git config --global user.name "Gitea Actions" + git config --global user.email "actions@git.icc.gg" + + # Atualiza o JSON + echo "{\"upstream_sha\": \"${{ steps.upstream.outputs.sha }}\", \"updated_at\": \"$(date -u)\"}" > manifest.json + + # Commit e Push + git add manifest.json + git commit -m "chore: update manifest to upstream commit ${{ steps.upstream.outputs.sha }}" + git push \ No newline at end of file