Skip to content

Commit 3c80d63

Browse files
author
Sophia Simões Gonçalves
committed
add new tools
1 parent 72a790a commit 3c80d63

File tree

5 files changed

+338
-0
lines changed

5 files changed

+338
-0
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,21 @@ jobs:
118118
with:
119119
name: mage-coverage-${{ github.sha }}
120120
path: magento/vendor/pagarme/pagarme-magento2-module/clover.xml
121+
122+
coverage-report:
123+
needs: phpunit
124+
uses: ./.github/workflows/coverage-report.yml
125+
with:
126+
ARTIFACT_NAME: mage-coverage-${{ github.sha }}
127+
WORKING_DIRECTORY: ./
128+
PROJECT: Magento2 Dashboard
129+
PR_MINIMUM: 0
130+
NAME_HTML_REPORT: MAgento2 Coverage Report
131+
RUNS_ON: ubuntu-latest
132+
secrets:
133+
EXPORTED_PAGARME_GH_PAT: ${{ secrets.GITHUB_TOKEN }}
134+
135+
mega_linter:
136+
uses: ./.github/workflows/mega-linter.yml
137+
with:
138+
RUNS_ON: ubuntu-latest

.github/workflows/coverage-report.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Coverage-Report
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
WORKING_DIRECTORY:
7+
type: string
8+
ARTIFACT_NAME:
9+
type: string
10+
ARTIFACT_PATTERN:
11+
type: string
12+
PROJECT:
13+
type: string
14+
PR_MINIMUM:
15+
type: number
16+
NAME_HTML_REPORT:
17+
type: string
18+
ALL_FILES_MINIMUN:
19+
type: number
20+
default: 0
21+
RUNS_ON:
22+
type: string
23+
default: small-runner
24+
secrets:
25+
EXPORTED_PAGARME_GH_PAT:
26+
docker_username:
27+
docker_password:
28+
29+
permissions:
30+
contents: read
31+
pull-requests: write
32+
33+
jobs:
34+
lcov:
35+
runs-on: ${{ inputs.RUNS_ON }}
36+
container:
37+
image: btfshadow/lcov
38+
39+
steps:
40+
- uses: actions/checkout@v4
41+
with:
42+
fetch-depth: '0'
43+
submodules: recursive
44+
token: ${{ secrets.EXPORTED_PAGARME_GH_PAT }}
45+
- uses: actions/download-artifact@v4
46+
if: ${{ inputs.ARTIFACT_NAME }}
47+
with:
48+
name: ${{ inputs.ARTIFACT_NAME }}
49+
path: coverage
50+
- name: Download All Artifacts
51+
if: ${{ inputs.ARTIFACT_PATTERN }}
52+
uses: actions/download-artifact@v4
53+
with:
54+
path: coverage
55+
pattern: ${{ inputs.ARTIFACT_PATTERN }}
56+
merge-multiple: true
57+
- name: Setup node
58+
uses: actions/setup-node@v4
59+
with:
60+
node-version: '20'
61+
62+
- name: Move Lcov
63+
if: ${{ inputs.ARTIFACT_NAME }}
64+
run: |
65+
mkdir -p ${{ inputs.WORKING_DIRECTORY }}coverage/
66+
cp coverage/lcov.info ${{ inputs.WORKING_DIRECTORY }}coverage/lcov.info
67+
68+
# - uses: hrishikesh-kadam/setup-lcov@v1
69+
70+
- name: Merge lcov
71+
if: ${{ inputs.ARTIFACT_PATTERN }}
72+
run: |
73+
# Cria pasta para salvar o coverage
74+
mkdir ${{ inputs.WORKING_DIRECTORY }}coverage/
75+
# Pasta raiz onde você quer buscar os arquivos lcov.info
76+
ROOT_DIR="coverage/"
77+
# Encontra todos os arquivos lcov.info e imprime a linha completa com --add-tracefile
78+
lcovs=$(find "$ROOT_DIR" -type f -name "lcov.info" | awk '{printf "--add-tracefile %s ", $0} END {print ""}')
79+
lcov $lcovs --output-file ${{ inputs.WORKING_DIRECTORY }}coverage/lcov.info
80+
81+
- uses: kefasjw/lcov-pull-request-report@main
82+
with:
83+
# Lcov file location. For example, coverage/lcov.info
84+
lcov-file: ${{ inputs.WORKING_DIRECTORY }}coverage/lcov.info
85+
86+
# Github token required for getting list of changed files and posting comments
87+
github-token: ${{ secrets.GITHUB_TOKEN }}
88+
89+
# Working directory
90+
# Default: empty (repository root)
91+
working-directory: ${{ inputs.WORKING_DIRECTORY }}
92+
93+
# Report comment title
94+
# Default: empty
95+
comment-title: ${{ inputs.PROJECT }}
96+
97+
# All files minimum coverage in percentage. For example, 0, 50, 100
98+
# Default: 0
99+
all-files-minimum-coverage: ${{ inputs.ALL_FILES_MINIMUN }}
100+
101+
# Changed files minimum coverage in percentage. For example, 0, 50, 100
102+
# Default: 0
103+
changed-files-minimum-coverage: ${{ inputs.PR_MINIMUM }}
104+
105+
# Artifact name of the generated html. Requires LCOV to be installed
106+
# Default: empty (skip uploading artifact)
107+
artifact-name: ${{ inputs.NAME_HTML_REPORT }}

.github/workflows/mega-linter.yml

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
---
2+
name: MegaLinter
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
GRAFANA_API_REPORTER_URL:
8+
type: string
9+
GRAFANA_API_REPORTER_METRICS_URL:
10+
type: string
11+
API_REPORTER_DEBUG:
12+
type: boolean
13+
default: false
14+
API_REPORTER:
15+
type: boolean
16+
default: false
17+
DEFAULT_BRANCH:
18+
type: string
19+
default: "main"
20+
APPLY_FIXES_IF_PR:
21+
type: boolean
22+
default: false
23+
RUNS_ON:
24+
type: string
25+
default: ubuntu-latest
26+
27+
secrets:
28+
GRAFANA_API_REPORTER_BASIC_AUTH_USERNAME:
29+
required: false
30+
GRAFANA_API_REPORTER_TOKEN:
31+
required: false
32+
GRAFANA_API_REPORTER_METRICS_BASIC_AUTH_USERNAME:
33+
required: false
34+
35+
36+
# Comment env block if you do not want to apply fixes
37+
env:
38+
API_REPORTER: ${{ inputs.API_REPORTER }}
39+
API_REPORTER_URL: ${{ inputs.GRAFANA_API_REPORTER_URL }}
40+
API_REPORTER_BASIC_AUTH_USERNAME: ${{ secrets.GRAFANA_API_REPORTER_BASIC_AUTH_USERNAME }}
41+
API_REPORTER_BASIC_AUTH_PASSWORD: ${{ secrets.GRAFANA_API_REPORTER_TOKEN }}
42+
API_REPORTER_METRICS_URL: ${{ inputs.GRAFANA_API_REPORTER_METRICS_URL }}
43+
API_REPORTER_METRICS_BASIC_AUTH_USERNAME: ${{ secrets.GRAFANA_API_REPORTER_METRICS_BASIC_AUTH_USERNAME }}
44+
API_REPORTER_METRICS_BASIC_AUTH_PASSWORD: ${{ secrets.GRAFANA_API_REPORTER_TOKEN }}
45+
API_REPORTER_DEBUG: ${{ inputs.API_REPORTER_DEBUG }}
46+
SARIF_REPORTER: true
47+
APPLY_FIXES_IF_PR: ${{ inputs.APPLY_FIXES_IF_PR }}
48+
49+
concurrency:
50+
group: ${{ github.ref }}-${{ github.workflow }}
51+
cancel-in-progress: true
52+
53+
permissions: {}
54+
55+
jobs:
56+
megalinter:
57+
name: MegaLinter
58+
runs-on: ${{ inputs.RUNS_ON }}
59+
60+
# Give the default GITHUB_TOKEN write permission to commit and push, comment
61+
# issues & post new PR; remove the ones you do not need
62+
permissions:
63+
contents: write
64+
issues: write
65+
pull-requests: write
66+
security-events: write
67+
actions: read
68+
69+
steps:
70+
# Git Checkout
71+
- name: Checkout Code
72+
uses: actions/checkout@v4
73+
with:
74+
token: ${{ secrets.GITHUB_TOKEN }}
75+
76+
# If you use VALIDATE_ALL_CODEBASE = true, you can remove this line to
77+
# improve performance
78+
fetch-depth: 0
79+
80+
# MegaLinter
81+
- name: MegaLinter
82+
83+
# You can override MegaLinter flavor used to have faster performances
84+
# More info at https://megalinter.io/latest/flavors/
85+
uses: oxsecurity/megalinter@v8
86+
87+
id: ml
88+
89+
# All available variables are described in documentation
90+
# https://megalinter.io/latest/configuration/
91+
env:
92+
# Validates all source when push on main, else just the git diff with
93+
# main. Override with true if you always want to lint all sources
94+
#
95+
# To validate the entire codebase, set to:
96+
# VALIDATE_ALL_CODEBASE: true
97+
#
98+
# To validate only diff with main, set to:
99+
# VALIDATE_ALL_CODEBASE: >-
100+
# ${{
101+
# github.event_name == 'push' &&
102+
# contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref)
103+
# }}
104+
VALIDATE_ALL_CODEBASE: >-
105+
${{
106+
github.event_name == 'push' &&
107+
contains(fromJSON('["refs/heads/${{inputs.DEFAULT_BRANCH}}"]'), github.ref)
108+
}}
109+
110+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
111+
112+
# ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE
113+
# .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
114+
115+
# Uncomment to disable copy-paste and spell checks
116+
# DISABLE: COPYPASTE,SPELL
117+
118+
# Upload MegaLinter artifacts
119+
- name: Archive production artifacts
120+
if: success() || failure()
121+
uses: actions/upload-artifact@v4
122+
with:
123+
name: MegaLinter reports
124+
include-hidden-files: "true"
125+
path: |
126+
megalinter-reports
127+
mega-linter.log
128+
129+
# Set APPLY_FIXES_IF var for use in future steps
130+
- name: Set APPLY_FIXES_IF var
131+
run: |
132+
printf 'APPLY_FIXES_IF=%s\n' "${{
133+
steps.ml.outputs.has_updated_sources == 1 &&
134+
(
135+
env.APPLY_FIXES_EVENT == 'all' ||
136+
env.APPLY_FIXES_EVENT == github.event_name
137+
) &&
138+
(
139+
github.event_name == 'push' ||
140+
github.event.pull_request.head.repo.full_name == github.repository
141+
)
142+
}}" >> "${GITHUB_ENV}"
143+
144+
# Set APPLY_FIXES_IF_* vars for use in future steps
145+
- name: Set APPLY_FIXES_IF_* vars
146+
run: |
147+
printf 'APPLY_FIXES_IF_PR=%s\n' "${{
148+
env.APPLY_FIXES_IF == 'true' &&
149+
env.APPLY_FIXES_MODE == 'pull_request'
150+
}}" >> "${GITHUB_ENV}"
151+
printf 'APPLY_FIXES_IF_COMMIT=%s\n' "${{
152+
env.APPLY_FIXES_IF == 'true' &&
153+
env.APPLY_FIXES_MODE == 'commit' &&
154+
(!contains(fromJSON('["refs/heads/${{ inputs.DEFAULT_BRANCH }}"]'), github.ref))
155+
}}" >> "${GITHUB_ENV}"
156+
157+
# Create pull request if applicable
158+
# (for now works only on PR from same repository, not from forks)
159+
- name: Create Pull Request with applied fixes
160+
uses: peter-evans/create-pull-request@v6
161+
id: cpr
162+
if: env.APPLY_FIXES_IF_PR == 'true'
163+
with:
164+
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
165+
commit-message: "[MegaLinter] Apply linters automatic fixes"
166+
title: "[MegaLinter] Apply linters automatic fixes"
167+
labels: bot
168+
169+
- name: Create PR output
170+
if: env.APPLY_FIXES_IF_PR == 'true'
171+
run: |
172+
echo "PR Number - ${{ steps.cpr.outputs.pull-request-number }}"
173+
echo "PR URL - ${{ steps.cpr.outputs.pull-request-url }}"
174+
175+
# Push new commit if applicable
176+
# (for now works only on PR from same repository, not from forks)
177+
- name: Prepare commit
178+
if: env.APPLY_FIXES_IF_COMMIT == 'true'
179+
run: sudo chown -Rc $UID .git/
180+
181+
- name: Commit and push applied linter fixes
182+
uses: stefanzweifel/git-auto-commit-action@v4
183+
if: env.APPLY_FIXES_IF_COMMIT == 'true'
184+
with:
185+
branch: >-
186+
${{
187+
github.event.pull_request.head.ref ||
188+
github.head_ref ||
189+
github.ref
190+
}}
191+
commit_message: "[MegaLinter] Apply linters fixes"
192+
commit_user_name: megalinter-bot
193+
commit_user_email: 129584137+megalinter-bot@users.noreply.github.com
194+
195+
- name: Upload MegaLinter scan results to GitHub Security tab
196+
if: success() || failure()
197+
uses: github/codeql-action/upload-sarif@v3
198+
with:
199+
sarif_file: 'megalinter-reports/megalinter-report.sarif'
200+
category: mega linter

.jscpd.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"threshold": 0,
3+
"reporters": ["html", "console", "sarif"],
4+
"ignore": ["**/__snapshots__/**", "**/node_modules/**", "**/test/**"],
5+
"absolute": true
6+
}

.mega-linter.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ENABLE:
2+
- JAVASCRIPT
3+
- TYPESCRIPT
4+
- PHP
5+
- HTML
6+
- COPYPASTE
7+
- CSS

0 commit comments

Comments
 (0)