diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index a7bff5b..8863ce4 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -4,99 +4,97 @@ on: push: branches: [main] -env: - PATH: /opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin - ANDROID_HOME: /Users/freetlab/Library/Android/sdk - jobs: - analizar: - name: Análisis de código - runs-on: [self-hosted, macos, arm64, flutter] - steps: - - uses: actions/checkout@v4 - - name: Obtener dependencias - run: flutter pub get - - name: Generar l10n - run: flutter gen-l10n - - name: Analizar código - run: flutter analyze --no-fatal-infos - build: - name: Build APK + AAB release runs-on: [self-hosted, macos, arm64, flutter] - needs: analizar - if: ${{ gitea.ref == 'refs/heads/main' }} steps: - - uses: actions/checkout@v4 - - - name: Bump versión patch + commit + - name: Setup PATH run: | - git config user.name "ShanaiaBot" - git config user.email "shanaia@freetimelab.es" - CURRENT=$(grep '^version:' pubspec.yaml | awk '{print $2}') - SEMVER=$(echo $CURRENT | cut -d'+' -f1) - BUILD=$(echo $CURRENT | cut -d'+' -f2) - MAJOR=$(echo $SEMVER | cut -d. -f1) - MINOR=$(echo $SEMVER | cut -d. -f2) - PATCH=$(echo $SEMVER | cut -d. -f3) - NEW_PATCH=$((PATCH + 1)) - NEW_BUILD=$((BUILD + 1)) - NEW_VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}+${NEW_BUILD}" - sed -i '' "s/^version: .*/version: ${NEW_VERSION}/" pubspec.yaml - git add pubspec.yaml - git commit -m "chore: bump version to ${NEW_VERSION} [ci skip]" - git push origin main - echo "NEW_SEMVER=${MAJOR}.${MINOR}.${NEW_PATCH}" >> $GITHUB_ENV + echo "/opt/homebrew/bin" >> $GITHUB_PATH + echo "/Users/freetlab/.pub-cache/bin" >> $GITHUB_PATH + export PATH="/opt/homebrew/bin:$PATH" - - name: Extraer versión + - name: Checkout + run: | + export PATH="/opt/homebrew/bin:$PATH" + if [ -d ".git" ]; then + git fetch origin main + git checkout main + git reset --hard origin/main + else + git clone http://192.168.0.33:3100/FreeTLab/farolero.git . + fi + + - name: Flutter version + run: | + export PATH="/opt/homebrew/bin:$PATH" + flutter --version + + - name: Get dependencies + run: | + export PATH="/opt/homebrew/bin:$PATH" + flutter pub get + + - name: Generate l10n + run: | + export PATH="/opt/homebrew/bin:$PATH" + flutter gen-l10n + + - name: Analyze + run: | + export PATH="/opt/homebrew/bin:$PATH" + flutter analyze + + - name: Build APK Release + run: | + export PATH="/opt/homebrew/bin:$PATH" + flutter build apk --release + + - name: Build AAB Release + run: | + export PATH="/opt/homebrew/bin:$PATH" + flutter build appbundle --release + + - name: Extract version id: version run: | - VERSION=$(grep '^version:' pubspec.yaml | awk '{print $2}' | cut -d'+' -f1) - COMMIT=$(git rev-parse --short HEAD) - echo "version=$VERSION" >> $GITHUB_OUTPUT - echo "commit=$COMMIT" >> $GITHUB_OUTPUT + VERSION=$(grep 'version:' pubspec.yaml | head -1 | sed 's/version: //' | sed 's/+.*//') + echo "version=v${VERSION}" >> $GITHUB_OUTPUT - - name: Obtener dependencias - run: flutter pub get - - - name: Generar l10n - run: flutter gen-l10n - - - name: Build APK release - run: flutter build apk --release - - - name: Build AAB release - run: flutter build appbundle --release - - - name: Publicar en ftl-builds (Zimaboard) + - name: Deploy to ftl-builds run: | - VERSION="${{ steps.version.outputs.version }}" - APK_NOMBRE="farolero-v${VERSION}.apk" - AAB_NOMBRE="farolero-v${VERSION}.aab" - DESTINO="/opt/ftl-builds/builds/farolero/v${VERSION}" + VERSION=$(grep 'version:' pubspec.yaml | head -1 | sed 's/version: //' | sed 's/+.*//') + VERSION="v${VERSION}" SSH_KEY="/Users/freetlab/.openclaw/workspace/.secure/zimaboard_ed25519" + HOST="192.168.0.33" + USER="ShanaiaBot" + BUILDS_DIR="/opt/ftl-builds/builds/farolero/${VERSION}" - ssh -i "$SSH_KEY" -o StrictHostKeyChecking=no ShanaiaBot@192.168.0.33 "mkdir -p ${DESTINO}" - scp -i "$SSH_KEY" -o StrictHostKeyChecking=no \ + ssh -i "$SSH_KEY" -o StrictHostKeyChecking=no ${USER}@${HOST} "mkdir -p ${BUILDS_DIR}" + + scp -i "$SSH_KEY" \ build/app/outputs/flutter-apk/app-release.apk \ - "ShanaiaBot@192.168.0.33:${DESTINO}/${APK_NOMBRE}" - scp -i "$SSH_KEY" -o StrictHostKeyChecking=no \ - build/app/outputs/bundle/release/app-release.aab \ - "ShanaiaBot@192.168.0.33:${DESTINO}/${AAB_NOMBRE}" - echo "✅ APK: builds.freetimelab.es → farolero → v${VERSION}" - echo "✅ AAB: builds.freetimelab.es → farolero → v${VERSION}" + ${USER}@${HOST}:${BUILDS_DIR}/farolero-${VERSION}.apk - - name: Notificar Telegram + scp -i "$SSH_KEY" \ + build/app/outputs/bundle/release/app-release.aab \ + ${USER}@${HOST}:${BUILDS_DIR}/farolero-${VERSION}.aab + + - name: Notify Telegram if: always() run: | - VERSION="${{ steps.version.outputs.version }}" - COMMIT="${{ steps.version.outputs.commit }}" - BOT_TOKEN=$(plutil -extract 'EnvironmentVariables:TELEGRAM_BOT_TOKEN' raw /Users/freetlab/Library/LaunchAgents/ai.openclaw.gateway.plist 2>/dev/null || echo "") - if [ -z "$BOT_TOKEN" ]; then exit 0; fi + export PATH="/opt/homebrew/bin:$PATH" + VERSION=$(grep 'version:' pubspec.yaml | head -1 | sed 's/version: //' | sed 's/+.*//') + VERSION="v${VERSION}" + BOT_TOKEN=$(plutil -extract ':EnvironmentVariables:TELEGRAM_BOT_TOKEN' raw /Users/freetlab/Library/LaunchAgents/ai.openclaw.gateway.plist 2>/dev/null || echo "") + if [ -z "$BOT_TOKEN" ]; then + echo "No bot token found, skipping notification" + exit 0 + fi if [ "${{ job.status }}" = "success" ]; then - MSG="✅ *Farolero* v${VERSION} build OK · ${COMMIT}%0AAPK + AAB en builds.freetimelab.es" + MSG="✅ Farolero ${VERSION} — Build OK. APK + AAB en builds.freetimelab.es" else - MSG="❌ *Farolero* v${VERSION} build FAILED · ${COMMIT}" + MSG="❌ Farolero ${VERSION} — Build FAILED" fi curl -s -X POST "https://api.telegram.org/bot${BOT_TOKEN}/sendMessage" \ - -d "chat_id=221721467" -d "parse_mode=Markdown" -d "text=${MSG}" || true + -d "chat_id=221721467" -d "text=${MSG}" || true