
on:
 workflow_dispatch:
env:
 #for upload
 GITHUB_TOKEN: ${{ secrets.PAT }}

jobs:
 archbuild:
  runs-on: ubuntu-24.04-arm

  steps:
  - name: Checkout
    uses: actions/checkout@v3
    with:
     path: src
  - name: build
    run: |
     sudo apt update
     sudo apt install -y pacman-package-manager qemu-user libc6-i386-cross libc6-amd64-cross makepkg libarchive-tools #libarchive-tools with bsdtar, called at makepkg

     git clone -n --depth=1 --filter=tree:0 https://github.com/colin-i/pkgbuilds
     cd pkgbuilds
     git sparse-checkout set --no-cone /ocompiler
     git checkout
     cd ocompiler
     ver=`cat ./PKGBUILD | grep ^pkgver | grep -Po "(?<==).*"`
     rel=`cat ./PKGBUILD | grep ^pkgrel | grep -Po "(?<==).*"`
     otag=ocompiler-${ver}-${rel}
     cd ../..

     wget https://github.com/colin-i/o/releases/download/${otag}/${otag}-arch-x86_64.pkg.tar.zst
     sudo pacman -U --arch x86_64 --assume-installed lib32-glibc --noconfirm ${otag}-arch-x86_64.pkg.tar.zst

     cd src
     LD_LIBRARY_PATH=/usr/i686-linux-gnu/lib:/usr/x86_64-linux-gnu/lib \
     OCOMP="qemu-i386 /usr/i686-linux-gnu/lib/ld-linux.so.2 /usr/bin/o" \
     OCONV="qemu-amd64 /usr/x86_64-linux-gnu/lib/ld-linux-x86-64.so.2 /usr/bin/otoc" \
     OLINK="qemu-i386 /usr/i686-linux-gnu/lib/ld-linux.so.2 /usr/bin/ounused" \
     make SUBDIRS="dev oad"
     cd csrc
     LD_LIBRARY_PATH=/usr/i686-linux-gnu/lib:/usr/x86_64-linux-gnu/lib \
     OCOMP="qemu-i386 /usr/i686-linux-gnu/lib/ld-linux.so.2 /usr/bin/o" \
     OCONV="qemu-amd64 /usr/x86_64-linux-gnu/lib/ld-linux-x86-64.so.2 /usr/bin/otoc" \
     OLINK="qemu-i386 /usr/i686-linux-gnu/lib/ld-linux.so.2 /usr/bin/ounused" \
     make
     cd ..

     name=`cat debian/changelog | head -1 | grep -o ^[^\ ]*`
     cd ..

     wget https://raw.githubusercontent.com/colin-i/pkgbuilds/refs/heads/main/${name}-`uname -m`/PKGBUILD
     makepkg

     nm=`ls | grep ".*\.gz$"`
     nm2=`echo ${nm} | sed s/-aarch64/-ubuntu-aarch64/` #"; s/${name}/liboadbgdata/"
     mv ${nm} ${nm2}
     echo "file=${nm2}" >> $GITHUB_ENV

     wget https://github.com/colin-i/test/releases/download/1.5/${name} -O 1.txt
     echo "up_url=`cat 1.txt`" >> $GITHUB_ENV
  - name: Upload Release Asset
    uses: actions/upload-release-asset@v1
    with:
     upload_url: ${{ env.up_url }}
     asset_path: ./${{ env.file }}
     asset_name: ${{ env.file }}
     asset_content_type: application/zstd
