Files
simplebentopdf/.gitea/workflows/simplesbentocreation.yml
2025-12-09 17:07:24 -03:00

118 lines
4.0 KiB
YAML

name: Sync Upstream and Build Docker Image
run-name: Build BentoPDF (Simple Mode) based on Upstream
on:
schedule:
- cron: '0 4 * * *'
workflow_dispatch:
jobs:
check-and-build:
runs-on: ubuntu-latest
container:
image: catthehacker/ubuntu:act-latest
permissions:
contents: write # Precisa de write para commitar o manifest.json
packages: write
steps:
- name: Install dependencies
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: 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 }}
# 6. Configura Docker Buildx
- name: Set up QEMU
if: steps.compare.outputs.skip == 'false'
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
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.compare.outputs.skip == 'false'
uses: docker/build-push-action@v5
with:
# Aponta para a pasta onde baixamos o código original
context: ./upstream_src
platforms: linux/amd64,linux/arm64
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.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