From bb7e4ea01d23d8ea07e9b15bfaab0b49eacc7d42 Mon Sep 17 00:00:00 2001 From: syui Date: Sat, 14 Jun 2025 17:30:00 +0900 Subject: [PATCH] Remove cargo build from Cloudflare Pages workflow and delete build-binary.yml --- .github/workflows/build-binary.yml | 51 ------------------- .github/workflows/cloudflare-pages.yml | 69 +++++++++++++++++++++++--- 2 files changed, 62 insertions(+), 58 deletions(-) delete mode 100644 .github/workflows/build-binary.yml diff --git a/.github/workflows/build-binary.yml b/.github/workflows/build-binary.yml deleted file mode 100644 index bca1300..0000000 --- a/.github/workflows/build-binary.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: Build Binary - -on: - workflow_dispatch: # Manual trigger - push: - branches: [ main ] - paths: - - 'src/**' - - 'Cargo.toml' - - 'Cargo.lock' - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Setup Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - - - name: Cache cargo registry - uses: actions/cache@v4 - with: - path: ~/.cargo/registry - key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} - - - name: Cache cargo index - uses: actions/cache@v4 - with: - path: ~/.cargo/git - key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} - - - name: Cache target directory - uses: actions/cache@v4 - with: - path: target - key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} - - - name: Build binary - run: cargo build --release - - - name: Upload binary - uses: actions/upload-artifact@v4 - with: - name: ailog-linux - path: target/release/ailog - retention-days: 30 \ No newline at end of file diff --git a/.github/workflows/cloudflare-pages.yml b/.github/workflows/cloudflare-pages.yml index 0fe4771..b0f6497 100644 --- a/.github/workflows/cloudflare-pages.yml +++ b/.github/workflows/cloudflare-pages.yml @@ -38,18 +38,73 @@ jobs: cp -r oauth/dist/assets/* my-blog/static/assets/ cp oauth/dist/index.html my-blog/static/oauth/index.html || true - - name: Setup Rust - uses: actions-rs/toolchain@v1 + - name: Cache ailog binary + uses: actions/cache@v4 with: - toolchain: stable - - - name: Build ailog - run: cargo build --release + path: ./bin + key: ailog-bin-${{ runner.os }} + restore-keys: | + ailog-bin-${{ runner.os }} + + - name: Check and update ailog binary + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Get latest release version + LATEST_VERSION=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \ + https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name) + echo "Latest version: $LATEST_VERSION" + + # Check current binary version if exists + mkdir -p ./bin + if [ -f "./bin/ailog" ]; then + CURRENT_VERSION=$(./bin/ailog --version 2>/dev/null || echo "unknown") + echo "Current version: $CURRENT_VERSION" + else + CURRENT_VERSION="none" + echo "No binary found" + fi + + # Download if version is different or binary doesn't exist + if [ "$CURRENT_VERSION" != "${LATEST_VERSION#v}" ]; then + echo "Downloading ailog $LATEST_VERSION..." + # Get download URL for the asset + DOWNLOAD_URL=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \ + https://api.github.com/repos/${{ github.repository }}/releases/tags/$LATEST_VERSION | \ + jq -r '.assets[] | select(.name == "ailog-linux-x86_64.tar.gz") | .url') + + if [ -z "$DOWNLOAD_URL" ] || [ "$DOWNLOAD_URL" = "null" ]; then + echo "Error: Could not find download URL for ailog-linux-x86_64.tar.gz" + exit 1 + fi + + # Download using GitHub API with Accept header + echo "Downloading from: $DOWNLOAD_URL" + curl -L -H "Authorization: Bearer $GITHUB_TOKEN" \ + -H "Accept: application/octet-stream" \ + "$DOWNLOAD_URL" -o ailog-linux-x86_64.tar.gz + + # Check if download was successful + if [ ! -f "ailog-linux-x86_64.tar.gz" ] || [ ! -s "ailog-linux-x86_64.tar.gz" ]; then + echo "Error: Download failed" + exit 1 + fi + + # Extract the binary + tar -xzf ailog-linux-x86_64.tar.gz + mv ailog ./bin/ailog + chmod +x ./bin/ailog + rm ailog-linux-x86_64.tar.gz + echo "Updated to version: $(./bin/ailog --version 2>/dev/null)" + else + echo "Binary is up to date" + chmod +x ./bin/ailog + fi - name: Build site with ailog run: | cd my-blog - ../target/release/ailog build + ../bin/ailog build - name: List public directory run: |