vane 0.9.2

A flow-based reverse proxy with multi-layer routing and programmable pipelines.
name: Package OpenWrt

on:
  workflow_call:
    inputs:
      ref:
        required: true
        type: string
        description: 'Git ref to checkout (tag or branch)'

jobs:
  build:
    strategy:
      matrix:
        include:
          - arch: x86_64
            sdk_url: https://downloads.openwrt.org/releases/23.05.5/targets/x86/64/openwrt-sdk-23.05.5-x86-64_gcc-12.3.0_musl.Linux-x86_64.tar.xz
            sdk_dir: openwrt-sdk-23.05.5-x86-64_gcc-12.3.0_musl.Linux-x86_64
          - arch: aarch64
            sdk_url: https://downloads.openwrt.org/releases/23.05.5/targets/rockchip/armv8/openwrt-sdk-23.05.5-rockchip-armv8_gcc-12.3.0_musl.Linux-x86_64.tar.xz
            sdk_dir: openwrt-sdk-23.05.5-rockchip-armv8_gcc-12.3.0_musl.Linux-x86_64

    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v6
        with:
          ref: ${{ inputs.ref }}

      - name: Get package info
        id: pkg
        run: |
          BIN_NAME=$(grep -A1 '^\[\[bin\]\]' Cargo.toml | grep '^name' | head -1 | sed 's/.*= *"\([^"]*\)".*/\1/' || true)
          if [ -z "$BIN_NAME" ]; then
            BIN_NAME=$(grep '^name' Cargo.toml | head -1 | sed 's/.*= *"\([^"]*\)".*/\1/')
          fi
          VERSION="${{ inputs.ref }}"
          VERSION="${VERSION#v}"
          echo "bin_name=$BIN_NAME" >> $GITHUB_OUTPUT
          echo "version=$VERSION" >> $GITHUB_OUTPUT

      - name: Download pre-built binary
        uses: actions/download-artifact@v7
        with:
          name: bin-linux-${{ matrix.arch }}
          path: package/openwrt/target

      - name: Download LICENSE
        run: cp LICENSE package/openwrt/LICENSE

      - name: Prepare .env file
        run: cp package/openwrt/.env.example package/openwrt/.env

      - name: Prepare binary
        run: chmod +x package/openwrt/target/${{ steps.pkg.outputs.bin_name }}

      - name: Replace version placeholder in Makefile
        run: |
          sed -i "s/%VERSION%/${{ steps.pkg.outputs.version }}/g" package/openwrt/Makefile

      - name: Download OpenWrt SDK
        run: |
          curl -Lo sdk.tar.xz "${{ matrix.sdk_url }}"
          tar -xf sdk.tar.xz

      - name: Copy package to SDK
        run: |
          cp -r package/openwrt ${{ matrix.sdk_dir }}/package/${{ steps.pkg.outputs.bin_name }}

      - name: Configure SDK
        run: |
          cd ${{ matrix.sdk_dir }}
          # Create minimal config to build the package
          echo "CONFIG_PACKAGE_${{ steps.pkg.outputs.bin_name }}=m" > .config
          make defconfig

      - name: Build IPK
        run: |
          cd ${{ matrix.sdk_dir }}
          make package/${{ steps.pkg.outputs.bin_name }}/compile V=s -j$(nproc)

      - name: Find and rename IPK
        id: ipk
        run: |
          IPK_FILE=$(find ${{ matrix.sdk_dir }}/bin -name "${{ steps.pkg.outputs.bin_name }}*.ipk" | head -1)
          FINAL_NAME="${{ steps.pkg.outputs.bin_name }}-v${{ steps.pkg.outputs.version }}-openwrt-${{ matrix.arch }}.ipk"
          cp "$IPK_FILE" "$FINAL_NAME"
          echo "ipk_name=$FINAL_NAME" >> $GITHUB_OUTPUT

      - name: Upload artifact
        uses: actions/upload-artifact@v6
        with:
          name: ${{ steps.pkg.outputs.bin_name }}-openwrt-${{ matrix.arch }}
          path: ${{ steps.ipk.outputs.ipk_name }}
          retention-days: 1