-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6d438d
commit 9abedf8
Showing
5 changed files
with
226 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
name: "Test" | ||
|
||
on: | ||
pull_request: | ||
workflow_dispatch: | ||
workflow_call: | ||
push: | ||
branches: [main] | ||
|
||
jobs: | ||
test-stable: | ||
name: "Test stable toolchain" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Rust toolchain | ||
if: matrix.info.container == '' | ||
uses: dtolnay/rust-toolchain@stable | ||
with: | ||
toolchain: stable | ||
|
||
- name: Enable Rust cache | ||
uses: Swatinem/rust-cache@cb2cf0cc7c5198d3364b9630e2c3d457f160790c # 1.4.0 | ||
|
||
- name: Test simple | ||
uses: ./ | ||
with: | ||
command: build | ||
directory: test/hello_world | ||
|
||
- name: Test args | ||
uses: ./ | ||
with: | ||
command: build | ||
args: --release | ||
directory: test/hello_world | ||
|
||
test-nightly: | ||
name: "Test nightly toolchain" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Rust toolchain | ||
if: matrix.info.container == '' | ||
uses: dtolnay/rust-toolchain@stable | ||
with: | ||
toolchain: nightly | ||
|
||
- name: Enable Rust cache | ||
uses: Swatinem/rust-cache@cb2cf0cc7c5198d3364b9630e2c3d457f160790c # 1.4.0 | ||
|
||
- name: Test simple | ||
uses: ./ | ||
with: | ||
toolchain: nightly | ||
command: build | ||
directory: test/hello_world | ||
|
||
- name: Test args | ||
uses: ./ | ||
with: | ||
toolchain: nightly | ||
command: build | ||
args: --release | ||
directory: test/hello_world | ||
|
||
test-cross: | ||
name: "Test using cross" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Rust toolchain | ||
if: matrix.info.container == '' | ||
uses: dtolnay/rust-toolchain@stable | ||
with: | ||
toolchain: stable | ||
target: aarch64-unknown-linux-gnu | ||
|
||
- name: Enable Rust cache | ||
uses: Swatinem/rust-cache@cb2cf0cc7c5198d3364b9630e2c3d457f160790c # 1.4.0 | ||
|
||
- name: Test simple | ||
uses: ./ | ||
with: | ||
command: build | ||
use-cross: true | ||
cross-version: 0.2.4 | ||
directory: test/hello_world | ||
|
||
- name: Test args | ||
uses: ./ | ||
with: | ||
command: build | ||
args: --release | ||
use-cross: true | ||
cross-version: 0.2.4 | ||
directory: test/hello_world |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,39 @@ | ||
# cargo-action | ||
A simple GitHub Action to invoke cargo and subcommands. | ||
|
||
A simple GitHub Action to invoke cargo/cross and commands. Inspired by the [cargo action from action-rs](https://github.com/actions-rs/cargo), | ||
with [rust-toolchain](https://github.com/dtolnay/rust-toolchain) as reference. | ||
|
||
Written for use in personal projects, though feel free to use it on your own. May or may not work for your use case. | ||
|
||
## Inputs | ||
|
||
**Note: Inputs aren't necessarily checked to be valid!** | ||
|
||
| Name | Description | | ||
| --------------- | --------------------------------------------------------------------------------------------------------------------------- | | ||
| `command` | The `cargo` command to run (e.g. `build`, `test`). Required. | | ||
| `toolchain` | The toolchain to use. Do not include the `+` sign (e.g. `nightly`, `beta`). Defaults to stable. | | ||
| `args` | What arguments to pass to the cargo/cross command. | | ||
| `use-cross` | Whether to use cross instead of using cargo. If enabled, cross will automatically be installed if needed. | | ||
| `cross-version` | The cross version to use. Only used if `use-cross` is enabled. If not set, defaults to the newest stable version of cross. | | ||
| `directory` | Change to the specified directory prior to execution. Useful if your repo's base folder does not contain your Rust project. | | ||
|
||
## Example | ||
|
||
```yaml | ||
name: Test | ||
on: push | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: dtolnay/rust-toolchain@stable | ||
- uses: clementtsang/cargo-action@v1 | ||
with: | ||
command: test | ||
args: --lib --bins --benches | ||
use-cross: true | ||
cross-version: 0.2.4 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
name: cargo action | ||
author: Clement Tsang | ||
description: Invoke cargo/cross and commands. | ||
branding: | ||
icon: box | ||
color: blue | ||
|
||
inputs: | ||
command: | ||
description: The `cargo` command to run (e.g. `build`, `test`). | ||
required: true | ||
|
||
toolchain: | ||
description: The toolchain to use. Do not include the `+` sign (e.g. `nightly`, `beta`). Defaults to stable. | ||
required: false | ||
default: "" | ||
|
||
args: | ||
description: What arguments to pass to the cargo/cross command. | ||
required: false | ||
default: "" | ||
|
||
use-cross: | ||
description: Whether to use cross instead of using cargo. If enabled, cross will automatically be installed if needed. | ||
required: false | ||
default: "false" | ||
|
||
cross-version: | ||
description: > | ||
The cross version to use. Only used if `use-cross` is enabled. If not set, defaults to the newest stable | ||
version of cross. | ||
required: false | ||
default: "" | ||
|
||
directory: | ||
description: > | ||
Change to the specified directory prior to execution. Useful if your repo's base folder does not contain your | ||
Rust project. | ||
required: false | ||
default: "" | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Handle inputs. | ||
id: set-flags | ||
shell: bash | ||
run: | | ||
if [[ ${{inputs.use-cross}} == false ]]; then | ||
echo "::set-output name=invoker::cargo"; | ||
else | ||
echo "::set-output name=invoker::cross"; | ||
fi | ||
if [[ -n "${{inputs.toolchain}}" ]]; then | ||
echo "::set-output name=toolchain::+${{inputs.toolchain}}"; | ||
fi | ||
- name: Install cross if required. | ||
shell: bash | ||
if: inputs.use-cross == 'true' | ||
run: | | ||
if [[ -n "${{inputs.cross-version}}" ]]; then | ||
CROSS_VERSION_ARG="--version=${{inputs.cross-version}}"; | ||
fi | ||
cargo install cross --locked ${CROSS_VERSION_ARG}; | ||
- name: Execute the cargo/cross command. | ||
shell: bash | ||
run: | | ||
if [[ -n "${{inputs.directory}}" ]]; then | ||
cd ${{inputs.directory}}; | ||
fi | ||
${{ steps.set-flags.outputs.invoker }} ${{ steps.set-flags.outputs.toolchain }} ${{inputs.command}} ${{inputs.args}}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "hello_world" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
} |