Repository navigation
65 lines (56 loc) · 2.47 KB
/
Copy pathrust-format.yml
File metadata and controls
65 lines (56 loc) · 2.47 KB
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
name: Rust Format
# rustfmt + taplo over the Rust and TOML files a pull request adds or changes
# in the Rust parts of OMCompiler (both cargo workspaces). Files the pull
# request does not touch are not checked.
# Check only: a failing run prints the diff; fix it locally with
# OMCompiler/Compiler/OpenModelica.rs/format.sh FILE...
# or install common/pre-commit.sh, which formats on every commit.
on:
pull_request:
branches:
- master
paths:
- 'OMCompiler/Compiler/OpenModelica.rs/**/*.rs'
- 'OMCompiler/Compiler/OpenModelica.rs/**/*.toml'
- 'OMCompiler/SimulationRuntime/rust/**/*.rs'
- 'OMCompiler/SimulationRuntime/rust/**/*.toml'
permissions:
contents: read
pull-requests: read
env:
TAPLO_VERSION: '0.10.0'
jobs:
rust-format:
name: rustfmt and taplo
runs-on: ubuntu-latest
steps:
# Only the two Rust trees and the files in the repository root.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
sparse-checkout: |
OMCompiler/Compiler/OpenModelica.rs
OMCompiler/SimulationRuntime/rust
# Only rustfmt of the pinned nightly; format.sh selects it through
# RUSTUP_TOOLCHAIN, so the full rust-toolchain.toml (cranelift, wasm
# targets) is never installed.
- name: Install rustfmt
run: |
channel=$(sed -n 's/^channel *= *"\(.*\)"/\1/p' OMCompiler/Compiler/OpenModelica.rs/rust-toolchain.toml)
rustup toolchain install "$channel" --profile minimal --component rustfmt
echo "RUSTUP_TOOLCHAIN=$channel" >> "$GITHUB_ENV"
- name: Install taplo
run: |
mkdir -p "$HOME/.local/bin"
curl -fsSL "https://github.com/tamasfe/taplo/releases/download/${TAPLO_VERSION}/taplo-linux-x86_64.gz" \
| gunzip > "$HOME/.local/bin/taplo"
chmod +x "$HOME/.local/bin/taplo"
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
# format.sh ignores everything that is not a Rust or TOML file of the two
# trees.
- name: Check formatting of the changed files
env:
GH_TOKEN: ${{ github.token }}
PR_FILES: repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files
run: |
gh api --paginate "$PR_FILES" --jq '.[] | select(.status != "removed") | .filename' > "$RUNNER_TEMP/changed-files"
xargs -r -d '\n' OMCompiler/Compiler/OpenModelica.rs/format.sh --check < "$RUNNER_TEMP/changed-files"