Format Code: ensure code formatting guidelines are met #13731
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
--- | |
name: 'Format Code: ensure code formatting guidelines are met' | |
on: | |
workflow_dispatch: null | |
schedule: | |
- cron: 45 4 * * 1 | |
permissions: | |
contents: write | |
pull-requests: write | |
concurrency: | |
group: '${{ github.ref }}-${{ github.workflow }}' | |
cancel-in-progress: true | |
jobs: | |
build: | |
name: MegaLinter | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 #v4.1.1 | |
with: | |
token: '${{ secrets.GITHUB_TOKEN }}' | |
fetch-depth: 0 | |
- name: Prepare Git options | |
run: bash ./scripts/git-setup.sh | |
- name: Create new branch | |
run: | | |
date=$(date +%Y_%m_%d) | |
branch_name="date_$date" | |
git checkout -b $branch_name | |
- name: Run linter | |
id: ml | |
# You can override MegaLinter flavor used to have faster performances | |
# More info at https://megalinter.io/flavors/ | |
uses: oxsecurity/megalinter/flavors/terraform@a87b2872713c6bdde46d2473c5d7ed23e5752dc2 #v7.4.0 | |
env: | |
# All available variables are described in documentation | |
# https://megalinter.io/configuration/#shared-variables | |
# ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY | |
APPLY_FIXES: all # When active, APPLY_FIXES must also be defined as environment variable (in github/workflows/mega-linter.yml or other CI tool) | |
APPLY_FIXES_EVENT: all # Decide which event triggers application of fixes in a commit or a PR (pull_request, push, all) | |
APPLY_FIXES_MODE: pull_request # If APPLY_FIXES is used, defines if the fixes are directly committed (commit) or posted in a PR (pull_request) | |
DISABLE_ERRORS: true | |
EMAIL_REPORTER: false | |
ENABLE_LINTERS: JSON_PRETTIER,YAML_PRETTIER,TERRAFORM_TERRAFORM_FMT,MARKDOWN_MARKDOWNLINT | |
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' | |
VALIDATE_ALL_CODEBASE: true | |
YAML_PRETTIER_FILTER_REGEX_EXCLUDE: (.github/*) | |
REPORT_OUTPUT_FOLDER: none | |
- name: Check for changes | |
run: | | |
git add . | |
git commit -m "Updates from GitHub Actions Format Code workflow" | |
branch_name=$(git branch --show-current) | |
changes=$(git diff origin/main...$branch_name --name-only) | |
if [ -z "$changes" ]; then | |
echo "No changes detected." | |
exit 1 | |
else | |
echo "Changes detected." | |
exit 0 | |
fi | |
- name: Push changes | |
run: | | |
git config --global push.autoSetupRemote true | |
git push | |
- name: Create pull request | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
pr_title="GitHub Actions Code Formatter workflow" | |
pr_body="This pull request includes updates from the GitHub Actions Code Formatter workflow. Please review the changes and merge if everything looks good." | |
branch_name=$(git branch --show-current) | |
pr_head="${{ github.repository_owner }}:${branch_name}" | |
pr_base="main" | |
gh pr create --title "$pr_title" --body "$pr_body" --head "$pr_head" --base "$pr_base" --label "code quality" | |