Docs: Refined documentation and linting (closes #35) #29
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# kics-scan disable=555ab8f9-2001-455e-a077-f2d0f41e2fb9 | |
## | |
# MegaLinter GitHub Action configuration file | |
# | |
# @link https://megalinter.io | |
# | |
--- | |
name: MegaLinter | |
on: | |
## | |
# Run after Pull Requests merge onto environment Branches | |
# | |
# Logic below configures a full code test on push for `staging` and `production`. | |
# | |
push: | |
branches: | |
- main | |
- production | |
- staging | |
## | |
# Run MegaLinter any Pull Requests within the project | |
# | |
# Logic below configures a partial code test on only changed files on Pull Request. | |
# | |
pull_request: | |
## | |
# Environment configurations | |
# | |
# @link https://docs.github.com/en/actions/learn-github-actions/contexts#env-context | |
# | |
env: | |
## | |
# Apply linter fixes during integration for basic formatting Issues | |
# | |
APPLY_FIXES: all | |
## | |
# Decide which event triggers automatic fixes in a commit or a PR (`pull_request`, `push`, or `all`) | |
# | |
APPLY_FIXES_EVENT: pull_request | |
## | |
# If using `APPLY_FIXES`, this defines if the fixes are directly committed (`commit`) or posted in a Pull Request | |
# (`pull_request`) | |
# | |
APPLY_FIXES_MODE: commit | |
## | |
# Cancel in-progress actions on the same Branch when triggering a new workflow | |
# | |
# @link https://docs.github.com/en/actions/using-jobs/using-concurrency | |
# | |
concurrency: | |
group: ${{ github.ref }}-${{ github.workflow }} | |
cancel-in-progress: true | |
## | |
# Code linting job configurations | |
# | |
# @link https://docs.github.com/en/actions/using-jobs/using-jobs-in-a-workflow | |
# | |
jobs: | |
build: | |
name: MegaLinter | |
runs-on: ubuntu-latest | |
## | |
# This job's `GITHUB_TOKEN` must have these permissions | |
# | |
# Always aim to provide as few permissions as possible for personal access tokens. | |
# | |
# @link https://docs.github.com/en/actions/security-guides/automatic-token-authentication | |
# | |
permissions: | |
contents: write | |
issues: write | |
pull-requests: write | |
steps: | |
## | |
# Checkout the full Repository for linting | |
# | |
# @link https://github.com/actions/checkout | |
# | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} | |
# If you use `VALIDATE_ALL_CODEBASE = true`, you can remove this line to improve performance | |
fetch-depth: 0 | |
## | |
# Run MegaLinter | |
# | |
- name: Lint with MegaLinter | |
id: ml | |
## | |
# More specific flavors reduce container size and significantly increase performance | |
# | |
# The template that generated this project uses the full MegaLinter image, by default, which is extremely large | |
# and has numerous linters likely not needed by any one specific project. | |
# | |
# @link https://megalinter.io/flavors/ | |
# | |
uses: oxsecurity/megalinter@v7 | |
## | |
# Variables are overridden on GitHub workflows for certain conditions | |
# | |
# https://megalinter.io/configuration/ | |
# | |
env: | |
## | |
# Lint the entire codebase any time a staging or production Branch deployment occurs, otherwise, only test | |
# changed files for efficiency | |
# | |
VALIDATE_ALL_CODEBASE: >- | |
${{ | |
github.event_name == 'push' && ( | |
github.ref == 'refs/heads/staging' || | |
github.ref == 'refs/heads/production' | |
) | |
}} | |
## | |
# This token is automatically created on the GitHub server | |
# | |
# If running locally, provide this token with the `gh` utility. For example, with `act`: | |
# | |
# ```sh | |
# act -s GITHUB_TOKEN="$(gh auth token)" | |
# ``` | |
# | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
## | |
# ADD YOUR CUSTOM ENV VARIABLES HERE TO OVERRIDE VALUES OF .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY | |
# | |
## | |
# Upload MegaLinter artifacts | |
# | |
# This stores each report and log from tests for reference during CI/CD. | |
# | |
# @link https://github.com/actions/upload-artifact | |
# @link https://megalinter.io/latest/reporters/ | |
# | |
- name: Archive production artifacts | |
if: ${{ success() }} || ${{ failure() }} | |
uses: actions/upload-artifact@v3 | |
with: | |
name: MegaLinter reports | |
path: | | |
megalinter-reports | |
mega-linter.log | |
## | |
# Create a Pull Request with any automatic fixes | |
# | |
# Note that this doesn't currently work for Forks, only Pull Requests from the same Repository. | |
# | |
- name: Create Pull Request with applied fixes | |
id: cpr | |
if: | | |
steps.ml.outputs.has_updated_sources == 1 && | |
( | |
env.APPLY_FIXES_EVENT == 'all' || | |
env.APPLY_FIXES_EVENT == github.event_name | |
) && | |
env.APPLY_FIXES_MODE == 'pull_request' && | |
( | |
github.event_name == 'push' || | |
github.event.pull_request.head.repo.full_name == github.repository | |
) && | |
!contains(github.event.head_commit.message, 'skip fix') | |
uses: peter-evans/create-pull-request@v5 | |
with: | |
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} | |
commit-message: "[MegaLinter] Apply linters automatic fixes" | |
title: "[MegaLinter] Apply linters automatic fixes" | |
labels: bot | |
- name: Create Pull Request output | |
if: | | |
steps.ml.outputs.has_updated_sources == 1 && | |
( | |
env.APPLY_FIXES_EVENT == 'all' || | |
env.APPLY_FIXES_EVENT == github.event_name | |
) && | |
env.APPLY_FIXES_MODE == 'pull_request' && | |
( | |
github.event_name == 'push' || | |
github.event.pull_request.head.repo.full_name == github.repository | |
) && | |
!contains(github.event.head_commit.message, 'skip fix') | |
run: | | |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" | |
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" | |
- name: Prepare commit | |
if: | | |
steps.ml.outputs.has_updated_sources == 1 && | |
( | |
env.APPLY_FIXES_EVENT == 'all' || | |
env.APPLY_FIXES_EVENT == github.event_name | |
) && | |
env.APPLY_FIXES_MODE == 'commit' && | |
github.ref != 'refs/heads/main' && | |
( | |
github.event_name == 'push' || | |
github.event.pull_request.head.repo.full_name == github.repository | |
) && | |
!contains(github.event.head_commit.message, 'skip fix') | |
run: sudo chown -Rc $UID .git/ | |
- name: Commit and push applied linter fixes | |
if: | | |
steps.ml.outputs.has_updated_sources == 1 && | |
( | |
env.APPLY_FIXES_EVENT == 'all' || | |
env.APPLY_FIXES_EVENT == github.event_name | |
) && | |
env.APPLY_FIXES_MODE == 'commit' && | |
github.ref != 'refs/heads/main' && | |
( | |
github.event_name == 'push' || | |
github.event.pull_request.head.repo.full_name == github.repository | |
) && | |
!contains(github.event.head_commit.message, 'skip fix') | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
branch: ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }} | |
commit_message: "[MegaLinter] Apply linters fixes" | |
commit_user_name: megalinter-bot | |
commit_user_email: [email protected] |