actions / create-release

An Action to create releases via the GitHub Release API
MIT License
1.34k stars 303 forks source link

Support for publishing latest draft release #63

Open tayyab-educative opened 4 years ago

tayyab-educative commented 4 years ago

Is it possible to publish the latest draft release with this action? I use actions/release-drafter which automatically adds my latest changes to a draft. I want to use this action to publish that release draft automatically when the workflow is triggered.

mzabaluev commented 4 years ago

Another motivation for this is release notifications. When a release is first created, then assets are uploaded to it, the release notification email lists only the repository source links. It should be possible to upload the assets to a draft release created at an earlier step, then publish the release.

tayyab-educative commented 4 years ago

If there's anyone else looking to publish a draft release, you could use the Github API. You can get all your releases, select the draft release, and update it setting the draft property false. This will publish it.

I'm using this with a cloud function that runs on schedule, so it publishes my release at a regular interval.

mzabaluev commented 4 years ago

@tayyab-anwar Thanks, I guess a workflow can use hub for this, no need for specialized actions.

eine commented 4 years ago

@mzabaluev I tried to do something similar with hub, but I found it to be quite limited. In the end, I used a Python script (https://github.com/eine/tip/blob/master/tip.py). It would be possible to do the same in JavaScript/TypeScript, however with Python there is no need to build/package/transpile the sources.

kmturley commented 4 years ago

Looks like it might be possible using this third-party action: https://github.com/marketplace/actions/publish-release

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
    - name: Create Draft Release
      id: create_release
      uses: actions/create-release@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        tag_name: <tofill>
        release_name: <tofill>
        draft: true
        prerelease: false

    - uses: actions/upload-release-asset@v1.0.1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        upload_url: ${{ steps.create_release.outputs.upload_url }}
        asset_path: ./my-artifact.zip
        asset_name: my-artifact.zip
        asset_content_type: application/zip

    - uses: eregon/publish-release@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        release_id: ${{ steps.create_release.outputs.id }}
kmturley commented 4 years ago

And another potential approach here: https://github.com/actions/virtual-environments/actions/runs/197846688/workflow

name: Update release

on:
  repository_dispatch:
    types: [update-github-release]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2

    - name: Update release for ${{ github.event.client_payload.ReleaseBranchName }}
      uses: actions/github-script@v2
      with:
        github-token: ${{secrets.GITHUB_TOKEN}}
        script: |
            const response = await github.repos.getReleaseByTag({
              owner: context.repo.owner,
              repo: context.repo.repo,
              tag: "${{ github.event.client_payload.ReleaseBranchName }}"
            });
            github.repos.updateRelease({
              owner: context.repo.owner,
              repo: context.repo.repo,
              release_id: response.data.id,
              prerelease: ${{ github.event.client_payload.Prerelease }}
            });