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

Add MegaLinter for JSON and GitHub Workflow files #573

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions .github/linters/.jsonlintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"trailing-commas": true,
"duplicate-keys": true,
"compact": true,
"continue": true,
"quiet": true
}
9 changes: 9 additions & 0 deletions .github/linters/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Linters

This directory aims to consolidate configuration files from all linters. MegaLinter knows to look for any linter specific configurations in this directory.

## Local Linting

If you have Docker and npm installed locally then you can run MegaLinter using the exact same configuration as the CI runners.

See [MegaLinter docs](https://megalinter.io/latest/mega-linter-runner/) for instructions on local setup.
24 changes: 24 additions & 0 deletions .github/problem-matchers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Problem Matchers

[GitHub Official Problem Matchers Documentation](https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md)

## Summary

Problem Matchers are used to scan the output of GitHub workflows and display any errors/warnings/information directly on the Pull Request web view.

### Purpose

- **Identify Issues:** Detects and highlights errors, warnings, and informational messages from action outputs.
- **Create Annotations:** Automatically generates GitHub Annotations and log file decorations when matches are found.
- **Improve Visibility:** Surfaces critical information prominently in the UI for easier debugging and review.

### Use Cases

- **Automated Code Review:** Integrate with tools to automatically detect coding standard violations.
- **Continuous Integration:** Enhance CI workflows by providing immediate feedback on build or test failures.
- **Custom Log Parsing:** Create custom matchers to identify and annotate specific patterns in log outputs.

### Key Features

- **Regex-Based Matching:** Uses regular expressions to define the patterns to look for in the logs.
- **Customization:** Allows users to define custom matchers and register/unregister them in GitHub workflows.
17 changes: 17 additions & 0 deletions .github/problem-matchers/actionlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"problemMatcher": [
{
"owner": "actionlint",
"pattern": [
{
"regexp": "^(?:\\x1b\\[\\d+m)?(.+?)(?:\\x1b\\[\\d+m)*:(?:\\x1b\\[\\d+m)*(\\d+)(?:\\x1b\\[\\d+m)*:(?:\\x1b\\[\\d+m)*(\\d+)(?:\\x1b\\[\\d+m)*: (?:\\x1b\\[\\d+m)*(.+?)(?:\\x1b\\[\\d+m)* \\[(.+?)\\]$",
"file": 1,
"line": 2,
"column": 3,
"message": 4,
"code": 5
}
]
}
]
}
17 changes: 17 additions & 0 deletions .github/problem-matchers/jsonlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"problemMatcher": [
{
"owner": "jsonlint",
"pattern": [
{
"regexp": "^(.*[\\/\\\\])?([.\\w\\-_]*):\\sline\\s(\\d*).*col\\s(\\d*),\\s(.*)$",
"fromPath": 1,
"file": 2,
"line": 3,
"column": 4,
"message": 5
}
]
}
]
}
48 changes: 48 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Linting action to run on pull requests.
# Refer to the .mega-linter.yml file to enable or disable other linters.
# Refer to .github/linters for linter specific configurations.
# Refer to .github/problem-matchers for configuration GitHub annotations on linting errors.
name: MegaLinter
on:
pull_request:
branches: [main]

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
megalinter:
name: MegaLinter
runs-on: ubuntu-latest
permissions:
contents: read # Read from repository
# Read/write to PR comments section.
issues: write
pull-requests: write
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
token: ${{ secrets.UEPSEUDO_PAT }}
submodules: recursive
fetch-depth: 0

# Register problem matchers to report issues as annotation on GitHub PRs.
- name: Register Problem Matchers
run: |
echo "::add-matcher::.github/problem-matchers/jsonlint.json"
echo "::add-matcher::.github/problem-matchers/actionlint.json"

- name: MegaLinter
id: ml
uses: oxsecurity/megalinter@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Unregistering problem matchers isn't strictly necessary but not harmful to include.
# It protects us from registering duplicate matchers if we add additional steps to this workflow or retool it as a composite/reusable workflow.
- name: Unregister Problem Matchers
run: |
echo "::remove-matcher owner=jsonlint::"
echo "::remove-matcher owner=actionlint::"
14 changes: 14 additions & 0 deletions .mega-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Configuration file for MegaLinter
# See all available variables at https://megalinter.io/configuration/ and in linters documentation

# Global Settings
FLAVOR_SUGGESTIONS: false
APPLY_FIXES: false
PRINT_ALL_FILES: false
SHOW_ELAPSED_TIME: true

# Linter List
ENABLE_LINTERS:
- "JSON_JSONLINT"
- "ACTION_ACTIONLINT"

Loading