Skip to content

Rewrite it in Rust

Rewrite it in Rust #19

Workflow file for this run

name: build
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true
jobs:
crate_metadata:
name: Extract crate metadata
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Extract crate information
id: crate_metadata
run: |
cargo metadata --no-deps --format-version 1 | jq -r '"name=" + .packages[0].name' | tee -a $GITHUB_OUTPUT
cargo metadata --no-deps --format-version 1 | jq -r '"version=" + .packages[0].version' | tee -a $GITHUB_OUTPUT
outputs:
name: ${{ steps.crate_metadata.outputs.name }}
version: ${{ steps.crate_metadata.outputs.version }}
format_check:
name: Check formatting
runs-on: ubuntu-latest
steps:
- uses: dtolnay/rust-toolchain@stable
with:
profile: minimal
components: rustfmt
- uses: actions/checkout@v4
- run: cargo fmt -- --check
lint_check:
name: Check clippy warnings
runs-on: ubuntu-latest
steps:
- uses: dtolnay/rust-toolchain@stable
with:
profile: minimal
components: clippy
- uses: actions/checkout@v4
- run: cargo clippy --all-targets --all-features -- -Dwarnings
build:
name: ${{ matrix.job.target }}
runs-on: ${{ matrix.job.os }}
needs: crate_metadata
strategy:
fail-fast: false
matrix:
job:
- { target: i686-pc-windows-msvc, os: windows-latest }
- { target: x86_64-pc-windows-msvc, os: windows-latest }
- { target: x64_64-apple-darwin, os: macos-latest }
- { target: x86_64-unknown-linux-gnu, os: ubuntu-latest }
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.job.target }}
toolchain: nightly
profile: minimal
components: rust-src
override: true
- name: Build
shell: bash
run: cargo build --locked --profile=release-lto --target=${{ matrix.job.target }}
- name: Run tests
shell: bash
run: cargo test --locked --target=${{ matrix.job.target }}
- name: Set up package directory
id: package_dir
shell: bash
run: |
EXE_SUFFIX=""
PKG_SUFFIX=".tar.gz"
case "${{ matrix.job.target }}" in
*-pc-windows-*)
EXE_SUFFIX=".exe"
PKG_SUFFIX=".zip"
;;
esac
BIN_NAME=${{ needs.crate_metadata.outputs.name }}${{ matrix.job.exe_suffix }}
BIN_PATH=target/${{ matrix.job.target }}/release-lto/${BIN_NAME}
PKG_BASENAME=${{ needs.crate_metadata.outputs.name }}-v${{ needs.crate_metadata.outputs.version }}-${{ matrix.job.target }}
PKG_NAME=${PKG_BASENAME}${{ matrix.job.pkg_suffix }}
PKG_BASEDIR=packages
PKG_DIR=${PKG_BASEDIR}/${PKG_BASENAME}
mkdir -p "${PKG_DIR}"
echo "bin_path=${BIN_PATH}" >> $GITHUB_OUTPUT
echo "pkg_basename=${PKG_BASENAME}" >> $GITHUB_OUTPUT
echo "pkg_name=${PKG_NAME}" >> $GITHUB_OUTPUT
echo "pkg_basedir=${PKG_BASEDIR}" >> $GITHUB_OUTPUT
echo "pkg_dir=${PKG_DIR}" >> $GITHUB_OUTPUT
- name: Collect dependency information
shell: bash
run: |
python3 -m pip install license-expression
cargo metadata --format-version=1 \
| python3 scripts/collect-dependencies.py \
-p ${{ needs.crate_metadata.outputs.name }} \
-o ${{ steps.package_dir.outputs.pkg_dir }}
- name: Create release package
id: package
shell: bash
run: |
BIN_PATH="${{ steps.package_dir.outputs.bin_path }}"
PKG_BASENAME="${{ steps.package_dir.outputs.pkg_basename }}"
PKG_NAME="${{ steps.package_dir.outputs.pkg_name }}"
PKG_BASEDIR="${{ steps.package_dir.outputs.pkg_basedir }}"
PKG_DIR="${{ steps.package_dir.outputs.pkg_dir }}"
cp "${BIN_PATH}" "README.md" "LICENSE" "${PKG_DIR}"
pushd "${PKG_BASEDIR}/" >/dev/null
case "${{ matrix.job.target }}" in
*-pc-windows-*) 7z -y a "${PKG_NAME}" "${PKG_BASENAME}/*" | tail -2 ;;
*) tar -czf "${PKG_NAME}" "${PKG_BASENAME}"/* ;;
esac
popd >/dev/null
echo "pkg_path=${PKG_BASEDIR}/${PKG_NAME}" >> $GITHUB_OUTPUT
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.package_dir.outputs.pkg_name }}
path: ${{ steps.package.outputs.pkg_path }}