Optimize Your CI/CD Pipeline
Get instant insights into your CI/CD performance and costs. Reduce build times by up to 45% and save on infrastructure costs.
name: Publish to GitHub Release
on:
push:
tags:
- '*'
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --release
- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: target/release/mything
asset_name: mything
tag: ${{ github.ref }}
overwrite: true
body: "This is my release text"
Upload Release Action
This action allows you to upload selected files to a GitHub release upon tagging.
What is upload-release-action?
upload-release-action
will upload selected files as assets of a GitHub release in case a new tag is created. The action also features multiple operating system support and options for tuning the release settings.
How to Use file
The file
input is required to specify which file to upload. Here's how to configure it:
with:
file: target/release/mything
You can also use glob patterns by setting file_glob
to true
:
with:
file: target/release/my*
file_glob: true
How to Customize the Release
You can modify release settings such as prerelease
, draft
, or release_name
. For example, to mark a release as a draft:
with:
draft: true
To explicitly set the release name:
with:
release_name: 'My Custom Release Name'
How to Set Overwrite Mode
If you want to overwrite an existing asset with the same name, set the overwrite
input to true
:
with:
overwrite: true
How to Promote a Pre-Release to a Release
You can promote an existing pre-release to a release by enabling the promote
option:
with:
promote: true
Example: Creating a Release in a Foreign Repository
To create a release in a different GitHub repository, set the repo_name
input and provide a personal access token:
with:
repo_name: owner/repository-name
repo_token: ${{ secrets.YOUR_PERSONAL_ACCESS_TOKEN }}
file: target/release/mything
tag: ${{ github.ref }}
How to Use a File for the Release Body
To dynamically populate the release body from a file in your repository, use the following example:
- name: Read release.md and use it as a body of new release
id: read_release
shell: bash
run: |
r=$(cat path/to/release.md)
r="${r//'%'/'%25'}"
r="${r//$'\n'/'%0A'}"
r="${r//$'\r'/'%0D'}"
echo "RELEASE_BODY=$r" >> $GITHUB_OUTPUT
- name: Upload Binaries to Release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref }}
body: |
${{ steps.read_release.outputs.RELEASE_BODY }}
Outputs
The upload-release-action
provides an output variable, browser_download_url
, which contains the public download URL of the uploaded asset.
steps:
- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: target/release/mything
- run: echo "Download URL: ${{ steps.upload.outputs.browser_download_url }}"
This action ensures that your tagged releases are always up-to-date with the correct binaries or assets, supporting both simple and complex workflows.