Skip to content

ci: conditional build #14

ci: conditional build

ci: conditional build #14

Workflow file for this run

name: Release Binaries
on:
push:
branches:
- ci/44-create-prebuilt-binaries-in-gh-action
jobs:
check_version:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Get latest release version
id: latest_version
run: |
LATEST_VERSION=$(curl --silent "https://api.github.com/repos/$GITHUB_REPOSITORY/releases/latest" | jq -r .tag_name)
echo "::set-output name=version::$LATEST_VERSION"
- name: Get version from Cargo.toml
id: cargo_version
run: |
CARGO_VERSION=$(cargo tree --depth 0 | awk 'NR==1 {print $2}')
echo "::set-output name=version::$CARGO_VERSION"
- name: Print version
run: echo "Using version ${{ steps.cargo_version.outputs.version }}"
- name: Compare versions and set result
id: compare
run: |
LATEST_VERSION=${{ steps.latest_version.outputs.version }}
CARGO_VERSION=${{ steps.cargo_version.outputs.version }}
if [[ "$CARGO_VERSION" != "$LATEST_VERSION" ]]; then
echo "::set-output name=should_run::true"
else
echo "::set-output name=should_run::false"
fi
- name: Print output
run: echo "Should run ${{ steps.compare.outputs.should_run }}"
build:
needs: check_version
if: needs.compare.outputs.should_run == 'true'
name: Build on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: macOS-latest
target: x86_64-apple-darwin
- os: windows-latest
target: x86_64-pc-windows-msvc
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Build Release
uses: actions-rs/cargo@v1
with:
command: build
args: --release --target ${{ matrix.target }}
- name: Upload binaries as artifacts
uses: actions/upload-artifact@v2
with:
name: binary-${{ matrix.os }}
path: ./target/${{ matrix.target }}/release/litt${{ matrix.os == 'windows-latest' && '.exe' || '' }}
release:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set version
run: echo "RELEASE_VERSION=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.RELEASE_VERSION }}
release_name: Release ${{ env.RELEASE_VERSION }}
draft: false
prerelease: false
- name: Download binaries from artifacts
uses: actions/download-artifact@v2
with:
name: binary-ubuntu-latest
path: binaries/ubuntu
- name: Download binaries from artifacts
uses: actions/download-artifact@v2
with:
name: binary-macOS-latest
path: binaries/macos
- name: Download binaries from artifacts
uses: actions/download-artifact@v2
with:
name: binary-windows-latest
path: binaries/windows
- name: Upload Release Asset (Ubuntu)
id: upload-release-asset-ubuntu
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: binaries/ubuntu/litt
asset_name: litt-ubuntu-latest
asset_content_type: application/octet-stream
- name: Upload Release Asset (macOS)
id: upload-release-asset-macos
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: binaries/macos/litt
asset_name: litt-macOS-latest
asset_content_type: application/octet-stream
- name: Upload Release Asset (Windows)
id: upload-release-asset-windows
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: binaries/windows/litt.exe
asset_name: litt-windows-latest
asset_content_type: application/octet-stream