Skip to content

Commit b8ea170

Browse files
authored
New formatters flavor (#3071)
* [automation] Auto-update linters version, help and documentation * trvy * New formatters flavor Fixes #2921 Co-authored-by: Matt Bishop <1046132+withinfocus@users.noreply.github.com> * [MegaLinter] Apply linters fixes --------- Co-authored-by: nvuillam <nvuillam@users.noreply.github.com>
1 parent 82087a5 commit b8ea170

File tree

10 files changed

+306
-0
lines changed

10 files changed

+306
-0
lines changed

.automation/build.py

+8
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,16 @@ def match_flavor(item, flavor, flavor_info):
590590
and flavor in item["descriptor_flavors_exclude"]
591591
):
592592
return False
593+
# Flavor all
593594
elif flavor == "all":
594595
return True
596+
# Formatter flavor
597+
elif flavor == "formatters":
598+
if "is_formatter" in item and item["is_formatter"] is True:
599+
return True
600+
else:
601+
return False
602+
# Other flavors
595603
elif "descriptor_flavors" in item:
596604
if flavor in item["descriptor_flavors"] or (
597605
"all_flavors" in item["descriptor_flavors"]

.github/workflows/deploy-BETA-flavors.yml

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ jobs:
6262
"documentation",
6363
"dotnet",
6464
"dotnetweb",
65+
"formatters",
6566
"go",
6667
"java",
6768
"javascript",

.github/workflows/deploy-RELEASE-flavors.yml

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
"documentation",
5252
"dotnet",
5353
"dotnetweb",
54+
"formatters",
5455
"go",
5556
"java",
5657
"javascript",

flavors/formatters/Dockerfile

+233
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
# syntax=docker/dockerfile:1
2+
# MEGALINTER FLAVOR [formatters]: Contains only formatters
3+
###########################################
4+
###########################################
5+
## Dockerfile to run MegaLinter ##
6+
###########################################
7+
###########################################
8+
9+
# @not-generated
10+
11+
#############################################################################################
12+
## @generated by .automation/build.py using descriptor files, please do not update manually ##
13+
#############################################################################################
14+
#FROM__START
15+
FROM mvdan/shfmt:latest-alpine as shfmt
16+
FROM alpine/terragrunt:latest as terragrunt
17+
#FROM__END
18+
19+
##################
20+
# Get base image #
21+
##################
22+
FROM python:3.11.5-alpine3.18
23+
ARG GITHUB_TOKEN
24+
25+
#############################################################################################
26+
## @generated by .automation/build.py using descriptor files, please do not update manually ##
27+
#############################################################################################
28+
#ARG__START
29+
ARG PSSA_VERSION='latest'
30+
#ARG__END
31+
32+
####################
33+
# Run APK installs #
34+
####################
35+
36+
WORKDIR /
37+
38+
#############################################################################################
39+
## @generated by .automation/build.py using descriptor files, please do not update manually ##
40+
#############################################################################################
41+
#APK__START
42+
RUN apk add --no-cache \
43+
bash \
44+
ca-certificates \
45+
curl \
46+
gcc \
47+
git \
48+
git-lfs \
49+
libffi-dev \
50+
make \
51+
musl-dev \
52+
openssh \
53+
npm \
54+
nodejs-current \
55+
yarn \
56+
&& git config --global core.autocrlf true
57+
#APK__END
58+
59+
# PATH for golang & python
60+
ENV GOROOT=/usr/lib/go \
61+
GOPATH=/go
62+
# PYTHONPYCACHEPREFIX="$HOME/.cache/cpython/" NV: not working for all packages :/
63+
# hadolint ignore=DL3044
64+
ENV PATH="$PATH":"$GOROOT"/bin:"$GOPATH"/bin
65+
RUN mkdir -p ${GOPATH}/src ${GOPATH}/bin || true && \
66+
# Ignore npm package issues
67+
yarn config set ignore-engines true || true
68+
69+
##############################
70+
# Installs rust dependencies #
71+
#############################################################################################
72+
## @generated by .automation/build.py using descriptor files, please do not update manually ##
73+
#############################################################################################
74+
75+
#CARGO__START
76+
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal --default-toolchain stable \
77+
&& export PATH="/root/.cargo/bin:${PATH}" \
78+
&& cargo install --force --locked sarif-fmt \
79+
&& rm -rf /root/.cargo/registry /root/.cargo/git /root/.cache/sccache /root/.rustup
80+
ENV PATH="/root/.cargo/bin:${PATH}"
81+
#CARGO__END
82+
83+
################################
84+
# Installs python dependencies #
85+
#############################################################################################
86+
## @generated by .automation/build.py using descriptor files, please do not update manually ##
87+
#############################################################################################
88+
89+
#PIPVENV__START
90+
RUN PYTHONDONTWRITEBYTECODE=1 pip3 install --no-cache-dir --upgrade pip virtualenv \
91+
&& mkdir -p "/venvs/black" && cd "/venvs/black" && virtualenv . && source bin/activate && PYTHONDONTWRITEBYTECODE=1 pip3 install --no-cache-dir black && deactivate && cd ./../.. \
92+
&& mkdir -p "/venvs/isort" && cd "/venvs/isort" && virtualenv . && source bin/activate && PYTHONDONTWRITEBYTECODE=1 pip3 install --no-cache-dir isort black && deactivate && cd ./../.. \
93+
&& mkdir -p "/venvs/rstfmt" && cd "/venvs/rstfmt" && virtualenv . && source bin/activate && PYTHONDONTWRITEBYTECODE=1 pip3 install --no-cache-dir rstfmt && deactivate && cd ./../.. \
94+
&& mkdir -p "/venvs/snakefmt" && cd "/venvs/snakefmt" && virtualenv . && source bin/activate && PYTHONDONTWRITEBYTECODE=1 pip3 install --no-cache-dir snakefmt && deactivate && cd ./../.. \
95+
&& find . | grep -E "(/__pycache__$|\.pyc$|\.pyo$)" | xargs rm -rf && rm -rf /root/.cache
96+
ENV PATH="${PATH}":/venvs/black/bin:/venvs/isort/bin:/venvs/rstfmt/bin:/venvs/snakefmt/bin
97+
#PIPVENV__END
98+
99+
############################
100+
# Install NPM dependencies #
101+
#############################################################################################
102+
## @generated by .automation/build.py using descriptor files, please do not update manually ##
103+
#############################################################################################
104+
105+
ENV NODE_OPTIONS="--max-old-space-size=8192" \
106+
NODE_ENV=production
107+
#NPM__START
108+
WORKDIR /node-deps
109+
RUN npm --no-cache install --ignore-scripts --omit=dev \
110+
prettier \
111+
markdownlint-cli \
112+
markdown-table-formatter && \
113+
echo "Cleaning npm cache…" \
114+
&& npm cache clean --force || true \
115+
&& echo "Changing owner of node_modules files…" \
116+
&& chown -R "$(id -u)":"$(id -g)" node_modules # fix for https://github.com/npm/cli/issues/5900 \
117+
&& echo "Removing extra node_module files…" \
118+
&& rm -rf /root/.npm/_cacache \
119+
&& find . -name "*.d.ts" -delete \
120+
&& find . -name "*.map" -delete \
121+
&& find . -name "*.npmignore" -delete \
122+
&& find . -name "*.travis.yml" -delete \
123+
&& find . -name "CHANGELOG.md" -delete \
124+
&& find . -name "README.md" -delete \
125+
&& find . -name ".package-lock.json" -delete \
126+
&& find . -name "package-lock.json" -delete \
127+
&& find . -name "README.md" -delete
128+
WORKDIR /
129+
130+
#NPM__END
131+
132+
# Add node packages to path #
133+
ENV PATH="/node-deps/node_modules/.bin:${PATH}" \
134+
NODE_PATH="/node-deps/node_modules"
135+
136+
##############################
137+
# Installs ruby dependencies #
138+
#############################################################################################
139+
## @generated by .automation/build.py using descriptor files, please do not update manually ##
140+
#############################################################################################
141+
142+
#GEM__START
143+
144+
#GEM__END
145+
146+
##############################
147+
# COPY instructions #
148+
#############################################################################################
149+
## @generated by .automation/build.py using descriptor files, please do not update manually ##
150+
#############################################################################################
151+
152+
#COPY__START
153+
COPY --link --from=shfmt /bin/shfmt /usr/bin/
154+
COPY --link --from=terragrunt /bin/terraform /usr/bin/
155+
#COPY__END
156+
157+
#############################################################################################
158+
## @generated by .automation/build.py using descriptor files, please do not update manually ##
159+
#############################################################################################
160+
#OTHER__START
161+
# shfmt installation
162+
# Managed with COPY --link --from=shfmt /bin/shfmt /usr/bin/
163+
164+
# csharpier installation
165+
RUN /usr/share/dotnet/dotnet tool install -g csharpier \
166+
167+
# powershell_formatter installation
168+
&& pwsh -c 'Install-Module -Name PSScriptAnalyzer -RequiredVersion ${PSSA_VERSION} -Scope AllUsers -Force'
169+
170+
# terraform-fmt installation
171+
# Managed with COPY --link --from=terragrunt /bin/terraform /usr/bin/
172+
173+
#OTHER__END
174+
175+
################################
176+
# Installs python dependencies #
177+
################################
178+
COPY megalinter /megalinter
179+
RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
180+
&& PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py clean --all \
181+
&& rm -rf /var/cache/apk/* \
182+
&& find . | grep -E "(/__pycache__$|\.pyc$|\.pyo$)" | xargs rm -rf
183+
184+
#######################################
185+
# Copy scripts and rules to container #
186+
#######################################
187+
COPY megalinter/descriptors /megalinter-descriptors
188+
COPY TEMPLATES /action/lib/.automation
189+
190+
# Copy server scripts
191+
COPY server /server
192+
193+
###########################
194+
# Get the build arguments #
195+
###########################
196+
ARG BUILD_DATE
197+
ARG BUILD_REVISION
198+
ARG BUILD_VERSION
199+
200+
#################################################
201+
# Set ENV values used for debugging the version #
202+
#################################################
203+
ENV BUILD_DATE=$BUILD_DATE \
204+
BUILD_REVISION=$BUILD_REVISION \
205+
BUILD_VERSION=$BUILD_VERSION
206+
207+
#FLAVOR__START
208+
ENV MEGALINTER_FLAVOR=formatters
209+
#FLAVOR__END
210+
211+
#########################################
212+
# Label the instance and set maintainer #
213+
#########################################
214+
LABEL com.github.actions.name="MegaLinter" \
215+
com.github.actions.description="The ultimate linters aggregator to make sure your projects are clean" \
216+
com.github.actions.icon="code" \
217+
com.github.actions.color="red" \
218+
maintainer="Nicolas Vuillamy <nicolas.vuillamy@gmail.com>" \
219+
org.opencontainers.image.created=$BUILD_DATE \
220+
org.opencontainers.image.revision=$BUILD_REVISION \
221+
org.opencontainers.image.version=$BUILD_VERSION \
222+
org.opencontainers.image.authors="Nicolas Vuillamy <nicolas.vuillamy@gmail.com>" \
223+
org.opencontainers.image.url="https://megalinter.io" \
224+
org.opencontainers.image.source="https://github.com/oxsecurity/megalinter" \
225+
org.opencontainers.image.documentation="https://megalinter.io" \
226+
org.opencontainers.image.vendor="Nicolas Vuillamy" \
227+
org.opencontainers.image.description="Lint your code base with GitHub Actions"
228+
229+
#EXTRA_DOCKERFILE_LINES__START
230+
COPY entrypoint.sh /entrypoint.sh
231+
RUN chmod +x entrypoint.sh
232+
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
233+
#EXTRA_DOCKERFILE_LINES__END

flavors/formatters/action.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Automatically @generated by build.py
2+
name: "MegaLinter"
3+
author: "Nicolas Vuillamy"
4+
description: "[formatters flavor] Combine all available linters to automatically validate your sources without configuration !"
5+
outputs:
6+
has_updated_sources:
7+
description: "0 if no source file has been updated, 1 if source files has been updated"
8+
runs:
9+
using: "docker"
10+
image: "docker://oxsecurity/megalinter-formatters:v7"
11+
args:
12+
- "-v"
13+
- "/var/run/docker.sock:/var/run/docker.sock:rw"
14+
branding:
15+
icon: "check"
16+
color: "green"

flavors/formatters/flavor.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"descriptors": [],
3+
"label": "Contains only formatters",
4+
"linters": [
5+
"BASH_SHFMT",
6+
"CSHARP_DOTNET_FORMAT",
7+
"CSHARP_CSHARPIER",
8+
"JAVASCRIPT_PRETTIER",
9+
"JSON_PRETTIER",
10+
"MARKDOWN_MARKDOWNLINT",
11+
"MARKDOWN_MARKDOWN_TABLE_FORMATTER",
12+
"POWERSHELL_POWERSHELL_FORMATTER",
13+
"PYTHON_BLACK",
14+
"PYTHON_ISORT",
15+
"RST_RSTFMT",
16+
"SNAKEMAKE_SNAKEFMT",
17+
"TERRAFORM_TERRAFORM_FMT",
18+
"TYPESCRIPT_PRETTIER",
19+
"VBDOTNET_DOTNET_FORMAT",
20+
"YAML_PRETTIER"
21+
]
22+
}

megalinter/descriptors/all_flavors.json

+22
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,28 @@
411411
"YAML_V8R"
412412
]
413413
},
414+
"formatters": {
415+
"descriptors": [],
416+
"label": "Contains only formatters",
417+
"linters": [
418+
"BASH_SHFMT",
419+
"CSHARP_DOTNET_FORMAT",
420+
"CSHARP_CSHARPIER",
421+
"JAVASCRIPT_PRETTIER",
422+
"JSON_PRETTIER",
423+
"MARKDOWN_MARKDOWNLINT",
424+
"MARKDOWN_MARKDOWN_TABLE_FORMATTER",
425+
"POWERSHELL_POWERSHELL_FORMATTER",
426+
"PYTHON_BLACK",
427+
"PYTHON_ISORT",
428+
"RST_RSTFMT",
429+
"SNAKEMAKE_SNAKEFMT",
430+
"TERRAFORM_TERRAFORM_FMT",
431+
"TYPESCRIPT_PRETTIER",
432+
"VBDOTNET_DOTNET_FORMAT",
433+
"YAML_PRETTIER"
434+
]
435+
},
414436
"go": {
415437
"descriptors": [
416438
"BASH",

megalinter/descriptors/schemas/megalinter-descriptor.jsonschema.json

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"documentation",
4848
"dotnet",
4949
"dotnetweb",
50+
"formatters",
5051
"go",
5152
"java",
5253
"javascript",

megalinter/flavor_factory.py

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def list_megalinter_flavors():
5151
"dotnetweb": {
5252
"label": "Optimized for C, C++, C# or VB based projects with JS/TS"
5353
},
54+
"formatters": {"label": "Contains only formatters"},
5455
"go": {"label": "Optimized for GO based projects"},
5556
"java": {"label": "Optimized for JAVA based projects"},
5657
"javascript": {

mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ nav:
359359
- "documentation": "flavors/documentation.md"
360360
- "dotnet": "flavors/dotnet.md"
361361
- "dotnetweb": "flavors/dotnetweb.md"
362+
- "formatters": "flavors/formatters.md"
362363
- "go": "flavors/go.md"
363364
- "java": "flavors/java.md"
364365
- "javascript": "flavors/javascript.md"

0 commit comments

Comments
 (0)