-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (84 loc) · 2.83 KB
/
rust-ci.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
name: Rust CI
on:
push:
branches: ['**']
pull_request:
branches: ['**']
env:
CARGO_TERM_COLOR: always
jobs:
build:
if: |
github.event_name == 'workflow_dispatch' ||
(github.actor != 'github-actions[bot]' &&
github.actor != 'bythelindemans-actions-bot' &&
(github.event.head_commit.author.email != '[email protected]' || github.event.head_commit.author.email == null))
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
actions: write
steps:
- name: Generate GitHub App Token
id: generate_token
uses: tibdex/github-app-token@v1
with:
app_id: ${{ vars.BTL_ACTIONS_BOT_APP_ID }}
private_key: ${{ secrets.BTL_ACTIONS_BOT_PRIVATE_KEY }}
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ steps.generate_token.outputs.token }}
- name: Install Rust stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
override: true
- name: Cache Cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache Cargo build
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-build-
- name: Run cargo fmt
run: cargo fmt --all
- name: Check if any files were formatted
id: changes
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "changes=true" >> $GITHUB_OUTPUT
else
echo "changes=false" >> $GITHUB_OUTPUT
fi
- name: Create Pull Request with Formatting Fixes
if: steps.changes.outputs.changes == 'true'
uses: peter-evans/create-pull-request@v4
with:
token: ${{ steps.generate_token.outputs.token }}
commit-message: "Apply rustfmt formatting"
branch: formatting-fixes
title: "Automated Formatting Fixes"
body: |
This pull request applies rustfmt formatting to the codebase.
labels: automated fix
- name: Run Clippy
if: steps.changes.outputs.changes == 'false'
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Build
if: steps.changes.outputs.changes == 'false'
run: cargo build --verbose
- name: Run tests
if: steps.changes.outputs.changes == 'false'
run: cargo test --verbose
- name: Run cargo audit
if: steps.changes.outputs.changes == 'false'
uses: actions-rs/audit-check@v1