diff --git a/.github/workflows/asd.yaml b/.github/workflows/asd.yaml new file mode 100644 index 0000000..148a630 --- /dev/null +++ b/.github/workflows/asd.yaml @@ -0,0 +1,166 @@ +name: Build and Deploy Packages + +on: + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + PARALLEL: 2 + +permissions: + contents: write + actions: read + checks: read + +jobs: + build_darwin: + runs-on: macos-latest + env: + OS_SUFFIX: -darwin-aarch64 + TARGET: aarch64-apple-darwin + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Make scripts executable + run: chmod +x ./scripts/*.sh + + - name: Run packages script + run: ./scripts/packages.sh + + - name: Upload Mac packages + uses: actions/upload-artifact@v4 + with: + name: darwin-packages + path: ./packages + retention-days: 1 + + build_linux_amd64: + runs-on: ubuntu-latest + env: + OS_SUFFIX: -linux-amd64 + TARGET: x86_64-unknown-linux-gnu + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Make scripts executable + run: chmod +x ./scripts/*.sh + + - name: Run packages script + run: TARGET=x86_64-unknown-linux-gnu ./scripts/packages.sh + + - name: Upload Linux amd64 packages + uses: actions/upload-artifact@v4 + with: + name: linux-amd64-packages + path: ./packages + retention-days: 1 + + build_linux_aarch64: + runs-on: ubuntu-latest + env: + OS_SUFFIX: -linux-aarch64 + TARGET: aarch64-unknown-linux-gnu + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Make scripts executable + run: chmod +x ./scripts/*.sh + + - name: Run packages script + run: TARGET=aarch64-unknown-linux-gnu ./scripts/packages.sh + + - name: Upload Linux aarch64 packages + uses: actions/upload-artifact@v4 + with: + name: linux-aarch64-packages + path: ./packages + retention-days: 1 + + deploy: + needs: + - build_darwin + - build_linux_amd64 + - build_linux_aarch64 + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install dependencies + run: sudo apt-get update && sudo apt-get install -y jq + + - name: Make scripts executable + run: chmod +x ./scripts/*.sh + + - name: Create raw directory + run: mkdir -p raw + + - name: Download Mac packages + uses: actions/download-artifact@v4 + with: + name: darwin-packages + path: darwin-packages + + - name: Download Ubuntu packages + uses: actions/download-artifact@v4 + with: + name: linux-amd64-packages + path: linux-amd64-packages + + - name: Download Linux musl packages + uses: actions/download-artifact@v4 + with: + name: linux-aarch64-packages + path: linux-aarch64-packages + + - name: Move artifacts to raw directory + run: | + # cp darwin-packages/*.tar.gz raw/ || true + cp linux-amd64-packages/*.tar.gz raw/ || true + cp linux-aarch64-packages/*.tar.gz raw/ || true + + - name: Run resolver script + run: ./scripts/resolver-packages-dir.sh + + - name: Setup Git for packages repo + run: | + git config --global user.name "GitHub Actions Bot" + git config --global user.email "actions@github.com" + + - name: Clone packages repository + env: + TOKEN: ${{ secrets.PHLOW_PACKAGES_PAT }} + run: | + git clone https://x-access-token:${TOKEN}@github.com/phlowdotdev/phlow-packages.git + + - name: Update packages repository + env: + GH_TOKEN: ${{ secrets.GH_PAT }} # necessário para o `gh pr create` + run: | + cp -R packages/* phlow-packages/packages/ + cd phlow-packages + git checkout -b update-packages-${{ github.run_id }} + git add . + git commit -m "Update packages from workflow run ${{ github.run_id }}" || echo "No changes to commit" + git push --set-upstream origin update-packages-${{ github.run_id }} + gh pr create --title "Update packages from workflow run ${{ github.run_id }}" --body "Automated package update from workflow run." --base main --head update-packages-${{ github.run_id }} diff --git a/.github/workflows/build-packages.yml b/.github/workflows/build-packages.yml index 8a7e0ef..422eebf 100644 --- a/.github/workflows/build-packages.yml +++ b/.github/workflows/build-packages.yml @@ -19,36 +19,153 @@ jobs: run: | echo "modules=$(ls -d modules/* | xargs -n1 basename | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT - build: - needs: discover_modules + prefetch-linux: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Cache cargo registry (Linux) + uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo-registry- + - name: Cargo fetch (Linux host) + run: cargo fetch --locked + - name: Cargo fetch (Linux amd64 target) + run: cargo fetch --locked --target x86_64-unknown-linux-gnu + - name: Cargo fetch (Linux aarch64 target) + run: cargo fetch --locked --target aarch64-unknown-linux-gnu + + prefetch-macos: + runs-on: macos-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Cache cargo registry (macOS) + uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo-registry- + - name: Cargo fetch (macOS) + run: cargo fetch --locked + + build-macos: + needs: [discover_modules, prefetch-macos] + runs-on: macos-latest strategy: matrix: module: ${{ fromJson(needs.discover_modules.outputs.modules) }} - arch: - - { - name: "macos-latest", - os_suffix: "-darwin-aarch64", - target: "aarch64-apple-darwin", - } - - { - name: "ubuntu-latest", - os_suffix: "-linux-amd64", - target: "x86_64-unknown-linux-gnu", - } - - { - name: "ubuntu-latest", - os_suffix: "-linux-aarch64", - target: "aarch64-unknown-linux-gnu", - } - runs-on: ${{ matrix.arch.name }} env: - OS_SUFFIX: ${{ matrix.arch.os_suffix }} - TARGET: ${{ matrix.arch.target }} + OS_SUFFIX: -darwin-aarch64 + TARGET: aarch64-apple-darwin + MODULE_EXTENSION: dylib steps: - name: Checkout repository uses: actions/checkout@v4 + - name: Restore cargo registry cache (macOS) + uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo-registry- - name: Make scripts executable run: chmod +x ./scripts/*.sh + - name: Install yq (macOS) + run: | + curl -L https://github.com/mikefarah/yq/releases/latest/download/yq_darwin_arm64 -o yq + chmod +x yq + sudo mv yq /usr/local/bin/yq + - name: Install cross + run: cargo install cross --force + - name: Build module + run: ./scripts/packages.sh --single "modules/${{ matrix.module }}" + - name: Upload package artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.module }}${{ env.OS_SUFFIX }} + path: packages/*.tar.gz + retention-days: 1 + + build-linux-amd64: + needs: [discover_modules, prefetch-linux] + runs-on: ubuntu-latest + strategy: + matrix: + module: ${{ fromJson(needs.discover_modules.outputs.modules) }} + env: + OS_SUFFIX: -linux-amd64 + TARGET: x86_64-unknown-linux-gnu + MODULE_EXTENSION: so + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Restore cargo registry cache (Linux) + uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo-registry- + - name: Make scripts executable + run: chmod +x ./scripts/*.sh + - name: Install yq (Linux) + run: | + sudo curl -L https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -o /usr/local/bin/yq + sudo chmod +x /usr/local/bin/yq + - name: Install cross + run: cargo install cross --force + - name: Build module + run: ./scripts/packages.sh --single "modules/${{ matrix.module }}" + - name: Upload package artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.module }}${{ env.OS_SUFFIX }} + path: packages/*.tar.gz + retention-days: 1 + + build-linux-aarch64: + needs: [discover_modules, prefetch-linux] + runs-on: ubuntu-latest + strategy: + matrix: + module: ${{ fromJson(needs.discover_modules.outputs.modules) }} + env: + OS_SUFFIX: -linux-aarch64 + TARGET: aarch64-unknown-linux-gnu + MODULE_EXTENSION: so + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Restore cargo registry cache (Linux) + uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo-registry- + - name: Make scripts executable + run: chmod +x ./scripts/*.sh + - name: Install yq (Linux) + run: | + sudo curl -L https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -o /usr/local/bin/yq + sudo chmod +x /usr/local/bin/yq + - name: Install cross + run: cargo install cross --force - name: Build module run: ./scripts/packages.sh --single "modules/${{ matrix.module }}" - name: Upload package artifact @@ -59,13 +176,18 @@ jobs: retention-days: 1 deploy: - needs: build + needs: + - build-macos + - build-linux-amd64 + - build-linux-aarch64 runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 + - name: Install dependencies run: sudo apt-get update && sudo apt-get install -y jq + - name: Make scripts executable run: chmod +x ./scripts/*.sh - name: Create raw directory @@ -74,8 +196,19 @@ jobs: uses: actions/download-artifact@v4 with: path: raw + merge-multiple: true + - name: List downloaded tarballs + run: | + echo "🔍 Listing tarballs in raw (depth 2)" + find raw -maxdepth 2 -type f -name '*.tar.gz' -print -exec ls -lh {} \; || echo "Nenhum arquivo .tar.gz encontrado" - name: Run resolver script run: ./scripts/resolver-packages-dir.sh + - name: List resolved packages + run: | + echo "🔍 Listing resolved packages (*.tar.gz) under ./packages" + find packages -maxdepth 3 -type f -name '*.tar.gz' -print -exec ls -lh {} \; || echo "Nenhum .tar.gz encontrado em ./packages" + echo "📁 Preview of package directories" + find packages -maxdepth 3 -type d | sort | head -n 200 - name: Setup Git for packages repo run: | git config --global user.name "GitHub Actions Bot" diff --git a/scripts/packages.sh b/scripts/packages.sh index 52ce36f..5711d26 100755 --- a/scripts/packages.sh +++ b/scripts/packages.sh @@ -1,5 +1,3 @@ -echo "📦 Clean folder ./packages" -echo "🎉 All modules packaged successfully!" #!/usr/bin/env bash set -euo pipefail @@ -106,13 +104,23 @@ package_module() { echo "📦 Creating archive: $ARCHIVE_NAME" tar -czf "$ARCHIVE_NAME" -C "$TMP_DIR" . + rm -rf "$TMP_DIR" - cd - > /dev/null + # Diagnóstico: listar arquivos antes do mv + echo "🔍 Diagnostic: ls -l ." + ls -l . + echo "📂 Current directory: $(pwd)" - # Renomeia com OS_SUFFIX + # Renomeia com OS_SUFFIX antes de sair do diretório RENAMED_ARCHIVE="${NAME}-${VERSION}${OS_SUFFIX}.tar.gz" - mv "$MODULE_DIR/$ARCHIVE_NAME" "./packages/$RENAMED_ARCHIVE" + # Verifica se ../../packages existe, se não existir cria + if [ ! -d "../../packages" ]; then + mkdir -p "../../packages" + fi + mv "$ARCHIVE_NAME" "../../packages/$RENAMED_ARCHIVE" + + cd - > /dev/null echo "✅ Module packaged: $RENAMED_ARCHIVE" } @@ -132,7 +140,7 @@ fi # MODO PRINCIPAL: prepara ambiente e dispara empacotamento em paralelo # ------------------------------------------------------------ -cargo install cross || true +# cargo install cross || true # Detect operating system or target # Define OS_SUFFIX, TARGET e MODULE_EXTENSION dinamicamente