• Stars
    star
    163
  • Rank 231,141 (Top 5 %)
  • Language
    Shell
  • License
    Apache License 2.0
  • Created almost 4 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

GitHub Action for building and uploading Rust binary to GitHub Releases.

upload-rust-binary-action

release build status

GitHub Action for building and uploading Rust binary to GitHub Releases.

Usage

This action builds and uploads Rust binary that specified by bin option to GitHub Releases.

Currently, this action is basically intended to be used in combination with an action like create-gh-release-action that creates a GitHub release when a tag is pushed. See also supported events.

Inputs

Name Required Description Type Default
bin true Comma-separated list of binary names (non-extension portion of filename) to build and upload String
token true 1 GitHub token for creating GitHub Releases (see action.yml for more) String
archive false Archive name (non-extension portion of filename) to be uploaded String $bin-$target
target false Target triple, default is host triple String (host triple)
features false Comma-separated list of cargo build features to enable String
no_default_features false Whether to disable cargo build default features Boolean false
tar false On which platform to distribute the .tar.gz file (all, unix, windows, or none) String unix
zip false On which platform to distribute the .zip file (all, unix, windows, or none) String windows
checksum false Comma-separated list of algorithms to be used for checksum (sha256, sha512, sha1, or md5) String
include false Comma-separated list of additional files to be included to the archive String
asset false Comma-separated list of additional files to be uploaded separately String
leading_dir false Whether to create the leading directory in the archive or not Boolean false
build_tool false Tool to build binaries (cargo, cross, or cargo-zigbuild, see cross-compilation example for more) String
ref false Fully-formed tag ref for this release (see action.yml for more) String
manifest_path false Path to Cargo.toml String Cargo.toml
profile false The cargo profile to build. This defaults to the release profile. String release

Example workflow: Basic usage

In this example, when a new tag is pushed, creating a new GitHub Release by using create-gh-release-action, then uploading Rust binary to the created GitHub Release.

An archive file with a name like $bin-$target.tar.gz will be uploaded to GitHub Release.

name: Release

permissions:
  contents: write

on:
  push:
    tags:
      - v[0-9]+.*

jobs:
  create-release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: taiki-e/create-gh-release-action@v1
        with:
          # (optional) Path to changelog.
          changelog: CHANGELOG.md
          # (required) GitHub token for creating GitHub Releases.
          token: ${{ secrets.GITHUB_TOKEN }}

  upload-assets:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: taiki-e/upload-rust-binary-action@v1
        with:
          # (required) Comma-separated list of binary names (non-extension portion of filename) to build and upload.
          # Note that glob pattern is not supported yet.
          bin: ...
          # (required) GitHub token for uploading assets to GitHub Releases.
          token: ${{ secrets.GITHUB_TOKEN }}

You can specify multiple binaries when the root manifest is a virtual manifest or specified binaries are in the same crate.

- uses: taiki-e/upload-rust-binary-action@v1
  with:
    # (required) Comma-separated list of binary names (non-extension portion of filename) to build and upload.
    # Note that glob pattern is not supported yet.
    bin: app1,app2
    # (optional) Archive name (non-extension portion of filename) to be uploaded.
    # [default value: $bin-$target]
    # [possible values: the following variables and any string]
    #   variables:
    #     - $bin    - Binary name (non-extension portion of filename).
    #     - $target - Target triple.
    #     - $tag    - Tag of this release.
    # When multiple binary names are specified, default archive name or $bin variable cannot be used.
    archive: app-$target
    # (required) GitHub token for uploading assets to GitHub Releases.
    token: ${{ secrets.GITHUB_TOKEN }}

Example workflow: Basic usage (multiple platforms)

This action supports Linux, macOS, and Windows as a host OS and supports binaries for various targets.

See also cross-compilation example.

name: Release

permissions:
  contents: write

on:
  push:
    tags:
      - v[0-9]+.*

jobs:
  create-release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: taiki-e/create-gh-release-action@v1
        with:
          # (optional) Path to changelog.
          changelog: CHANGELOG.md
          # (required) GitHub token for creating GitHub Releases.
          token: ${{ secrets.GITHUB_TOKEN }}

  upload-assets:
    strategy:
      matrix:
        os:
          - ubuntu-latest
          - macos-latest
          - windows-latest
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v3
      - uses: taiki-e/upload-rust-binary-action@v1
        with:
          # (required) Comma-separated list of binary names (non-extension portion of filename) to build and upload.
          # Note that glob pattern is not supported yet.
          bin: ...
          # (optional) On which platform to distribute the `.tar.gz` file.
          # [default value: unix]
          # [possible values: all, unix, windows, none]
          tar: unix
          # (optional) On which platform to distribute the `.zip` file.
          # [default value: windows]
          # [possible values: all, unix, windows, none]
          zip: windows
          # (required) GitHub token for uploading assets to GitHub Releases.
          token: ${{ secrets.GITHUB_TOKEN }}

Example workflow: Customize archive name

By default, this action will upload an archive file with a name like $bin-$target.$extension.

You can customize archive name by archive option.

name: Release

permissions:
  contents: write

on:
  push:
    tags:
      - v[0-9]+.*

jobs:
  create-release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: taiki-e/create-gh-release-action@v1
        with:
          # (optional) Path to changelog.
          changelog: CHANGELOG.md
          # (required) GitHub token for creating GitHub Releases.
          token: ${{ secrets.GITHUB_TOKEN }}

  upload-assets:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: taiki-e/upload-rust-binary-action@v1
        with:
          bin: ...
          # (optional) Archive name (non-extension portion of filename) to be uploaded.
          # [default value: $bin-$target]
          # [possible values: the following variables and any string]
          #   variables:
          #     - $bin    - Binary name (non-extension portion of filename).
          #     - $target - Target triple.
          #     - $tag    - Tag of this release.
          # When multiple binary names are specified, default archive name or $bin variable cannot be used.
          archive: $bin-$tag-$target
          # (required) GitHub token for uploading assets to GitHub Releases.
          token: ${{ secrets.GITHUB_TOKEN }}

Example workflow: Build with different features on different platforms

This action enables the systemd and io_uring features for Linux, and leave macOS, and Windows with default set of features.

name: Release

permissions:
  contents: write

on:
  push:
    tags:
      - v[0-9]+.*

jobs:
  create-release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: taiki-e/create-gh-release-action@v1
        with:
          # (optional) Path to changelog.
          changelog: CHANGELOG.md
          # (required) GitHub token for creating GitHub Releases.
          token: ${{ secrets.GITHUB_TOKEN }}

  upload-assets:
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        include:
          - os: ubuntu-latest
            features: systemd,io_uring
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v3
      - uses: taiki-e/upload-rust-binary-action@v1
        with:
          # (required) Comma-separated list of binary names (non-extension portion of filename) to build and upload.
          # Note that glob pattern is not supported yet.
          bin: ...
          # (optional) On which platform to distribute the `.tar.gz` file.
          # [default value: unix]
          # [possible values: all, unix, windows, none]
          tar: unix
          # (optional) On which platform to distribute the `.zip` file.
          # [default value: windows]
          # [possible values: all, unix, windows, none]
          zip: windows
          # (optional) Build with the given set of features if any.
          features: ${{ matrix.features || '' }}
          # (required) GitHub token for uploading assets to GitHub Releases.
          token: ${{ secrets.GITHUB_TOKEN }}

Example workflow: Cross-compilation

cross

By default, this action uses cross for cross-compilation (if cross supports that target). In the following example, only aarch64-unknown-linux-gnu uses cross, the rest use cargo.

If cross is not installed, this action calls cargo install cross --locked to install cross. If you want to speed up the installation of cross or use an older version of cross, consider using install-action.

name: Release

permissions:
  contents: write

on:
  push:
    tags:
      - v[0-9]+.*

jobs:
  create-release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: taiki-e/create-gh-release-action@v1
        with:
          # (optional) Path to changelog.
          changelog: CHANGELOG.md
          # (required) GitHub token for creating GitHub Releases.
          token: ${{ secrets.GITHUB_TOKEN }}

  upload-assets:
    strategy:
      matrix:
        include:
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
          - target: aarch64-apple-darwin
            os: macos-latest
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
          - target: x86_64-apple-darwin
            os: macos-latest
          # Universal macOS binary is supported as universal-apple-darwin.
          - target: universal-apple-darwin
            os: macos-latest
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v3
      - uses: taiki-e/upload-rust-binary-action@v1
        with:
          # (required) Comma-separated list of binary names (non-extension portion of filename) to build and upload.
          # Note that glob pattern is not supported yet.
          bin: ...
          # (optional) Target triple, default is host triple.
          target: ${{ matrix.target }}
          # (required) GitHub token for uploading assets to GitHub Releases.
          token: ${{ secrets.GITHUB_TOKEN }}

setup-cross-toolchain-action

However, if the host has another cross-compilation setup, it will be respected. The following is an example using setup-cross-toolchain-action. In this example, this action uses cargo for all targets.

name: Release

permissions:
  contents: write

on:
  push:
    tags:
      - v[0-9]+.*

jobs:
  create-release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: taiki-e/create-gh-release-action@v1
        with:
          # (optional) Path to changelog.
          changelog: CHANGELOG.md
          # (required) GitHub token for creating GitHub Releases.
          token: ${{ secrets.GITHUB_TOKEN }}

  upload-assets:
    strategy:
      matrix:
        include:
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
          - target: aarch64-apple-darwin
            os: macos-latest
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
          - target: x86_64-apple-darwin
            os: macos-latest
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v3
      - name: Install cross-compilation tools
        uses: taiki-e/setup-cross-toolchain-action@v1
        with:
          target: ${{ matrix.target }}
        if: startsWith(matrix.os, 'ubuntu')
      - uses: taiki-e/upload-rust-binary-action@v1
        with:
          # (required) Comma-separated list of binary names (non-extension portion of filename) to build and upload.
          # Note that glob pattern is not supported yet.
          bin: ...
          # (optional) Target triple, default is host triple.
          target: ${{ matrix.target }}
          # (required) GitHub token for uploading assets to GitHub Releases.
          token: ${{ secrets.GITHUB_TOKEN }}

cargo-zigbuild

if you want to use cargo-zigbuild, if the heuristic to detect host cross-compilation setups does not work well, or if you want to force the use of cargo or cross, you can use the build_tool input option.

If cargo-zigbuild is not installed, this action calls pip3 install cargo-zigbuild to install cargo-zigbuild.

name: Release

on:
  push:
    tags:
      - v[0-9]+.*

jobs:
  create-release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: taiki-e/create-gh-release-action@v1
        with:
          # (optional)
          changelog: CHANGELOG.md
          # (required)
          token: ${{ secrets.GITHUB_TOKEN }}

  upload-assets:
    strategy:
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            build_tool: cargo-zigbuild
          # cargo-zigbuild's glibc version suffix is also supported.
          - target: aarch64-unknown-linux-gnu.2.17
            os: ubuntu-latest
            build_tool: cargo-zigbuild
          - target: aarch64-apple-darwin
            os: macos-latest
            build_tool: cargo
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v3
      - uses: taiki-e/upload-rust-binary-action@v1
        with:
          # (required)
          bin: ...
          # (optional) Target triple, default is host triple.
          target: ${{ matrix.target }}
          # (optional) Tool to build binaries (cargo, cross, or cargo-zigbuild)
          build_tool: ${{ matrix.build_tool }}
          # (required) GitHub token for uploading assets to GitHub Releases.
          token: ${{ secrets.GITHUB_TOKEN }}

Example workflow: Include additional files

If you want include additional file to the archive, you can use the include option.

name: Release

permissions:
  contents: write

on:
  push:
    tags:
      - v[0-9]+.*

jobs:
  create-release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: taiki-e/create-gh-release-action@v1
        with:
          # (optional) Path to changelog.
          changelog: CHANGELOG.md
          # (required) GitHub token for creating GitHub Releases.
          token: ${{ secrets.GITHUB_TOKEN }}

  upload-assets:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: taiki-e/upload-rust-binary-action@v1
        with:
          # (required) Comma-separated list of binary names (non-extension portion of filename) to build and upload.
          # Note that glob pattern is not supported yet.
          bin: ...
          # (optional) Comma-separated list of additional files to be included to archive.
          # Note that glob pattern is not supported yet.
          include: LICENSE,README.md
          # (required) GitHub token for uploading assets to GitHub Releases.
          token: ${{ secrets.GITHUB_TOKEN }}

By default, the expanded archive does not include the leading directory. In the above example, the directory structure of the archive would be as follows:

/<bin>
/LICENSE
/README.md

You can use the leading_dir option to create the leading directory.

- uses: taiki-e/upload-rust-binary-action@v1
  with:
    # (required) Comma-separated list of binary names (non-extension portion of filename) to build and upload.
    # Note that glob pattern is not supported yet.
    bin: ...
    # (optional) Comma-separated list of additional files to be included to archive.
    # Note that glob pattern is not supported yet.
    include: LICENSE,README.md
    # (optional) Whether to create the leading directory in the archive or not. default to false.
    leading_dir: true
    # (required) GitHub token for uploading assets to GitHub Releases.
    token: ${{ secrets.GITHUB_TOKEN }}

In the above example, the directory structure of the archive would be as follows:

/<archive>/
/<archive>/<bin>
/<archive>/LICENSE
/<archive>/README.md

If you want upload additional file separately, you can use the asset option.

upload-assets:
  runs-on: ubuntu-latest
  steps:
    - uses: actions/checkout@v3
    - uses: taiki-e/upload-rust-binary-action@v1
      with:
        # (required) Comma-separated list of binary names (non-extension portion of filename) to build and upload.
        # Note that glob pattern is not supported yet.
        bin: ...
        # (optional) Comma-separated list of additional files to be uploaded separately.
        # Note that glob pattern is not supported yet.
        asset: LICENSE,README.md
        # (required) GitHub token for uploading assets to GitHub Releases.
        token: ${{ secrets.GITHUB_TOKEN }}

In the above example, the following 3 files will be uploaded:

<bin>-<target>.tar.gz
LICENSE
README.md

Other examples

Optimize Rust binary

You can optimize performance or size of Rust binaries by passing the profile options. The profile options can be specified by [profile] table in Cargo.toml, cargo config, environment variables, etc.

The followings are examples to specify profile options:

  • lto

    With profile:

    [profile.release]
    lto = true

    With environment variable:

    env:
      CARGO_PROFILE_RELEASE_LTO: true
  • codegen-units

    With profile:

    [profile.release]
    codegen-units = 1

    With environment variable:

    env:
      CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 1
  • strip

    With profile:

    [profile.release]
    strip = true

Note: Some of these options may increase the build time.

Supported events

The following two events are supported by default:

  • tags (on.push.tags)

    For example:

    on:
      push:
        tags:
          - v[0-9]+.*
  • GitHub release (on.release)

    For example:

    on:
      release:
        types: [created]

You can upload binaries from arbitrary event to arbitrary tag by specifying the ref input option.

For example, to upload binaries to the my_tag tag, specify ref input option as follows:

with:
  ref: refs/tags/my_tag

Compatibility

This action has been tested for GitHub-hosted runners (Ubuntu, macOS, Windows). To use this action in self-hosted runners or in containers, at least the following tools are required:

  • rustup, cargo, rustc
  • bash, GNU Coreutils, GNU grep, GNU tar
  • gh (GitHub CLI)
  • zip (only Unix-like)
  • 7z (only Windows)

Related Projects

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Footnotes

  1. Required one of token input option or GITHUB_TOKEN environment variable. ↩

More Repositories

1

cargo-llvm-cov

Cargo subcommand to easily use LLVM source-based code coverage (-C instrument-coverage).
Rust
741
star
2

pin-project

A crate for safe and ergonomic pin-projection.
Rust
447
star
3

cargo-hack

Cargo subcommand to provide various options useful for testing and continuous integration.
Rust
379
star
4

auto_enums

A library for to allow multiple return types by automatically generated enum.
Rust
303
star
5

install-action

GitHub Action for installing development tools (mainly from GitHub Releases).
Shell
256
star
6

futures-async-stream

Async stream for Rust and the futures crate.
Rust
167
star
7

pin-project-lite

A lightweight version of pin-project written with declarative macros.
Rust
135
star
8

portable-atomic

Portable atomic types including support for 128-bit atomics, atomic float, etc.
Rust
96
star
9

create-gh-release-action

GitHub Action for creating GitHub Releases based on changelog.
Shell
60
star
10

parse-changelog

Simple changelog parser, written in Rust.
Rust
46
star
11

replace-await

Migration tool for replacing await! macro with await syntax.
Rust
41
star
12

cargo-minimal-versions

Cargo subcommand for proper use of -Z minimal-versions and -Z direct-minimal-versions.
Rust
40
star
13

easy-ext

A lightweight attribute macro for easily writing extension trait pattern.
Rust
36
star
14

derive_utils

A procedural macro helper for easily writing custom derives for enums.
Rust
25
star
15

const_fn

A lightweight attribute for easy generation of const functions with conditional compilations.
Rust
23
star
16

atomic-memcpy

Byte-wise atomic memcpy.
Rust
21
star
17

setup-cross-toolchain-action

GitHub Action for setup toolchains for cross compilation and cross testing for Rust.
Shell
21
star
18

syn-serde

Library to serialize and deserialize Syn syntax trees.
Rust
15
star
19

futures-enum

#[derive(Future, Stream, Sink, AsyncRead, AsyncWrite, AsyncSeek, AsyncBufRead)] for enums.
Rust
13
star
20

atomic-maybe-uninit

Atomic operations on potentially uninitialized integers.
Rust
13
star
21

easytime

Providing wrapper types for safely performing panic-free checked arithmetic on instants and durations.
Rust
13
star
22

rust-cross-toolchain

Toolchains for cross compilation and cross testing for Rust.
Shell
12
star
23

cargo-no-dev-deps

Cargo subcommand for running cargo without dev-dependencies.
Rust
11
star
24

cargo-config2

Load and resolve Cargo configuration.
Rust
10
star
25

iter-enum

#[derive(Iterator, DoubleEndedIterator, ExactSizeIterator, FusedIterator, Extend)] for enums.
Rust
9
star
26

negative-impl

Negative trait implementations on stable Rust.
Shell
9
star
27

coverage-helper

Helper for https://github.com/taiki-e/cargo-llvm-cov/issues/123.
Shell
6
star
28

find-crate

Find the crate name from the current Cargo.toml.
Rust
5
star
29

syn-mid

Providing the features between "full" and "derive" of syn.
Rust
5
star
30

assert-unmoved

A type that asserts that the underlying type is not moved after being pinned and mutably accessed.
Rust
4
star
31

cache-cargo-install-action

GitHub Action for `cargo install` with cache.
Shell
4
star
32

io-enum

#[derive(Read, Write, Seek, BufRead)] for enums.
Shell
4
star
33

semihosting

Semihosting for AArch64, ARM, RISC-V, MIPS, and MIPS64
Rust
3
star
34

target-spec-json

Structured access to rustc --print target-spec-json and --print all-target-specs-json.
Rust
2
star
35

build-context

Make build environment/target information available as constants in normal libraries and binaries.
Shell
2
star
36

github-actions

Shell
2
star
37

iced_style_config

Create Iced style sheets from configuration files.
Rust
2
star
38

dependabot-config

Structured access to the Dependabot configuration file.
Rust
2
star
39

taiki-e

1
star
40

workflows

Shell
1
star
41

checkout-action

GitHub Action for checking out a repository. (Simplified actions/checkout alternative without depending on Node.js.)
Shell
1
star
42

test

Shell
1
star
43

dockerfiles

Shell
1
star