I want my github action to update the name of a release when it is published using oktokit.rest.repos.updateRelease
Apparently updateRelease requires the release_id. Is there some context variable that contains the release_id during this release publish process? Or do I first need to get a reference to the release using getReleaseByTag instead to get the ID? Maybe getReleaseByTag won't even work until after the release is first published?
update.yaml:
name: update release name
on:
release:
types: [published]
jobs:
update-release-name:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: ????????? <-- NEED RELEASE ID
name: 'Some New Name'
})
CodePudding user response:
You can grab the github release_id by storing it in an environmental variable, and then grabbing the variable in the script for easy access like so:
name: update release name
on:
release:
types: [published]
jobs:
update-release-name:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
env:
RELEASE_ID: ${{ github.event.release.id }}
with:
script: |
const { RELEASE_ID } = process.env
octokit.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: `${RELEASE_ID}`,
name: 'Some New Name'
})