AButler / upload-release-assets

GitHub Action to upload assets to a Release
MIT License
57 stars 20 forks source link

Cannot upload assets for release which is being undefined #6

Open liudonghua123 opened 4 years ago

liudonghua123 commented 4 years ago

I have a step like this:

      - uses: AButler/upload-release-assets@v2.0
        with:
          files: '/home/runner/work/github_actions/github_actions/dart-sdk-linux.tar.gz;/home/runner/work/github_actions/github_actions/depot_tools.tar.gz'
          repo-token: ${{ secrets.GITHUB_TOKEN }}

But I got the following error.

 Run AButler/upload-release-assets@v2.01s
##[warning]Cannot upload assets for release which is being undefined
Run AButler/upload-release-assets@v2.0
  with:
    files: /home/runner/work/github_actions/github_actions/dart-sdk-linux.tar.gz;/home/runner/work/github_actions/github_actions/depot_tools.tar.gz
    repo-token: ***
##[warning]Cannot upload assets for release which is being undefined

I can confirm that I pushed a tag instead of a master commit.

AButler commented 4 years ago

The action is mainly set up for creating a GitHub release (which creates a tag) rather than on tag creation. Are you creating a GitHub release in a previous step?

liudonghua123 commented 4 years ago

@AButler I did not create release in previous step.

AButler commented 4 years ago

Ah ok, thanks for the clarification. Currently this action only uploads assets to a release that already exists. I'll take a look at whether it makes sense to create a release if one does not exist already.

mristin commented 4 years ago

Hi @AButler , I'd like to confirm that I observe the same warning / error message (please see https://github.com/admin-shell-io/aasx-package-explorer/runs/986244151?check_suite_focus=true).

The release already exists and the action is triggered afterwards:

on:
  push:
    tags:
      - 'v*'

According to the documentation, the action should be there in github.context.payload: https://developer.github.com/webhooks/event-payloads/#webhook-payload-object-common-properties

Maybe you can output the whole github.context.payload in case github.context.payload is null or undefined to facilitate bug reports?

icemarkom commented 2 years ago

Similar to @mristin, I just hit this in the workflow that had a release created from a tag. At the time this step was running, release existed.

Ogerets commented 2 years ago

same issue here

D4VOS commented 2 years ago

same issue in my project

davidrunger commented 1 year ago

I'm chiming in here in case it helps others. I was getting this error and then fixed it by using the release-tag option.

Here's how I am using this GitHub Action:

  1. create a release manually through the GitHub web app; choose in the GitHub web app when doing so to have GitHub create a git tag for the release.
  2. then, one of my Actions workflows is triggered by the creation of the release tag. That workflow builds release assets, which are uploaded using this action to the release that I just manually created.

I initially was getting this error

 Warning: Cannot upload assets for release which is being undefined

I fixed the error by adding the release-tag option for this GitHub Action:

- name: Release
  uses: AButler/upload-release-assets@v2.0
  with:
    files: skedjewel-${{  github.ref_name }}-linux
    repo-token: ${{ secrets.GITHUB_TOKEN }}
    release-tag: ${{  github.ref_name }}

The value of ${{ github.ref_name }} there is apparently the release tag. That might only be because of how the action is triggered; I'm not sure. Here's how the action is triggered:

on:
  push:
    tags:
      - "v*.*.*"

Now my release assets are uploading successfully. 👍

For reference, click here to see my full GitHub Action workflow Link: https://github.com/davidrunger/skedjewel/blob/v0.0.6/.github/workflows/release.yml ```yml name: Release on: push: tags: - "v*.*.*" jobs: build_and_upload_linux_binary: runs-on: ubuntu-latest container: image: crystallang/crystal:latest-alpine steps: - uses: actions/checkout@v3 - name: Build run: shards build --production --release --no-debug --static - name: Check version matches tag run: "[[ \"v$(bin/skedjewel --version)\" == ${{ github.ref_name }} ]] || exit 1" - name: Move and rename run: mv bin/skedjewel ./skedjewel-${{ github.ref_name }}-linux - name: Release uses: AButler/upload-release-assets@v2.0 with: files: skedjewel-${{ github.ref_name }}-linux repo-token: ${{ secrets.GITHUB_TOKEN }} release-tag: ${{ github.ref_name }} build_and_upload_macos_binary: runs-on: macos-latest steps: - uses: actions/checkout@v3 - name: Install Crystal uses: crystal-lang/install-crystal@v1 - name: Build run: shards build --production --release --no-debug - name: Check version matches tag run: "[[ \"v$(bin/skedjewel --version)\" == ${{ github.ref_name }} ]] || exit 1" - name: Move and rename run: mv bin/skedjewel ./skedjewel-${{ github.ref_name }}-darwin - name: Release uses: AButler/upload-release-assets@v2.0 with: files: skedjewel-${{ github.ref_name }}-darwin repo-token: ${{ secrets.GITHUB_TOKEN }} release-tag: ${{ github.ref_name }} ```
anzz1 commented 1 year ago

I'm having the same problem, is there any action available which would work just like the original upload-release-asset action where you can specify an upload_url instead of tag. Basically an action which allows for multiple files and does not remove any other functionality. I've found many so far but none that actually works like the original.

anzz1 commented 1 year ago

Thanks to this comment I've found a working solution:

    - name: Create release
      id: create_release
      uses: zendesk/action-create-release@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        tag_schema: semantic
        prerelease: true
        auto_increment_type: prerelease

    - name: Upload release
      id: upload_release
      uses: actions/github-script@v3
      with:
        github-token: ${{secrets.GITHUB_TOKEN}}
        script: |
          const path = require('path');
          const fs = require('fs');
          const release_id = '${{ steps.create_release.outputs.id }}';
          for (let file of await fs.readdirSync('./')) {
           if (path.extname(file) === '.zip') {
              console.log('uploadReleaseAsset', file);
              await github.repos.uploadReleaseAsset({
                owner: context.repo.owner,
                repo: context.repo.repo,
                release_id: release_id,
                name: file,
                data: await fs.readFileSync(`./${file}`)
              });
            }
          }

It's not perfect as you still need to write a script and still can't use upload_url but at least you can use release_id so it works with prereleases and everything.