name: Cargo Build, Test & Release
on:
push:
branches:
- 'main'
pull_request:
branches:
- 'main'
env:
CARGO_TERM_COLOR: always
jobs:
build_and_test:
name: Rust project - latest
runs-on: ubuntu-latest
strategy:
matrix:
toolchain:
- stable
- beta
- nightly
steps:
- uses: actions/checkout@v3
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- run: cargo build --verbose
- run: cargo test --verbose
create_release:
name: Create a release for a new version of the program
permissions:
contents: write
needs: build_and_test
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.create_tag.outputs.tag }}
id: ${{ steps.create_release.outputs.id }}
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- name: Create tag
id: create_tag
run: |
tag=$(echo -n v ; cargo pkgid | cut -d "@" -f2)
echo "tag=$tag" >> $GITHUB_OUTPUT
- name: Create Release
id: create_release
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.create_tag.outputs.tag }}
makeLatest: true
draft: true
body: Release ${{ steps.create_tag.outputs.tag }}
skipIfReleaseExists: true
update_release:
name: Upload binaries to created release
needs: [build_and_test, create_release]
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- name: Build binaries
run: cargo build --release
- name: Upload files (windows)
if: startsWith(matrix.os, 'windows')
uses: planet-code/upload-to-release-action@1.0.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
asset-path: './target/release/temp-converter.exe'
- name: Upload files (linux)
if: startsWith(matrix.os, 'ubuntu')
uses: planet-code/upload-to-release-action@1.0.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
asset-path: './target/release/temp-converter'
publish_release:
name: Publish created and updated Release
needs: [build_and_test, create_release, update_release]
runs-on: ubuntu-latest
steps:
- name: Publish release
uses: eregon/publish-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ needs.create_release.outputs.id }}