-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
133 lines (110 loc) · 5.6 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: 'Rust GitHub Action'
description: 'Cross-Platform Composite GitHub Action for Rust Workflows'
inputs:
subcommand:
description: 'The cargo or cross subcommand to run. Examples: fmt, clippy, check, test, build, or run'
required: true
default: 'check'
arguments:
description: 'The arguments to specify to the cargo or cross subcommand, as a single string. Example: --workspace'
required: false
default: ''
rust_release_channel:
description: 'Examples: stable, beta, or nightly'
required: false
default: 'stable'
use_cross:
description: 'Use Cross for cross-compilation. Examples: true or false'
required: false
default: 'false'
compilation_target:
description: 'Examples: x86_64-unknown-linux-gnu, x86_64-pc-windows-msvc, or aarch64-apple-darwin. The compilation target overrides the values given for software_platform, and cpu_architecture'
required: false
default: 'x86_64-unknown-linux-gnu'
working_directory:
description: 'The directory within which commands are to be run. Examples: . , ./tests/test_app'
required: false
default: '.'
outputs:
artifact:
description: 'Built Binaries or Documentation uploaded as an artifact'
value: ${{ format('steps.artifact_upload_step.outputs.artifact-{0}-{1}', inputs.subcommand, inputs.compilation_target) }}
runs:
using: "composite"
steps:
- name: 🎟 Checkout Git Repository Step
id: repository_checkout_step
uses: actions/checkout@v4
- name: 🔎🧰 Determine Rust Toolchain components Step
id: rust_toolchain_components_determination_step
shell: bash
run: |
if [ ${{ inputs.subcommand }} = "fmt" ]; then
echo "rust_toolchain_components=cargo,rustfmt" >> "$GITHUB_ENV"
elif [ ${{ inputs.subcommand }} = "clippy" ]; then
echo "rust_toolchain_components=cargo,clippy" >> "$GITHUB_ENV"
elif [ ${{ inputs.subcommand }} = "check" ]; then
echo "rust_toolchain_components=cargo,rustc,rust-std" >> "$GITHUB_ENV"
elif [ ${{ inputs.subcommand }} = "test" ]; then
echo "rust_toolchain_components=cargo,rustc,rust-std" >> "$GITHUB_ENV"
elif [ ${{ inputs.subcommand }} = "doc" ]; then
echo "rust_toolchain_components=cargo,rustc,rust-std,rust-docs" >> "$GITHUB_ENV"
elif [ ${{ inputs.subcommand }} = "build" ]; then
echo "rust_toolchain_components=cargo,rustc,rust-std" >> "$GITHUB_ENV"
elif [ ${{ inputs.subcommand }} = "run" ]; then
echo "rust_toolchain_components=cargo,rustc,rust-std" >> "$GITHUB_ENV"
else
echo "rust_toolchain_components=cargo,rustc,rust-std,rustfmt,rust-docs,clippy,miri" >> "$GITHUB_ENV"
fi
- name: 💿🧰 Install Rust Toolchain Step
id: toolchain_install_step
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ inputs.rust_release_channel }}
targets: ${{ inputs.compilation_target }}
components: ${{ env.rust_toolchain_components }}
- name: 💿🔄 Install Cross-Compilation Tools Step
id: cross_install_step
if: ${{ inputs.use_cross == 'true' }}
uses: taiki-e/install-action@v2
with:
tool: cross
- name: 💿☂️ Install cargo-llvm-cov Step
id: llvm_coverage_install_step
if: ${{ inputs.subcommand == 'llvm-cov' }}
uses: taiki-e/install-action@cargo-llvm-cov
- name: 🏗️🗂 Setup Cache Step
id: cache_setup_step
uses: Swatinem/rust-cache@v2
with:
workspaces: ${{ inputs.working_directory }}
- name: 🚀📦🖥️ Cargo Command Step
id: cargo_command_step
if: ${{ inputs.use_cross != 'true' || inputs.subcommand == 'fmt' }}
shell: bash
run: cd ${{ inputs.working_directory }} && cargo ${{ inputs.subcommand }} ${{ inputs.arguments }}
- name: 🚀🔄🖥️ Cross Command Step
id: cross_command_step
if: ${{ inputs.use_cross == 'true' && inputs.subcommand != 'fmt' }}
shell: bash
run: cd ${{ inputs.working_directory }} && cross ${{ inputs.subcommand }} --target ${{ inputs.compilation_target }} ${{ inputs.arguments }}
- name: 📦🗃️ Gather Outputs
id: outputs_gather_step
shell: bash
run: |
cd ${{ inputs.working_directory }}
mkdir -p target/.dist
[ -d "target/debug" ] && find "target/debug" -maxdepth 1 -type f \( ! -name ".*" ! -name "*.d" ! -name "*.rlib" \) -exec cp "{}" "target/.dist/" \; || true
[ -d "target/release" ] && find "target/release" -maxdepth 1 -type f \( ! -name ".*" ! -name "*.d" ! -name "*.rlib" \) -exec cp "{}" "target/.dist/" \; || true
[ -d "target/doc" ] && cp -a "target/doc/." "target/.dist/" || true
[ -d "target/${{ inputs.compilation_target }}/debug" ] && find "target/${{ inputs.compilation_target }}/debug" -maxdepth 1 -type f \( ! -name ".*" ! -name "*.d" ! -name "*.rlib" \) -exec cp "{}" "target/.dist/" \; || true
[ -d "target/${{ inputs.compilation_target }}/release" ] && find "target/${{ inputs.compilation_target }}/release" -maxdepth 1 -type f \( ! -name ".*" ! -name "*.d" ! -name "*.rlib" \) -exec cp "{}" "target/.dist/" \; || true
[ -d "target/${{ inputs.compilation_target }}/doc" ] && cp -a "target/${{ inputs.compilation_target }}/doc/." "target/.dist/" || true
- name: ⬆️🌐🏺 Upload Artifact Step
id: artifact_upload_step
uses: actions/upload-artifact@v4
with:
name: artifact-${{ inputs.subcommand }}-${{ inputs.compilation_target }}
if-no-files-found: ignore
overwrite: true
path: ${{ inputs.working_directory }}/target/.dist/*