Upload a github action artifact to LATEST release

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

I started with github official action upload-release-asset to upload artifact.
It requires a upload_url as an input which tells it the url of release.
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/assets

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…

Hi @AtiqGauri,
You could call this api to get the latest release. There is an action send arbitrary requests to GitHub’s REST API called octokit/request-action. And then you can get the upload_url of it from the response json body. You could set the upload_url to an output variable which could be used in upload-release-asset step.
Please see my example:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Build project # This would actually build your project, using zip for an example artifact
      run: |
          zip --junk-paths my-artifact README.md
    - uses: octokit/request-action@v2.x
      id: get_latest_release
      with:
          route: GET /repos/:repository/releases/latest
          repository: ${{ github.repository }}
      env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    - name: get upload url
      id: get_upload_url
      run: |
        url=$(echo "$response" | jq -r '.upload_url')
        echo "::set-output name=url::$url"
      env: 
          response:  ${{ steps.get_latest_release.outputs.data }}
     
    - name: Upload a Release Asset
      uses: actions/upload-release-asset@v1.0.2
      env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        # The URL for uploading assets to the release
        upload_url:  ${{steps.get_upload_url.outputs.url}}
        # The path to the asset you want to upload
        asset_path: ./my-artifact.zip
        # The name of the asset you want to upload
        asset_name: my-artifact.zip
        # The content-type of the asset you want to upload. See the supported Media Types here: https://www.iana.org/assignments/media-types/media-types.xhtml for more information
        asset_content_type: application/zip
2 Likes

That was really helpfull…

Can you tell me how we can use this action to update/overwrite existing asset of latest release (endpoint: update, delete )

You need follow next steps :

  1. Call latest release API
  2. Add a run step to get the release id from the outputs data of step1 , set it to output variable.
  3. Call list release assets api .
  4. Get the asset id which you want to update or delete using bash script , set asset id to output variable
  5. Use the (endpoint: update, delete ) you mentioned before to update/overwrite existing asset of latest release.

octokit/request-action is for you to send request to API endpoint. You could refer to the examples in its README.md file.

would it be possible to set the ID on upload, so e.g. the latest upload can be with id “package”, and having the filename bear the version including the git hash of the build, like package-1.0-asdf.zst, then package-1.0-qeyd.zsd?