Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

Upload a github action artifact to LATEST release #52

Closed
AtiqGauri opened this issue Jul 15, 2020 · 5 comments
Closed

Upload a github action artifact to LATEST release #52

AtiqGauri opened this issue Jul 15, 2020 · 5 comments

Comments

@AtiqGauri
Copy link

AtiqGauri commented Jul 15, 2020

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
Copy link

roostarreksio commented Jul 18, 2020

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
Copy link
Author

AtiqGauri commented Jul 19, 2020

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
Copy link

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
Copy link
Author

AtiqGauri commented Jul 19, 2020

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

@eine
Copy link

eine commented Jul 19, 2020

@AtiqGauri, see #22.

EDIT

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants