Skip to content

Format Code: ensure code formatting guidelines are met #13776

Format Code: ensure code formatting guidelines are met

Format Code: ensure code formatting guidelines are met #13776

Workflow file for this run

---
name: 'Format Code: ensure code formatting guidelines are met'
on:
workflow_dispatch: null
schedule:
- cron: 45 4 * * 1
permissions:
contents: read
concurrency:
group: '${{ github.ref }}-${{ github.workflow }}'
cancel-in-progress: true
jobs:
build:
name: MegaLinter
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b #v4.1.4
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@bacb5f8674e3730b904ca4d20c8bd477bc51b1a7 #v7.13.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"