Automated GitHub releases for Rust projects using Actions

I've been using GitHub Actions more and more across the projects I maintain. It's a great offering and integrates well into GitHub.

There are a few Rust projects I have where I wanted to automate the publishing of prebuilt binaries to the GitHub releases page. I've seen others do it by using Travis but the setup seemed overly complex.

In order to trigger a release, I just create a tag:

$ git tag v0.1.1

and then push the tag to GitHub:

$ git push --tags

The build begins and the assets are uploaded to the repository. The workflow I used to achieve this is below. Be sure to change the <name> sections to something suitable. I placed the file in .github/workflows/publish.yml.

name: Publish

on:
  push:
    tags:
      - '*'

jobs:
  publish:
    name: Publish for ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        name: [
            linux,
            windows,
            macos
        ]

        include:
          - name: linux
            os: ubuntu-latest
            artifact_name: target/release/<name>
            asset_name: <name>-linux
          - name: windows
            os: windows-latest
            artifact_name: target/release/<name>.exe
            asset_name: <name>-windows
          - name: macos
            os: macos-latest
            artifact_name: target/release/<name>
            asset_name: <name>-macos

    steps:
    - uses: actions/checkout@v1

    - uses: actions-rs/toolchain@v1
      with:
        profile: minimal
        toolchain: stable

    - name: Build
      run: cargo build --release --locked

    - name: Upload binaries to release
      uses: actions/upload-artifact@v2
      with:
        name: ${{ matrix.asset_name }}
        path: ${{ matrix.artifact_name }}