
on:
 workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
 # This workflow contains a single job called "build"
 uorbuild:
  # The type of runner that the job will run on
  runs-on: ubuntu-latest
  # Steps represent a sequence of tasks that will be executed as part of the job
  steps:
   - uses: actions/checkout@v3
   - name: Run a multi-line script
     run: |
      #proj
      name=`cat debian/changelog | head -1 | grep -o ^[^\ ]*`
      #get up_url
      wget https://github.com/colin-i/test/releases/download/1.5/${name} -O 1.txt
      echo "up_url=`cat 1.txt`" >> $GITHUB_ENV
      #get artifact
      id=$(gh run list --workflow=rpm.yml -b $(git rev-parse --abbrev-ref HEAD) | cut -f7 | head -1)
      repo_at_gh=`cat debian/control | grep "^Homepage" | grep -o [^/]*$`
      #
      url=`gh api -H "Accept: application/vnd.github.v3+json" /repos/colin-i/${repo_at_gh}/actions/runs/${id}/artifacts | jq ".artifacts[0].archive_download_url"`
      url=${url:1:-1}
      echo ${url}
      curl -L -H "Authorization: token ${{ secrets.PAT }}" ${url} --output a.zip
      #to env
      file=`unzip -l a.zip | sed -n 4p | tr -s ' ' | cut -d ' ' -f5`
      unzip ./a.zip
      echo "file=${file}" >> $GITHUB_ENV
     env:
      #for gh
      GITHUB_TOKEN: ${{ secrets.PAT }}
   - name: Upload Release Asset
     uses: actions/upload-release-asset@v1
     env:
      GITHUB_TOKEN: ${{ secrets.PAT }}
     with:
      upload_url: ${{ env.up_url }}
      asset_path: ./${{ env.file }}
      asset_name: ${{ env.file }}
      asset_content_type: application/x-rpm
