Sub topic 15
Attaching files to a release
This chapter assumes you can create a release with gh release create and that you know a release is built on a tag. Here you add downloadable files to it.
What release assets are
A release asset is a file attached to a release. Users download assets from the release page, and scripts can fetch them by URL. Typical assets are compiled binaries, installers, and archives.
GitHub also adds two automatic archives, "Source code (zip)" and "Source code (tar.gz)". These are generated from the tagged commit. They are not assets you uploaded, so you cannot delete or replace them.
Attach files when you create the release
List the files after the tag name. Each path becomes one asset.
npm run build
tar -czf dist/app-v1.1.0.tar.gz -C dist app
gh release create v1.1.0 --title "Version 1.1.0" --generate-notes \
dist/app-v1.1.0.tar.gz dist/checksums.txtTo set the label shown on the page, add # and a display name to the path. Quote the argument so the shell does not treat # as a comment.
gh release create v1.1.0 "dist/app.tar.gz#Linux build"Add or replace files later
Use gh release upload on an existing release.
gh release upload v1.1.0 dist/app-windows.zip
gh release upload v1.1.0 dist/app-windows.zip --clobberWithout --clobber, the command fails if an asset with the same name exists. With it, the old file is overwritten. To remove an asset, run gh release delete-asset v1.1.0 app-windows.zip.
Download and inspect assets
gh release view v1.1.0
gh release download v1.1.0 --pattern "*.tar.gz"The --pattern option filters by file name, so you can fetch one asset instead of all of them.
Publish checksums
A checksum is a short fingerprint of a file's contents. Publishing one lets users confirm the download is intact.
cd dist
sha256sum app-v1.1.0.tar.gz > checksums.txt
gh release upload v1.1.0 checksums.txtA user then runs sha256sum -c checksums.txt in the folder with the downloaded files.
Common errors
| Symptom | Cause | Fix |
|---|---|---|
| `release not found` | The release does not exist yet, only the tag does | Run `gh release create` first |
| `asset under the same name already exists` | The file name is already used | Rename the file or add `--clobber` |
| `#` label is ignored or cut off | The argument was not quoted | Wrap the path and label in quotes |
| Upload fails with a size error | A single asset exceeds 2 GiB | Split the file or host it elsewhere |
Exercise
You created release v1.1.0 and forgot to attach app-windows.zip. You rebuilt the file once and uploaded it, then found a bug and rebuilt it again. Which commands add the file the first time and replace it the second time?
Show answer
First run gh release upload v1.1.0 app-windows.zip. For the replacement, run gh release upload v1.1.0 app-windows.zip --clobber. Without --clobber, the second upload fails because the name already exists. Because users may have downloaded the first file, a new patch release is the safer choice.