A great way to create releases and other GitHub actions, is the GitHub CLI (gh).
The GitHub workflow already has a GitHub token ${{ secrets.GITHUB_TOKEN }} and you can pass it to the env, the CLI will automatically pick it up.
permissions:
contents: write
jobs:
release:
steps:
- run: |
gh release create v1.2.3 release.tar.xz
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
name: Creates a release in GitHub and uploads attachments
Answer from jessehouwing on Stack OverflowNote: For some reason,
ghwill do one call to see if the file is already uploaded, the another call to upload the file. So I've burned through the API rate limits using this approach trying to attach 500 files to a release. Normally you should be able to do 1000 API calls per hour across workflows.
Videos
A great way to create releases and other GitHub actions, is the GitHub CLI (gh).
The GitHub workflow already has a GitHub token ${{ secrets.GITHUB_TOKEN }} and you can pass it to the env, the CLI will automatically pick it up.
permissions:
contents: write
jobs:
release:
steps:
- run: |
gh release create v1.2.3 release.tar.xz
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
name: Creates a release in GitHub and uploads attachments
Note: For some reason,
ghwill do one call to see if the file is already uploaded, the another call to upload the file. So I've burned through the API rate limits using this approach trying to attach 500 files to a release. Normally you should be able to do 1000 API calls per hour across workflows.
gh is a good solution. Or, if still needed to work with github-script, I confirmed that the following worked somehow (at least for a small file -- not tested with a large file, though), jfyi.
jobs:
publish:
permissions:
contents: write
steps:
# ...
- name: Upload an Asset in GitHub Release
uses: "actions/github-script@v6"
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
script: |
const fs = require('fs').promises;
await github.rest.repos.uploadReleaseAsset({
name: 'README.md',
owner: context.repo.owner,
repo: context.repo.repo,
release_id: ${{ env.RELEASE_ID }},
data: await fs.readFile('./README.md') # The file to upload.
});