action-gh-release icon indicating copy to clipboard operation
action-gh-release copied to clipboard

Document how to upload-only to an already existing release

Open jcornaz opened this issue 3 years ago • 4 comments

Hi,

I am trying to migrate from https://github.com/actions/upload-release-asset as I see it id discontinued and suggest to use this project instead.

But the github release is created by another tool (release-please), and I only need to upload assets.

Is that possible? May I upload assets for a release that is already created?

jcornaz avatar Jan 31 '22 11:01 jcornaz

Have you tried experimenting with this yet. it might just work. this pull attempts to find a release for a ref, and create one off one doesn't exist so that you can rerun a release job if it fails.

I'm wondering if this this would just working given the other action is creating the releases.

I'm not sure about disabling release creation in this action since creating releases is its primary focus.

softprops avatar Jan 31 '22 14:01 softprops

After some trial and errors I finally managed to make it work. Here is how to do:

  • action-gh-release must run on a different workflow reacting on tag push
    • If running in the same workflow that creates the release it fails with: Error: ⚠️ GitHub Releases requires a tag
  • the workflow that creates the tag must use a personal github token (not the GITHUB_TOKEN that is available by default in secrets)
    • Otherwise github prevents the tag created by a workflow to trigger another workflow

So I guess it only needs to be documented?

Though It'd be nice if it could run in the same workflow that creates the github release.

jcornaz avatar Feb 01 '22 08:02 jcornaz

I found a better way! If we have access to the tag of the existing release (release-please has a tag_name output), then we can simply give that as an input to action-gh-release, and it works perfectly fine.

Here's an (over-simplified) example:

name: release

on:
  push:
    branches:
      - main

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2         

      - name: create the release
        uses: google-github-actions/[email protected]
        id: release
        with:
          release-type: rust
      
      - name: build artifacts
        if: steps.release.outputs.release_created
        run: cargo build --release

      - name: upload artifacts
        uses: softprops/action-gh-release@v1
        if: steps.release.outputs.release_created
        with:
          tag_name: ${{ steps.release.outputs.tag_name }} # <-- The solution
          files: target/release/my-app

I renamed this issue as a request for documentation

jcornaz avatar Feb 04 '22 10:02 jcornaz

tag_name: ${{ github.ref_name }} should be enough, so that you can get rid of depending on google-github-actions/release-please-action.

SpriteOvO avatar Oct 13 '23 06:10 SpriteOvO