generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 20
86 lines (75 loc) · 3.19 KB
/
format-code.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
---
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@b48455a119cc28045eee8f1e9d0a542a85e71f4f #v7.5.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"