-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
130 lines (122 loc) · 3.8 KB
/
action.yml
File metadata and controls
130 lines (122 loc) · 3.8 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
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
name: "cargo-assist"
author: "Marco Ieni"
description: "GitHub action to automatically format your Rust code"
inputs:
clippy:
description: >
Whether to run `cargo clippy --fix` or not.
Useful if you want to run only `cargo fmt`.
Possible values: `true`, `false`.
Default: `true`.
default: true
required: false
clippy_allow_dirty:
description: >
Whether to add `--allow-dirty` to clippy or not.
Useful if you want to run `cargo clippy --fix` on a dirty repository.
If you run commands before cargo-assist, the repository might be dirty.
Possible values: `true`, `false`.
Default: `false`.
default: false
required: false
clippy_flags:
description: >
Flags to pass to `cargo clippy --fix`.
Default: `--all-targets --all-features --workspace`.
default: "--all-targets --all-features --workspace"
required: false
commit_message:
description: >
Commit message to use when committing the changes.
Default: `chore: format, fix lints`.
default: "chore: format, fix lints"
required: false
fmt:
description: >
Whether to run `cargo fmt` or not.
Useful if you want to run only `cargo clippy --fix`.
Possible values: `true`, `false`.
Default: `true`.
default: true
required: false
github_token:
description: >
GitHub token of the author of the commit.
If you provide `secrets.GITHUB_TOKEN`,
the author of the commit is the github-actions bot.
required: true
working_directory:
description: >
Directory where to run the commands.
Defaults to repository's root.
Useful if your rust project is in a subdirectory.
required: false
branding:
icon: "zap"
color: "yellow"
runs:
using: "composite"
steps:
- name: Configure git user from GitHub token
uses: MarcoIeni/git-config@v0.1
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
- name: Run cargo-assist
shell: bash
run: |
if [[ -n "${{ inputs.working_directory }}" ]]
then
cd "${{ inputs.working_directory }}"
fi
if [[ "${{ inputs.clippy_allow_dirty }}" == true ]]
then
CLIPPY_ALLOW_DIRTY="--allow-dirty"
else
CLIPPY_ALLOW_DIRTY=""
fi
if [[ "${{ inputs.clippy }}" == true ]]
then
CLIPPY_COMMAND="cargo clippy ${{ inputs.clippy_flags }} $CLIPPY_ALLOW_DIRTY --fix"
echo "running '$CLIPPY_COMMAND'"
$CLIPPY_COMMAND
fi
# If repository has uncommitted changes, it means that clippy fixed some lints
if [[ -n $(git status -s) ]]
then
echo "fixed clippy lints"
CLIPPY_FIXED=true
else
CLIPPY_FIXED=false
fi
if [[ "${{ inputs.fmt }}" == true ]]
then
echo "running cargo fmt"
cargo fmt --all
fi
if [[ "${{ inputs.commit_message }}" == "chore: format, fix lints" ]]
then
echo "user didn't specify a custom commit message"
COMMIT_MSG="chore: "
if [[ "${{ inputs.fmt }}" == true ]]
then
COMMIT_MSG="${COMMIT_MSG}format"
if [[ "${CLIPPY_FIXED}" == true ]]
then
COMMIT_MSG="${COMMIT_MSG}, "
fi
fi
if [[ "${CLIPPY_FIXED}" == true ]]
then
COMMIT_MSG="${COMMIT_MSG}fix lints"
fi
else
echo "using custom commit message"
COMMIT_MSG="${{ inputs.commit_message }}"
fi
# If repository has uncommitted changes, commit them
if [[ -n $(git status -s) ]]
then
git add .
git commit -m "$COMMIT_MSG"
git push
fi