Skip to content

Commit

Permalink
Add support for running cargo bench or cross bench
Browse files Browse the repository at this point in the history
  • Loading branch information
RaulTrombin authored and autarch committed Nov 23, 2024
1 parent e35168e commit 8a96988
Show file tree
Hide file tree
Showing 8 changed files with 752 additions and 30 deletions.
60 changes: 35 additions & 25 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
expect_file_re: "x86-64.+FreeBSD"
expect_cross: "--expect-cross"
expect_stripped: "--no-expect-stripped"
can_test: false
can_execute: false

- platform_name: Linux-x86_64
os: ubuntu-20.04
Expand All @@ -27,7 +27,7 @@ jobs:
expect_file_re: "ELF.+x86-64"
expect_cross: "--no-expect-cross"
expect_stripped: "--expect-stripped"
can_test: true
can_execute: true

- platform_name: Linux-aarch64
os: ubuntu-20.04
Expand All @@ -36,7 +36,7 @@ jobs:
expect_file_re: "aarch64"
expect_cross: "--expect-cross"
expect_stripped: "--no-expect-stripped"
can_test: true
can_execute: true

- platform_name: Linux-aarch64 (no cache)
os: ubuntu-20.04
Expand All @@ -45,7 +45,7 @@ jobs:
expect_file_re: "aarch64"
expect_cross: "--expect-cross"
expect_stripped: "--no-expect-stripped"
can_test: true
can_execute: true

- platform_name: Linux-aarch64 with cross v0.2.3
os: ubuntu-20.04
Expand All @@ -56,7 +56,7 @@ jobs:
expect_cross: "--expect-cross"
expect_cross_version: "0.2.3"
expect_stripped: "--no-expect-stripped"
can_test: true
can_execute: true

- platform_name: Linux-aarch64 with cross v0.2.3 (no cache)
os: ubuntu-20.04
Expand All @@ -67,7 +67,7 @@ jobs:
expect_cross: "--expect-cross"
expect_cross_version: "0.2.3"
expect_stripped: "--no-expect-stripped"
can_test: true
can_execute: true

- platform_name: Linux-aarch64 with cross 19be834
os: ubuntu-20.04
Expand All @@ -78,7 +78,7 @@ jobs:
expect_cross: "--expect-cross"
expect_cross_version: "19be834"
expect_stripped: "--no-expect-stripped"
can_test: true
can_execute: true

- platform_name: Linux-aarch64 with cross 19be834
os: ubuntu-20.04
Expand All @@ -89,7 +89,7 @@ jobs:
expect_cross: "--expect-cross"
expect_cross_version: "19be834"
expect_stripped: "--no-expect-stripped"
can_test: true
can_execute: true

- platform_name: Linux-arm
os: ubuntu-20.04
Expand All @@ -98,7 +98,7 @@ jobs:
expect_file_re: "32.+ARM"
expect_cross: "--expect-cross"
expect_stripped: "--no-expect-stripped"
can_test: true
can_execute: true

- platform_name: Linux-i586
os: ubuntu-20.04
Expand All @@ -107,7 +107,7 @@ jobs:
expect_file_re: "ELF.+80386"
expect_cross: "--expect-cross"
expect_stripped: "--no-expect-stripped"
can_test: true
can_execute: true

- platform_name: Linux-i686
os: ubuntu-20.04
Expand All @@ -116,7 +116,7 @@ jobs:
expect_file_re: "ELF.+80386"
expect_cross: "--expect-cross"
expect_stripped: "--no-expect-stripped"
can_test: true
can_execute: true

- platform_name: Linux-powerpc
os: ubuntu-20.04
Expand All @@ -125,7 +125,7 @@ jobs:
expect_file_re: "32.+PowerPC"
expect_cross: "--expect-cross"
expect_stripped: "--no-expect-stripped"
can_test: true
can_execute: true

- platform_name: Linux-powerpc64
os: ubuntu-20.04
Expand All @@ -134,7 +134,7 @@ jobs:
expect_file_re: "64.+PowerPC"
expect_cross: "--expect-cross"
expect_stripped: "--no-expect-stripped"
can_test: true
can_execute: true

- platform_name: Linux-powerpc64le
os: ubuntu-20.04
Expand All @@ -143,7 +143,7 @@ jobs:
expect_file_re: "64.+PowerPC"
expect_cross: "--expect-cross"
expect_stripped: "--no-expect-stripped"
can_test: true
can_execute: true

- platform_name: Linux-riscv64
os: ubuntu-20.04
Expand All @@ -152,7 +152,7 @@ jobs:
expect_file_re: "64.+RISC-V"
expect_cross: "--expect-cross"
expect_stripped: "--no-expect-stripped"
can_test: true
can_execute: true

- platform_name: Linux-s390x
os: ubuntu-20.04
Expand All @@ -161,7 +161,7 @@ jobs:
expect_file_re: "64.+S/390"
expect_cross: "--expect-cross"
expect_stripped: "--no-expect-stripped"
can_test: true
can_execute: true

- platform_name: NetBSD-x86_64
os: ubuntu-20.04
Expand All @@ -170,7 +170,7 @@ jobs:
expect_file_re: "x86-64.+NetBSD"
expect_cross: "--expect-cross"
expect_stripped: "--no-expect-stripped"
can_test: false
can_execute: false

- platform_name: Windows-aarch64
os: windows-latest
Expand All @@ -179,7 +179,7 @@ jobs:
expect_file_re: "Aarch64.+Windows"
expect_cross: "--no-expect-cross"
expect_stripped: "--no-expect-stripped"
can_test: false
can_execute: false

- platform_name: Windows-i686
os: windows-latest
Expand All @@ -188,15 +188,15 @@ jobs:
expect_file_re: "80386.+Windows"
expect_cross: "--no-expect-cross"
expect_stripped: "--expect-stripped"
can_test: true
can_execute: true

- platform_name: Windows-x86_64
os: windows-latest
target: x86_64-pc-windows-msvc
cache-cross-binary: true
expect_file_re: "x86-64.+Windows"
expect_stripped: "--expect-stripped"
can_test: true
can_execute: true

- platform_name: macOS-x86_64
os: macOS-latest
Expand All @@ -205,7 +205,7 @@ jobs:
expect_file_re: "Mach-O.+x86_64"
expect_cross: "--no-expect-cross"
expect_stripped: "--expect-stripped"
can_test: true
can_execute: true

- platform_name: macOS-aarch64
os: macOS-latest
Expand All @@ -214,7 +214,7 @@ jobs:
expect_file_re: "Mach-O.+arm64"
expect_cross: "--no-expect-cross"
expect_stripped: "--expect-stripped"
can_test: false
can_execute: false

runs-on: ${{ matrix.platform.os }}
steps:
Expand All @@ -233,7 +233,7 @@ jobs:
cache-cross-binary: ${{ matrix.platform.cache-cross-binary }}
target: ${{ matrix.platform.target }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: ${{ matrix.platform.can_test }}
if: ${{ matrix.platform.can_execute }}
- name: Run test command
uses: ./
with:
Expand All @@ -242,7 +242,7 @@ jobs:
cache-cross-binary: ${{ matrix.platform.cache-cross-binary }}
target: ${{ matrix.platform.target }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: ${{ matrix.platform.can_test }}
if: ${{ matrix.platform.can_execute }}
- name: Run test command with args
uses: ./
with:
Expand All @@ -252,7 +252,7 @@ jobs:
target: ${{ matrix.platform.target }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
args: "-- --ignored"
if: ${{ matrix.platform.can_test }}
if: ${{ matrix.platform.can_execute }}
- name: Run build command
uses: ./
with:
Expand All @@ -272,6 +272,16 @@ jobs:
target: ${{ matrix.platform.target }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
strip: true
- name: Run bench command
uses: ./
with:
command: bench
cross-version: ${{ matrix.platform.cross-version }}
cache-cross-binary: ${{ matrix.platform.cache-cross-binary }}
target: ${{ matrix.platform.target }}
working-directory: bench
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: ${{ matrix.platform.can_execute }}
- name: Check binary and cross on ${{ matrix.platform.platform_name }}
shell: bash
run: |
Expand Down
5 changes: 5 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.0.17

- Added support for running `cargo bench` or `cross bench`. Implemented by @RaulTrombin (Raul Victor
Trombin). GH #32.

## 0.0.16 - 2024-11-17

- Arguments passed in the `args` parameter are now always last when executing `cargo`. This lets you
Expand Down
26 changes: 21 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ inputs:
default: "."
command:
description: |
The commands to run (one of "build", "test", or "both").
The commands to run. This must be one of "build", "test", "both" (build and test), or "bench".
default: build
target:
description: The target platform
Expand Down Expand Up @@ -91,12 +91,16 @@ runs:
id: set-build-command
shell: bash
run: set-build-command.sh ${{ steps.set-cross-dir.outputs.cross-dir }}
- name: Determine which cargo commands to run
id: determine-cargo-commands
shell: bash
run: determine-cargo-commands.sh ${{ inputs.command }}
- name: Run tests (*nix)
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
${{ steps.set-build-command.outputs.build-command }} +${{inputs.toolchain}} test --target ${{ inputs.target }} ${{ inputs.args }}
if: inputs.command != 'build' && runner.os != 'Windows'
if: steps.determine-cargo-commands.outputs.test == 'true' && runner.os != 'Windows'
# We want to run in Powershell on Windows to make sure we compile in a
# native Windows environment. Some things won't compile properly under
# msys, notably OpenSSL, which is compiled locally when using the
Expand All @@ -106,19 +110,31 @@ runs:
shell: powershell
run: |
& ${{ steps.set-build-command.outputs.build-command }} +${{inputs.toolchain}} test --target ${{ inputs.target }} ${{ inputs.args }}
if: inputs.command != 'build' && runner.os == 'Windows'
if: steps.determine-cargo-commands.outputs.test == 'true' && runner.os == 'Windows'
- name: Run benchmarks (*nix)
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
${{ steps.set-build-command.outputs.build-command }} +${{inputs.toolchain}} bench --target ${{ inputs.target }} ${{ inputs.args }}
if: steps.determine-cargo-commands.outputs.bench == 'true' && runner.os != 'Windows'
- name: Run benchmarks (Windows)
working-directory: ${{ inputs.working-directory }}
shell: powershell
run: |
& ${{ steps.set-build-command.outputs.build-command }} +${{inputs.toolchain}} bench --target ${{ inputs.target }} ${{ inputs.args }}
if: steps.determine-cargo-commands.outputs.bench == 'true' && runner.os == 'Windows'
- name: Build binary (*nix)
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
${{ steps.set-build-command.outputs.build-command }} +${{inputs.toolchain}} build ${{ inputs.args }} --target ${{ inputs.target }}
if: inputs.command != 'test' && runner.os != 'Windows'
if: steps.determine-cargo-commands.outputs.build == 'true' && runner.os != 'Windows'
- name: Build binary (Windows)
working-directory: ${{ inputs.working-directory }}
shell: powershell
run: |
& ${{ steps.set-build-command.outputs.build-command }} +${{inputs.toolchain}} build ${{ inputs.args }} --target ${{ inputs.target }}
if: inputs.command != 'test' && runner.os == 'Windows'
if: steps.determine-cargo-commands.outputs.build == 'true' && runner.os == 'Windows'
- name: Strip binary
working-directory: ${{ inputs.working-directory }}
shell: bash
Expand Down
13 changes: 13 additions & 0 deletions determine-cargo-commands.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

set -e
set -x
set -o pipefail

COMMAND="$1"
if [ "$COMMAND" == 'both' ]; then
echo "build=true" >>"$GITHUB_OUTPUT"
echo "test=true" >>"$GITHUB_OUTPUT"
else
echo "$COMMAND=true" >>"$GITHUB_OUTPUT"
fi
Loading

0 comments on commit 8a96988

Please sign in to comment.