Skip to content

Commit 4de5c7f

Browse files
committed
GH action: Run rustfmt+cargo autofix when the PR is merged
and stopping showing it at dev phase
1 parent 78d8af9 commit 4de5c7f

File tree

2 files changed

+112
-98
lines changed

2 files changed

+112
-98
lines changed

.github/workflows/CICD.yml

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,6 @@ env:
1717
on: [push, pull_request]
1818

1919
jobs:
20-
code_format:
21-
name: Style/format
22-
runs-on: ${{ matrix.job.os }}
23-
strategy:
24-
fail-fast: false
25-
matrix:
26-
job:
27-
- { os: ubuntu-latest , features: feat_os_unix }
28-
steps:
29-
- uses: actions/checkout@v2
30-
- name: Initialize workflow variables
31-
id: vars
32-
shell: bash
33-
run: |
34-
## VARs setup
35-
outputs() { for var in "$@" ; do echo steps.vars.outputs.${var}="${!var}"; echo ::set-output name=${var}::${!var}; done; }
36-
# target-specific options
37-
# * CARGO_FEATURES_OPTION
38-
CARGO_FEATURES_OPTION='' ;
39-
if [ -n "${{ matrix.job.features }}" ]; then CARGO_FEATURES_OPTION='--features "${{ matrix.job.features }}"' ; fi
40-
outputs CARGO_FEATURES_OPTION
41-
- name: Install `rust` toolchain
42-
uses: actions-rs/toolchain@v1
43-
with:
44-
toolchain: stable
45-
default: true
46-
profile: minimal # minimal component installation (ie, no documentation)
47-
components: rustfmt
48-
- name: "`fmt` testing"
49-
shell: bash
50-
run: |
51-
# `fmt` testing
52-
# * convert any warnings to GHA UI annotations; ref: <https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message>
53-
S=$(cargo fmt -- --check) && printf "%s\n" "$S" || { printf "%s\n" "$S" | sed -E -n -e "s/^Diff[[:space:]]+in[[:space:]]+${PWD//\//\\/}\/(.*)[[:space:]]+at[[:space:]]+[^0-9]+([0-9]+).*$/::warning file=\1,line=\2::WARNING: \`cargo fmt\`: style violation/p" ; }
54-
- name: "`fmt` testing of tests"
55-
shell: bash
56-
run: |
57-
# `fmt` testing of tests
58-
# * convert any warnings to GHA UI annotations; ref: <https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message>
59-
S=$(find tests -name "*.rs" -print0 | xargs -0 cargo fmt -- --check) && printf "%s\n" "$S" || { printf "%s\n" "$S" | sed -E -n "s/^Diff[[:space:]]+in[[:space:]]+${PWD//\//\\/}\/(.*)[[:space:]]+at[[:space:]]+[^0-9]+([0-9]+).*$/::warning file=\1,line=\2::WARNING: \`cargo fmt\`: style violation/p" ; }
6020

6121
code_spellcheck:
6222
name: Style/spelling
@@ -114,64 +74,6 @@ jobs:
11474
# * convert any warnings to GHA UI annotations; ref: <https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message>
11575
S=$(cargo +nightly clippy --all-targets ${{ matrix.job.cargo-options }} ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }} -- -D warnings 2>&1) && printf "%s\n" "$S" || { printf "%s\n" "$S" ; printf "%s" "$S" | sed -E -n -e '/^error:/{' -e "N; s/^error:[[:space:]]+(.*)\\n[[:space:]]+-->[[:space:]]+(.*):([0-9]+):([0-9]+).*$/::warning file=\2,line=\3,col=\4::WARNING: \`cargo clippy\`: \1/p;" -e '}' ; }
11676
117-
min_version:
118-
name: MinRustV # Minimum supported rust version
119-
runs-on: ${{ matrix.job.os }}
120-
strategy:
121-
matrix:
122-
job:
123-
- { os: ubuntu-latest , features: feat_os_unix }
124-
steps:
125-
- uses: actions/checkout@v2
126-
- name: Install `rust` toolchain (v${{ env.RUST_MIN_SRV }})
127-
uses: actions-rs/toolchain@v1
128-
with:
129-
toolchain: ${{ env.RUST_MIN_SRV }}
130-
default: true
131-
profile: minimal # minimal component installation (ie, no documentation)
132-
- name: Install `cargo-tree` # for dependency information
133-
uses: actions-rs/install@v0.1
134-
with:
135-
crate: cargo-tree
136-
version: latest
137-
use-tool-cache: true
138-
env:
139-
RUSTUP_TOOLCHAIN: stable
140-
- name: Confirm compatible 'Cargo.lock'
141-
shell: bash
142-
run: |
143-
# Confirm compatible 'Cargo.lock'
144-
# * 'Cargo.lock' is required to be in a format that `cargo` of MinSRV can interpret (eg, v1-format for MinSRV < v1.38)
145-
cargo fetch --locked --quiet || { echo "::error file=Cargo.lock::Incompatible 'Cargo.lock' format; try \`cargo +${{ env.RUST_MIN_SRV }} update\`" ; exit 1 ; }
146-
- name: Info
147-
shell: bash
148-
run: |
149-
# Info
150-
## environment
151-
echo "## environment"
152-
echo "CI='${CI}'"
153-
## tooling info display
154-
echo "## tooling"
155-
which gcc >/dev/null 2>&1 && (gcc --version | head -1) || true
156-
rustup -V
157-
rustup show active-toolchain
158-
cargo -V
159-
rustc -V
160-
cargo-tree tree -V
161-
## dependencies
162-
echo "## dependency list"
163-
cargo fetch --locked --quiet
164-
## * using the 'stable' toolchain is necessary to avoid "unexpected '--filter-platform'" errors
165-
RUSTUP_TOOLCHAIN=stable cargo-tree tree --frozen --all --no-dev-dependencies --no-indent --features ${{ matrix.job.features }} | grep -vE "$PWD" | sort --unique
166-
167-
- name: Test
168-
uses: actions-rs/cargo@v1
169-
with:
170-
command: test
171-
args: --features "feat_os_unix" -p uucore -p coreutils
172-
env:
173-
RUSTFLAGS: '-Awarnings'
174-
17577
busybox_test:
17678
name: Busybox test suite
17779
runs-on: ${{ matrix.job.os }}

.github/workflows/merge.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Various autofixes on the code
2+
3+
env:
4+
RUST_MIN_SRV: "1.43.1" ## v1.43.0
5+
6+
# only trigger on pull request closed events
7+
on:
8+
pull_request:
9+
types: [ closed ]
10+
11+
jobs:
12+
13+
code_format_commit:
14+
if: github.event.pull_request.merged == true
15+
name: Style/format
16+
runs-on: ${{ matrix.job.os }}
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
job:
21+
- { os: ubuntu-latest , features: feat_os_unix }
22+
steps:
23+
- uses: actions/checkout@v2
24+
- name: Initialize workflow variables
25+
id: vars
26+
shell: bash
27+
run: |
28+
## VARs setup
29+
outputs() { for var in "$@" ; do echo steps.vars.outputs.${var}="${!var}"; echo ::set-output name=${var}::${!var}; done; }
30+
# target-specific options
31+
# * CARGO_FEATURES_OPTION
32+
CARGO_FEATURES_OPTION='' ;
33+
if [ -n "${{ matrix.job.features }}" ]; then CARGO_FEATURES_OPTION='--features "${{ matrix.job.features }}"' ; fi
34+
outputs CARGO_FEATURES_OPTION
35+
- name: Install `rust` toolchain
36+
uses: actions-rs/toolchain@v1
37+
with:
38+
toolchain: stable
39+
default: true
40+
profile: minimal # minimal component installation (ie, no documentation)
41+
components: rustfmt
42+
- name: "`cargo fmt` run"
43+
shell: bash
44+
run: |
45+
cargo fmt
46+
- name: "`fmt` testing of tests"
47+
shell: bash
48+
run: |
49+
find tests -name "*.rs" -print0 | xargs -0 cargo fmt --
50+
- name: Commit rustfmt changes
51+
uses: EndBug/add-and-commit@v7
52+
with:
53+
default_author: github_actions
54+
message: "maint ~ rustfmt (`cargo fmt`)"
55+
56+
min_version:
57+
if: github.event.pull_request.merged == true
58+
name: MinRustV # Minimum supported rust version
59+
runs-on: ${{ matrix.job.os }}
60+
strategy:
61+
matrix:
62+
job:
63+
- { os: ubuntu-latest , features: feat_os_unix }
64+
steps:
65+
- uses: actions/checkout@v2
66+
- name: Install `rust` toolchain (v${{ env.RUST_MIN_SRV }})
67+
uses: actions-rs/toolchain@v1
68+
with:
69+
toolchain: ${{ env.RUST_MIN_SRV }}
70+
default: true
71+
profile: minimal # minimal component installation (ie, no documentation)
72+
- name: Install `cargo-tree` # for dependency information
73+
uses: actions-rs/install@v0.1
74+
with:
75+
crate: cargo-tree
76+
version: latest
77+
use-tool-cache: true
78+
env:
79+
RUSTUP_TOOLCHAIN: stable
80+
- name: Confirm compatible 'Cargo.lock'
81+
shell: bash
82+
run: |
83+
# Confirm compatible 'Cargo.lock'
84+
# * 'Cargo.lock' is required to be in a format that `cargo` of MinSRV can interpret (eg, v1-format for MinSRV < v1.38)
85+
cargo fetch --locked --quiet || cargo +${RUST_MIN_SRV} update
86+
- name: Info
87+
shell: bash
88+
run: |
89+
# Info
90+
## environment
91+
echo "## environment"
92+
echo "CI='${CI}'"
93+
## tooling info display
94+
echo "## tooling"
95+
which gcc >/dev/null 2>&1 && (gcc --version | head -1) || true
96+
rustup -V
97+
rustup show active-toolchain
98+
cargo -V
99+
rustc -V
100+
cargo-tree tree -V
101+
## dependencies
102+
echo "## dependency list"
103+
cargo fetch --locked --quiet
104+
## * using the 'stable' toolchain is necessary to avoid "unexpected '--filter-platform'" errors
105+
RUSTUP_TOOLCHAIN=stable cargo-tree tree --frozen --all --no-dev-dependencies --no-indent --features ${{ matrix.job.features }} | grep -vE "$PWD" | sort --unique
106+
107+
- name: Commit Cargo.lock update
108+
uses: EndBug/add-and-commit@v7
109+
with:
110+
default_author: github_actions
111+
message: "maint ~ refresh 'Cargo.lock'"
112+
add: Cargo.lock

0 commit comments

Comments
 (0)