actions / upload-release-asset

An Action to upload a release asset via the GitHub Release API
MIT License
688 stars 190 forks source link

Upload a github action artifact to LATEST release #52

Closed AtiqGauri closed 4 years ago

AtiqGauri commented 4 years ago

I want to upload a artifact to latest release... without creating a new release.

This action rquires a upload_url, which is generally taken from creating a release in previous step with create-release action.

I tried to print output url from create_release- https://uploads.github.com/repos/atiqg/test/releases/28579698/assets{?name,label}

Then I changed it to direct to latest release- https://uploads.github.com/repos/atiqg/test/releases/latest/assests

Which oblivously did not work out and thrown this error- ##[error]Multipart form data required

Is there any way I can do this? I don't want to create a new release from actions. I want to create release normally then action should upload artifact to latest release...

Edit: So I found solution which was getting latest release upload_url from github api

upload_url=$(curl -sL https://api.github.com/repos/actions/checkout/releases/latest | jq -r '.upload_url')
 echo ::set-env name=UPLOAD_URL::$upload_url

But this still fails when there is asset already present with identical name... We need a overwrite option for this

roostarreksio commented 4 years ago

You can do it like this:

    - name: Get upload URL
      id: geturl
      run:   |
         upload_url=$(curl -sL https://api.github.com/repos/${{github.repository}}/releases/latest?access_token=${{ secrets.GITHUB_TOKEN }} | jq -r '.upload_url')
         echo ::set-output name=upload_url::$upload_url
    - name: Upload Release Asset
      id: upload-release-asset 
      uses: actions/upload-release-asset@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        upload_url: ${{ steps.geturl.outputs.upload_url }}
        asset_path: ./my-artifact.zip
        asset_name: my-artifact.zip
        asset_content_type: application/zip

Look here: StackOverflow

AtiqGauri commented 4 years ago

Yes that's me on stackoverflow...

But it's not the perfect answer as it will fail/throw error when there is already an asset with identical name. There is no option for overwrite...

roostarreksio commented 4 years ago

You could theoretically run a job to delete the asset before the upload. I found an action for this. You can do it like this:

    - name: Get Release ID
      id: getid
      run:   |
         rel_id=$(curl -sL https://api.github.com/repos/${{github.repository}}/releases/latest?access_token=${{ secrets.GITHUB_TOKEN }} | jq -r '.id')
         echo ::set-output name=rel_id::$rel_id
    - name: Remove Release Asset
      uses: flcdrg/remove-release-asset-action@v1.0.3
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        release_id: ${{ steps.getid.outputs.rel_id }}
        asset_name: 'asset_name.zip'
AtiqGauri commented 4 years ago

@roostarreksio Hmm it will work I think So, But It would be much cleaner if this actions does it with an optional argument

eine commented 4 years ago

@AtiqGauri, see #22.

EDIT

Oh, I see you already saw it. Sorry for bothering you...