Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New formatters flavor #3071

Merged
merged 8 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .automation/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,16 @@ def match_flavor(item, flavor, flavor_info):
and flavor in item["descriptor_flavors_exclude"]
):
return False
# Flavor all
elif flavor == "all":
return True
# Formatter flavor
elif flavor == "formatters":
if "is_formatter" in item and item["is_formatter"] is True:
return True
else:
return False
# Other flavors
elif "descriptor_flavors" in item:
if flavor in item["descriptor_flavors"] or (
"all_flavors" in item["descriptor_flavors"]
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-BETA-flavors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ jobs:
"documentation",
"dotnet",
"dotnetweb",
"formatters",
"go",
"java",
"javascript",
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-RELEASE-flavors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
"documentation",
"dotnet",
"dotnetweb",
"formatters",
"go",
"java",
"javascript",
Expand Down
233 changes: 233 additions & 0 deletions flavors/formatters/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
# syntax=docker/dockerfile:1
# MEGALINTER FLAVOR [formatters]: Contains only formatters
###########################################
###########################################
## Dockerfile to run MegaLinter ##
###########################################
###########################################

# @not-generated

#############################################################################################
## @generated by .automation/build.py using descriptor files, please do not update manually ##
#############################################################################################
#FROM__START
FROM mvdan/shfmt:latest-alpine as shfmt
FROM alpine/terragrunt:latest as terragrunt
#FROM__END

##################
# Get base image #
##################
FROM python:3.11.5-alpine3.18
ARG GITHUB_TOKEN

#############################################################################################
## @generated by .automation/build.py using descriptor files, please do not update manually ##
#############################################################################################
#ARG__START
ARG PSSA_VERSION='latest'
#ARG__END

####################
# Run APK installs #
####################

WORKDIR /

#############################################################################################
## @generated by .automation/build.py using descriptor files, please do not update manually ##
#############################################################################################
#APK__START
RUN apk add --no-cache \
bash \
ca-certificates \
curl \
gcc \
git \
git-lfs \
libffi-dev \
make \
musl-dev \
openssh \
npm \
nodejs-current \
yarn \
&& git config --global core.autocrlf true
#APK__END

# PATH for golang & python
ENV GOROOT=/usr/lib/go \
GOPATH=/go
# PYTHONPYCACHEPREFIX="$HOME/.cache/cpython/" NV: not working for all packages :/
# hadolint ignore=DL3044
ENV PATH="$PATH":"$GOROOT"/bin:"$GOPATH"/bin
RUN mkdir -p ${GOPATH}/src ${GOPATH}/bin || true && \
# Ignore npm package issues
yarn config set ignore-engines true || true

##############################
# Installs rust dependencies #
#############################################################################################
## @generated by .automation/build.py using descriptor files, please do not update manually ##
#############################################################################################

#CARGO__START
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal --default-toolchain stable \
&& export PATH="/root/.cargo/bin:${PATH}" \
&& cargo install --force --locked sarif-fmt \
&& rm -rf /root/.cargo/registry /root/.cargo/git /root/.cache/sccache /root/.rustup
ENV PATH="/root/.cargo/bin:${PATH}"
#CARGO__END

################################
# Installs python dependencies #
#############################################################################################
## @generated by .automation/build.py using descriptor files, please do not update manually ##
#############################################################################################

#PIPVENV__START
RUN PYTHONDONTWRITEBYTECODE=1 pip3 install --no-cache-dir --upgrade pip virtualenv \
&& mkdir -p "/venvs/black" && cd "/venvs/black" && virtualenv . && source bin/activate && PYTHONDONTWRITEBYTECODE=1 pip3 install --no-cache-dir black && deactivate && cd ./../.. \
&& mkdir -p "/venvs/isort" && cd "/venvs/isort" && virtualenv . && source bin/activate && PYTHONDONTWRITEBYTECODE=1 pip3 install --no-cache-dir isort black && deactivate && cd ./../.. \
&& mkdir -p "/venvs/rstfmt" && cd "/venvs/rstfmt" && virtualenv . && source bin/activate && PYTHONDONTWRITEBYTECODE=1 pip3 install --no-cache-dir rstfmt && deactivate && cd ./../.. \
&& mkdir -p "/venvs/snakefmt" && cd "/venvs/snakefmt" && virtualenv . && source bin/activate && PYTHONDONTWRITEBYTECODE=1 pip3 install --no-cache-dir snakefmt && deactivate && cd ./../.. \
&& find . | grep -E "(/__pycache__$|\.pyc$|\.pyo$)" | xargs rm -rf && rm -rf /root/.cache
ENV PATH="${PATH}":/venvs/black/bin:/venvs/isort/bin:/venvs/rstfmt/bin:/venvs/snakefmt/bin
#PIPVENV__END

############################
# Install NPM dependencies #
#############################################################################################
## @generated by .automation/build.py using descriptor files, please do not update manually ##
#############################################################################################

ENV NODE_OPTIONS="--max-old-space-size=8192" \
NODE_ENV=production
#NPM__START
WORKDIR /node-deps
RUN npm --no-cache install --ignore-scripts --omit=dev \
prettier \
markdownlint-cli \
markdown-table-formatter && \
echo "Cleaning npm cache…" \
&& npm cache clean --force || true \
&& echo "Changing owner of node_modules files…" \
&& chown -R "$(id -u)":"$(id -g)" node_modules # fix for https://github.com/npm/cli/issues/5900 \
&& echo "Removing extra node_module files…" \
&& rm -rf /root/.npm/_cacache \
&& find . -name "*.d.ts" -delete \
&& find . -name "*.map" -delete \
&& find . -name "*.npmignore" -delete \
&& find . -name "*.travis.yml" -delete \
&& find . -name "CHANGELOG.md" -delete \
&& find . -name "README.md" -delete \
&& find . -name ".package-lock.json" -delete \
&& find . -name "package-lock.json" -delete \
&& find . -name "README.md" -delete
WORKDIR /

#NPM__END

# Add node packages to path #
ENV PATH="/node-deps/node_modules/.bin:${PATH}" \
NODE_PATH="/node-deps/node_modules"

##############################
# Installs ruby dependencies #
#############################################################################################
## @generated by .automation/build.py using descriptor files, please do not update manually ##
#############################################################################################

#GEM__START

#GEM__END

##############################
# COPY instructions #
#############################################################################################
## @generated by .automation/build.py using descriptor files, please do not update manually ##
#############################################################################################

#COPY__START
COPY --link --from=shfmt /bin/shfmt /usr/bin/
COPY --link --from=terragrunt /bin/terraform /usr/bin/
#COPY__END

#############################################################################################
## @generated by .automation/build.py using descriptor files, please do not update manually ##
#############################################################################################
#OTHER__START
# shfmt installation
# Managed with COPY --link --from=shfmt /bin/shfmt /usr/bin/

# csharpier installation
RUN /usr/share/dotnet/dotnet tool install -g csharpier \

# powershell_formatter installation
&& pwsh -c 'Install-Module -Name PSScriptAnalyzer -RequiredVersion ${PSSA_VERSION} -Scope AllUsers -Force'

# terraform-fmt installation
# Managed with COPY --link --from=terragrunt /bin/terraform /usr/bin/

#OTHER__END

################################
# Installs python dependencies #
################################
COPY megalinter /megalinter
RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
&& PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py clean --all \
&& rm -rf /var/cache/apk/* \
&& find . | grep -E "(/__pycache__$|\.pyc$|\.pyo$)" | xargs rm -rf

#######################################
# Copy scripts and rules to container #
#######################################
COPY megalinter/descriptors /megalinter-descriptors
COPY TEMPLATES /action/lib/.automation

# Copy server scripts
COPY server /server

###########################
# Get the build arguments #
###########################
ARG BUILD_DATE
ARG BUILD_REVISION
ARG BUILD_VERSION

#################################################
# Set ENV values used for debugging the version #
#################################################
ENV BUILD_DATE=$BUILD_DATE \
BUILD_REVISION=$BUILD_REVISION \
BUILD_VERSION=$BUILD_VERSION

#FLAVOR__START
ENV MEGALINTER_FLAVOR=formatters
#FLAVOR__END

#########################################
# Label the instance and set maintainer #
#########################################
LABEL com.github.actions.name="MegaLinter" \
com.github.actions.description="The ultimate linters aggregator to make sure your projects are clean" \
com.github.actions.icon="code" \
com.github.actions.color="red" \
maintainer="Nicolas Vuillamy <nicolas.vuillamy@gmail.com>" \
org.opencontainers.image.created=$BUILD_DATE \
org.opencontainers.image.revision=$BUILD_REVISION \
org.opencontainers.image.version=$BUILD_VERSION \
org.opencontainers.image.authors="Nicolas Vuillamy <nicolas.vuillamy@gmail.com>" \
org.opencontainers.image.url="https://megalinter.io" \
org.opencontainers.image.source="https://github.com/oxsecurity/megalinter" \
org.opencontainers.image.documentation="https://megalinter.io" \
org.opencontainers.image.vendor="Nicolas Vuillamy" \
org.opencontainers.image.description="Lint your code base with GitHub Actions"

#EXTRA_DOCKERFILE_LINES__START
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x entrypoint.sh
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
#EXTRA_DOCKERFILE_LINES__END
16 changes: 16 additions & 0 deletions flavors/formatters/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Automatically @generated by build.py
name: "MegaLinter"
author: "Nicolas Vuillamy"
description: "[formatters flavor] Combine all available linters to automatically validate your sources without configuration !"
outputs:
has_updated_sources:
description: "0 if no source file has been updated, 1 if source files has been updated"
runs:
using: "docker"
image: "docker://oxsecurity/megalinter-formatters:v7"
args:
- "-v"
- "/var/run/docker.sock:/var/run/docker.sock:rw"
branding:
icon: "check"
color: "green"
22 changes: 22 additions & 0 deletions flavors/formatters/flavor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"descriptors": [],
"label": "Contains only formatters",
"linters": [
"BASH_SHFMT",
"CSHARP_DOTNET_FORMAT",
"CSHARP_CSHARPIER",
"JAVASCRIPT_PRETTIER",
"JSON_PRETTIER",
"MARKDOWN_MARKDOWNLINT",
"MARKDOWN_MARKDOWN_TABLE_FORMATTER",
"POWERSHELL_POWERSHELL_FORMATTER",
"PYTHON_BLACK",
"PYTHON_ISORT",
"RST_RSTFMT",
"SNAKEMAKE_SNAKEFMT",
"TERRAFORM_TERRAFORM_FMT",
"TYPESCRIPT_PRETTIER",
"VBDOTNET_DOTNET_FORMAT",
"YAML_PRETTIER"
]
}
22 changes: 22 additions & 0 deletions megalinter/descriptors/all_flavors.json
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,28 @@
"YAML_V8R"
]
},
"formatters": {
"descriptors": [],
"label": "Contains only formatters",
"linters": [
"BASH_SHFMT",
"CSHARP_DOTNET_FORMAT",
"CSHARP_CSHARPIER",
"JAVASCRIPT_PRETTIER",
"JSON_PRETTIER",
"MARKDOWN_MARKDOWNLINT",
"MARKDOWN_MARKDOWN_TABLE_FORMATTER",
"POWERSHELL_POWERSHELL_FORMATTER",
"PYTHON_BLACK",
"PYTHON_ISORT",
"RST_RSTFMT",
"SNAKEMAKE_SNAKEFMT",
"TERRAFORM_TERRAFORM_FMT",
"TYPESCRIPT_PRETTIER",
"VBDOTNET_DOTNET_FORMAT",
"YAML_PRETTIER"
]
},
"go": {
"descriptors": [
"BASH",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"documentation",
"dotnet",
"dotnetweb",
"formatters",
"go",
"java",
"javascript",
Expand Down
1 change: 1 addition & 0 deletions megalinter/flavor_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def list_megalinter_flavors():
"dotnetweb": {
"label": "Optimized for C, C++, C# or VB based projects with JS/TS"
},
"formatters": {"label": "Contains only formatters"},
"go": {"label": "Optimized for GO based projects"},
"java": {"label": "Optimized for JAVA based projects"},
"javascript": {
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ nav:
- "documentation": "flavors/documentation.md"
- "dotnet": "flavors/dotnet.md"
- "dotnetweb": "flavors/dotnetweb.md"
- "formatters": "flavors/formatters.md"
- "go": "flavors/go.md"
- "java": "flavors/java.md"
- "javascript": "flavors/javascript.md"
Expand Down