Skip to content

Commit ac67691

Browse files
committed
👷 setup ci & linters
Signed-off-by: David Bernard <david.bernard.31@gmail.com>
1 parent 36f9f26 commit ac67691

File tree

9 files changed

+623
-0
lines changed

9 files changed

+623
-0
lines changed

‎.editorconfig

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# https://editorconfig.org/
2+
3+
root = true
4+
5+
[*]
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
end_of_line = lf
11+
charset = utf-8
12+
13+
[*.conf]
14+
indent_size = 2
15+
16+
[*.md]
17+
#inside code block, indentation could be anything
18+
indent_size = unset
19+
20+
[*.py]
21+
indent_size = 4
22+
# 88 is the default for black formatter
23+
# 79 is PEP8's recommendation
24+
# 119 is django's recommendation
25+
max_line_length = 88
26+
27+
[*.rs]
28+
# https://github.com/rust-dev-tools/fmt-rfcs/blob/master/guide/guide.md
29+
indent_size = 4
30+
# officially the limit is 100, but we have long url (unsplittable) in comment
31+
max_line_length = 200
32+
33+
[{*.bazel,*.bzl,BUILD,WORKSPACE}]
34+
indent_size = 4
35+
36+
[*.java]
37+
# try to align with https://github.com/diffplug/spotless (https://github.com/google/google-java-format)
38+
indent_size = 4
39+
max_line_length = 100
40+
41+
# The JSON files contain newlines inconsistently
42+
[*.json]
43+
insert_final_newline = unset
44+
45+
[**/vendor/**]
46+
indent_style = unset
47+
indent_size = unset
48+
insert_final_newline = unset
49+
50+
# Minified JavaScript files shouldn't be changed
51+
[**.min.js]
52+
indent_style = unset
53+
indent_size = unset
54+
insert_final_newline = unset
55+
56+
# Makefiles always use tabs for indentation
57+
[Makefile]
58+
indent_style = tab
59+
indent_size = 4
60+
61+
[justfile]
62+
indent_style = space
63+
indent_size = 4
64+
65+
# Batch files use tabs for indentation
66+
[*.bat]
67+
indent_style = tab
68+
indent_size = 4

‎.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "cargo"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
- package-ecosystem: "github-actions"
8+
# Workflow files stored in the
9+
# default location of `.github/workflows`
10+
directory: "/"
11+
schedule:
12+
interval: "weekly"

‎.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
name: ci
3+
4+
on:
5+
push:
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
tests:
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
os: [ubuntu-latest]
18+
env:
19+
CARGO_TERM_COLOR: always
20+
RUST_BACKTRACE: full
21+
steps:
22+
- uses: actions/checkout@v4
23+
- uses: jdx/rtx-action@v1
24+
- name: Cache cargo registry
25+
uses: actions/cache@v3
26+
continue-on-error: false
27+
with:
28+
path: |
29+
~/.cargo/registry
30+
~/.cargo/git
31+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
32+
restore-keys: |
33+
${{ runner.os }}-cargo-
34+
- run: just check
35+
- run: just lint_rust # megalinter is running via an other workflow
36+
- run: just test

‎.github/workflows/mega-linter.yml

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# MegaLinter GitHub Action configuration file
2+
# More info at https://megalinter.io
3+
---
4+
name: MegaLinter
5+
6+
# Trigger mega-linter at every push. Action will also be visible from Pull
7+
# Requests to main
8+
on:
9+
# Comment this line to trigger action only on pull-requests
10+
# (not recommended if you don't pay for GH Actions)
11+
push:
12+
13+
# pull_request:
14+
# branches:
15+
# - main
16+
# - master
17+
18+
# Comment env block if you do not want to apply fixes
19+
env:
20+
# Apply linter fixes configuration
21+
#
22+
# When active, APPLY_FIXES must also be defined as environment variable
23+
# (in github/workflows/mega-linter.yml or other CI tool)
24+
APPLY_FIXES: all
25+
26+
# Decide which event triggers application of fixes in a commit or a PR
27+
# (pull_request, push, all)
28+
APPLY_FIXES_EVENT: pull_request
29+
30+
# If APPLY_FIXES is used, defines if the fixes are directly committed (commit)
31+
# or posted in a PR (pull_request)
32+
APPLY_FIXES_MODE: commit
33+
34+
concurrency:
35+
group: ${{ github.ref }}-${{ github.workflow }}
36+
cancel-in-progress: true
37+
38+
# Give the default GITHUB_TOKEN write permission to commit and push, comment
39+
# issues & post new PR; remove the ones you do not need
40+
permissions:
41+
contents: write
42+
issues: write
43+
pull-requests: write
44+
45+
jobs:
46+
megalinter:
47+
name: MegaLinter
48+
runs-on: ubuntu-latest
49+
50+
steps:
51+
# Git Checkout
52+
- name: Checkout Code
53+
uses: actions/checkout@v4
54+
with:
55+
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
56+
57+
# If you use VALIDATE_ALL_CODEBASE = true, you can remove this line to
58+
# improve performance
59+
fetch-depth: 0
60+
61+
# MegaLinter
62+
- name: MegaLinter
63+
64+
# You can override MegaLinter flavor used to have faster performances
65+
# More info at https://megalinter.io/flavors/
66+
uses: oxsecurity/megalinter@v7
67+
68+
id: ml
69+
70+
# All available variables are described in documentation
71+
# https://megalinter.io/configuration/
72+
env:
73+
# Validates all source when push on main, else just the git diff with
74+
# main. Override with true if you always want to lint all sources
75+
#
76+
# To validate the entire codebase, set to:
77+
# VALIDATE_ALL_CODEBASE: true
78+
#
79+
# To validate only diff with main, set to:
80+
# VALIDATE_ALL_CODEBASE: >-
81+
# ${{
82+
# github.event_name == 'push' &&
83+
# contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref)
84+
# }}
85+
VALIDATE_ALL_CODEBASE: >-
86+
${{
87+
github.event_name == 'push' &&
88+
contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref)
89+
}}
90+
91+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92+
93+
# ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE
94+
# .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
95+
96+
# Uncomment to disable copy-paste and spell checks
97+
# DISABLE: COPYPASTE,SPELL
98+
99+
# Upload MegaLinter artifacts
100+
- name: Archive production artifacts
101+
uses: actions/upload-artifact@v4
102+
if: success() || failure()
103+
with:
104+
name: MegaLinter reports
105+
path: |
106+
megalinter-reports
107+
mega-linter.log
108+
109+
# Set APPLY_FIXES_IF var for use in future steps
110+
- name: Set APPLY_FIXES_IF var
111+
run: |
112+
printf 'APPLY_FIXES_IF=%s\n' "${{
113+
steps.ml.outputs.has_updated_sources == 1 &&
114+
(
115+
env.APPLY_FIXES_EVENT == 'all' ||
116+
env.APPLY_FIXES_EVENT == github.event_name
117+
) &&
118+
(
119+
github.event_name == 'push' ||
120+
github.event.pull_request.head.repo.full_name == github.repository
121+
)
122+
}}" >> "${GITHUB_ENV}"
123+
124+
# Set APPLY_FIXES_IF_* vars for use in future steps
125+
- name: Set APPLY_FIXES_IF_* vars
126+
run: |
127+
printf 'APPLY_FIXES_IF_PR=%s\n' "${{
128+
env.APPLY_FIXES_IF == 'true' &&
129+
env.APPLY_FIXES_MODE == 'pull_request'
130+
}}" >> "${GITHUB_ENV}"
131+
printf 'APPLY_FIXES_IF_COMMIT=%s\n' "${{
132+
env.APPLY_FIXES_IF == 'true' &&
133+
env.APPLY_FIXES_MODE == 'commit' &&
134+
(!contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref))
135+
}}" >> "${GITHUB_ENV}"
136+
137+
# Create pull request if applicable
138+
# (for now works only on PR from same repository, not from forks)
139+
- name: Create Pull Request with applied fixes
140+
uses: peter-evans/create-pull-request@v5
141+
id: cpr
142+
if: env.APPLY_FIXES_IF_PR == 'true'
143+
with:
144+
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
145+
commit-message: "[MegaLinter] Apply linters automatic fixes"
146+
title: "[MegaLinter] Apply linters automatic fixes"
147+
labels: bot
148+
149+
- name: Create PR output
150+
if: env.APPLY_FIXES_IF_PR == 'true'
151+
run: |
152+
echo "PR Number - ${{ steps.cpr.outputs.pull-request-number }}"
153+
echo "PR URL - ${{ steps.cpr.outputs.pull-request-url }}"
154+
155+
# Push new commit if applicable
156+
# (for now works only on PR from same repository, not from forks)
157+
- name: Prepare commit
158+
if: env.APPLY_FIXES_IF_COMMIT == 'true'
159+
run: sudo chown -Rc $UID .git/
160+
161+
- name: Commit and push applied linter fixes
162+
uses: stefanzweifel/git-auto-commit-action@v5
163+
if: env.APPLY_FIXES_IF_COMMIT == 'true'
164+
with:
165+
branch: >-
166+
${{
167+
github.event.pull_request.head.ref ||
168+
github.head_ref ||
169+
github.ref
170+
}}
171+
commit_message: "[MegaLinter] Apply linters fixes"
172+
commit_user_name: megalinter-bot
173+
commit_user_email: nicolas.vuillamy@ox.security

0 commit comments

Comments
 (0)