-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
action.yml
91 lines (80 loc) · 2.92 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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. This is only used if `use-cross` is enabled. If it is not set, defaults to the newest
stable version of cross.
You can also set the special versions of "main" or "git:xyz" to specify a specific git hash or the current main
branch head 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: |
# Assign inputs to variables if needed
if [[ -z "${{inputs.use-cross}}" || "${{inputs.use-cross}}" != "true" ]]; then
echo "invoker=cargo" >> $GITHUB_OUTPUT;
else
echo "invoker=cross" >> $GITHUB_OUTPUT;
fi
if [[ -n "${{inputs.toolchain}}" ]]; then
echo "toolchain=+${{inputs.toolchain}}" >> $GITHUB_OUTPUT;
fi
- name: Install cross if required.
shell: bash
if: inputs.use-cross == 'true'
run: |
# Install cross
if [[ -n "${{inputs.cross-version}}" ]]; then
if [[ "${{inputs.cross-version}}" == "main" ]]; then
cargo install cross --git https://github.com/cross-rs/cross --branch main
elif [[ "${{inputs.cross-version}}" == "git:"* ]]; then
CROSS_VERSION_ARG="${{inputs.cross-version}}"
CROSS_HASH="${CROSS_VERSION_ARG:4}"
cargo install cross --git https://github.com/cross-rs/cross --rev ${CROSS_HASH}
else
CROSS_VERSION_ARG="--version=${{inputs.cross-version}}";
cargo install cross --locked ${CROSS_VERSION_ARG};
fi
else
# Install whatever is the latest version.
cargo install cross --locked
fi
- name: Execute the cargo/cross command.
shell: bash
run: |
# Execute cargo/cross command
if [[ -n "${{inputs.directory}}" ]]; then
cd ${{inputs.directory}};
fi
echo ${{inputs.args}} | xargs ${{ steps.set-flags.outputs.invoker }} ${{ steps.set-flags.outputs.toolchain }} ${{inputs.command}};