Skip to content

Instantly share code, notes, and snippets.

@carlos-a-g-h
Last active March 10, 2023 21:40
Show Gist options
  • Save carlos-a-g-h/c57ea624d39f528ce2ac25525e300753 to your computer and use it in GitHub Desktop.
Save carlos-a-g-h/c57ea624d39f528ce2ac25525e300753 to your computer and use it in GitHub Desktop.
Runs a test for simple one-file-like rust programs
name: Run tests using cargo
on:
workflow_dispatch:
inputs:
RS_FILE:
description: Name of the RS file (without the .RS extension)
required: true
type: string
DO_RUN:
description: Perform a cargo run instead of a test
required: true
type: boolean
default: false
env:
CARGO_TERM_COLOR: always
jobs:
main:
runs-on: ubuntu-latest
steps:
- name: Fetch repo
uses: actions/checkout@v3
- name: Run cargo init
run: |
cargo init --vcs=none "${{ inputs.RS_FILE }}"
mv "${{ inputs.RS_FILE }}".rs "${{ inputs.RS_FILE }}"/src/main.rs
rm *.rs
mv "${{ inputs.RS_FILE }}"/* ./
rmdir "${{ inputs.RS_FILE }}"
printf "\nFiles\n"
find ./|grep -v "^./.git"
- name: Run cargo build
run: cargo build --verbose
- name: Run cargo test (or run)
run: |
COND=${{ inputs.DO_RUN }}
if [ $COND == true ]
then
printf "\nProgram output is below this line\n"
cargo run --verbose
fi
if [ $COND == false ]
then
printf "\nTest results are below this line\n"
cargo test --verbose
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment