name: Ipk
'on':
  push:
    branches:
      - master
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: setup node.js
        uses: actions/setup-node@v2
        with:
          node-version: '16'
      - name: setup dotnet8
        uses: actions/setup-dotnet@v2
        env:
          GITHUB_TOKEN: ${{ secrets.ACTIONS_TOKEN }}
        with:
          dotnet-version: 8.0.x
      - name: setup ipk
        run: sudo apt-get install binutils tar gzip
      - name: chmod shell
        run: sed -i 's/\r$//' publish-ipk.sh
      - name: chmod shell
        run: chmod +x publish-ipk.sh
      - name: publish projects
        run: ./publish-ipk.sh
      - name: Get latest release
        id: get_release
        run: |
          response=$(curl -s \
            -H "Accept: application/vnd.github+json" \
            -H "Authorization: Bearer ${{ secrets.ACTIONS_TOKEN }}" \
            "https://api.github.com/repos/${{ github.repository }}/releases/latest")
          upload_url=$(echo "$response" | jq -r '.upload_url')
          echo "upload_url=$upload_url" >> $GITHUB_OUTPUT
      - name: upload-x64-oss
        id: upload-x64-oss
        uses: tvrcgo/oss-action@v0.1.1
        with:
          region: oss-cn-shenzhen
          key-id: ${{ secrets.ALIYUN_OSS_ID }}
          key-secret: ${{ secrets.ALIYUN_OSS_SECRET }}
          bucket: ide-qbcode
          asset-path: ./public/publish-ipk/x64/linker-x64.ipk
          target-path: /downloads/linker/v1.7.7/linker-x64.ipk
      - name: upload-x64
        id: upload-x64
        uses: actions/upload-release-asset@master
        env:
          GITHUB_TOKEN: ${{ secrets.ACTIONS_TOKEN }}
        with:
          upload_url: ${{ steps.get_release.outputs.upload_url }}
          asset_path: ./public/publish-ipk/x64/linker-x64.ipk
          asset_name: linker-x64.ipk
          asset_content_type: application/ipk
      - name: upload-arm-oss
        id: upload-arm-oss
        uses: tvrcgo/oss-action@v0.1.1
        with:
          region: oss-cn-shenzhen
          key-id: ${{ secrets.ALIYUN_OSS_ID }}
          key-secret: ${{ secrets.ALIYUN_OSS_SECRET }}
          bucket: ide-qbcode
          asset-path: ./public/publish-ipk/arm/linker-arm.ipk
          target-path: /downloads/linker/v1.7.7/linker-arm.ipk
      - name: upload-arm
        id: upload-arm
        uses: actions/upload-release-asset@master
        env:
          GITHUB_TOKEN: ${{ secrets.ACTIONS_TOKEN }}
        with:
          upload_url: ${{ steps.get_release.outputs.upload_url }}
          asset_path: ./public/publish-ipk/arm/linker-arm.ipk
          asset_name: linker-arm.ipk
          asset_content_type: application/ipk
      - name: upload-arm64-oss
        id: upload-arm64-oss
        uses: tvrcgo/oss-action@v0.1.1
        with:
          region: oss-cn-shenzhen
          key-id: ${{ secrets.ALIYUN_OSS_ID }}
          key-secret: ${{ secrets.ALIYUN_OSS_SECRET }}
          bucket: ide-qbcode
          asset-path: ./public/publish-ipk/arm64/linker-arm64.ipk
          target-path: /downloads/linker/v1.7.7/linker-arm64.ipk
      - name: upload-arm64
        id: upload-arm64
        uses: actions/upload-release-asset@master
        env:
          GITHUB_TOKEN: ${{ secrets.ACTIONS_TOKEN }}
        with:
          upload_url: ${{ steps.get_release.outputs.upload_url }}
          asset_path: ./public/publish-ipk/arm64/linker-arm64.ipk
          asset_name: linker-arm64.ipk
          asset_content_type: application/ipk
