Skip to content

Commit d9f0648

Browse files
authored
Remove sonar #591
2 parents ab95226 + a79b4ad commit d9f0648

File tree

6 files changed

+344
-37
lines changed

6 files changed

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

.github/workflows/mega-linter.yml

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
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: write-all
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+
steps:
63+
# Git Checkout
64+
- name: Checkout Code
65+
uses: actions/checkout@v4
66+
with:
67+
token: ${{ secrets.GITHUB_TOKEN }}
68+
69+
# If you use VALIDATE_ALL_CODEBASE = true, you can remove this line to
70+
# improve performance
71+
fetch-depth: 0
72+
73+
# MegaLinter
74+
- name: MegaLinter
75+
76+
# You can override MegaLinter flavor used to have faster performances
77+
# More info at https://megalinter.io/latest/flavors/
78+
uses: oxsecurity/megalinter@v8
79+
80+
id: ml
81+
82+
# All available variables are described in documentation
83+
# https://megalinter.io/latest/configuration/
84+
env:
85+
# Validates all source when push on main, else just the git diff with
86+
# main. Override with true if you always want to lint all sources
87+
#
88+
# To validate the entire codebase, set to:
89+
# VALIDATE_ALL_CODEBASE: true
90+
#
91+
# To validate only diff with main, set to:
92+
# VALIDATE_ALL_CODEBASE: >-
93+
# ${{
94+
# github.event_name == 'push' &&
95+
# contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref)
96+
# }}
97+
VALIDATE_ALL_CODEBASE: >-
98+
${{
99+
github.event_name == 'push' &&
100+
contains(fromJSON('["refs/heads/${{inputs.DEFAULT_BRANCH}}"]'), github.ref)
101+
}}
102+
103+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
104+
105+
# ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE
106+
# .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
107+
108+
# Uncomment to disable copy-paste and spell checks
109+
# DISABLE: COPYPASTE,SPELL
110+
111+
# Upload MegaLinter artifacts
112+
- name: Archive production artifacts
113+
if: success() || failure()
114+
uses: actions/upload-artifact@v4
115+
with:
116+
name: MegaLinter reports
117+
include-hidden-files: "true"
118+
path: |
119+
megalinter-reports
120+
mega-linter.log
121+
122+
# Set APPLY_FIXES_IF var for use in future steps
123+
- name: Set APPLY_FIXES_IF var
124+
run: |
125+
printf 'APPLY_FIXES_IF=%s\n' "${{
126+
steps.ml.outputs.has_updated_sources == 1 &&
127+
(
128+
env.APPLY_FIXES_EVENT == 'all' ||
129+
env.APPLY_FIXES_EVENT == github.event_name
130+
) &&
131+
(
132+
github.event_name == 'push' ||
133+
github.event.pull_request.head.repo.full_name == github.repository
134+
)
135+
}}" >> "${GITHUB_ENV}"
136+
137+
# Set APPLY_FIXES_IF_* vars for use in future steps
138+
- name: Set APPLY_FIXES_IF_* vars
139+
run: |
140+
printf 'APPLY_FIXES_IF_PR=%s\n' "${{
141+
env.APPLY_FIXES_IF == 'true' &&
142+
env.APPLY_FIXES_MODE == 'pull_request'
143+
}}" >> "${GITHUB_ENV}"
144+
printf 'APPLY_FIXES_IF_COMMIT=%s\n' "${{
145+
env.APPLY_FIXES_IF == 'true' &&
146+
env.APPLY_FIXES_MODE == 'commit' &&
147+
(!contains(fromJSON('["refs/heads/${{ inputs.DEFAULT_BRANCH }}"]'), github.ref))
148+
}}" >> "${GITHUB_ENV}"
149+
150+
# Create pull request if applicable
151+
# (for now works only on PR from same repository, not from forks)
152+
- name: Create Pull Request with applied fixes
153+
uses: peter-evans/create-pull-request@v6
154+
id: cpr
155+
if: env.APPLY_FIXES_IF_PR == 'true'
156+
with:
157+
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
158+
commit-message: "[MegaLinter] Apply linters automatic fixes"
159+
title: "[MegaLinter] Apply linters automatic fixes"
160+
labels: bot
161+
162+
- name: Create PR output
163+
if: env.APPLY_FIXES_IF_PR == 'true'
164+
run: |
165+
echo "PR Number - ${{ steps.cpr.outputs.pull-request-number }}"
166+
echo "PR URL - ${{ steps.cpr.outputs.pull-request-url }}"
167+
168+
# Push new commit if applicable
169+
# (for now works only on PR from same repository, not from forks)
170+
- name: Prepare commit
171+
if: env.APPLY_FIXES_IF_COMMIT == 'true'
172+
run: sudo chown -Rc $UID .git/
173+
174+
- name: Commit and push applied linter fixes
175+
uses: stefanzweifel/git-auto-commit-action@v4
176+
if: env.APPLY_FIXES_IF_COMMIT == 'true'
177+
with:
178+
branch: >-
179+
${{
180+
github.event.pull_request.head.ref ||
181+
github.head_ref ||
182+
github.ref
183+
}}
184+
commit_message: "[MegaLinter] Apply linters fixes"
185+
commit_user_name: megalinter-bot
186+
commit_user_email: 129584137+megalinter-bot@users.noreply.github.com
187+
188+
- name: Upload MegaLinter scan results to GitHub Security tab
189+
if: success() || failure()
190+
continue-on-error: true
191+
uses: github/codeql-action/upload-sarif@v3
192+
with:
193+
sarif_file: 'megalinter-reports/megalinter-report.sarif'
194+
category: mega linter

.github/workflows/pr.yml

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -72,45 +72,15 @@ jobs:
7272
version: ${{ vars.phpunit_version }}
7373
php_version : ${{ vars.unit_tests_php_version }}
7474
php_extensions: "xdebug"
75-
coverage_clover: "coverage/clover.xml"
75+
coverage_clover: "lcov.info"
7676

7777
- name: Upload coverage artifact
7878
uses: actions/upload-artifact@master
7979
with:
8080
name: woo-coverage-${{ github.sha }}
81-
path: coverage/clover.xml
82-
83-
sonar:
84-
name: Sonar
85-
runs-on: ubuntu-latest
86-
needs: phpunit
87-
steps:
88-
- name: Checkout project
89-
uses: actions/checkout@v3
90-
with:
91-
fetch-depth: 0
92-
93-
- name: Download coverage artifact
94-
uses: actions/download-artifact@master
95-
with:
96-
name: woo-coverage-${{ github.sha }}
97-
path: coverage
98-
99-
- name: Run Sonar
100-
uses: sonarsource/sonarcloud-github-action@master
101-
env:
102-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
103-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
104-
with:
105-
args: >
106-
-Dsonar.php.coverage.reportPaths=coverage/clover.xml
107-
-Dsonar.coverage.exclusions=tests/**,assets/**,src/Controller/**,templates/**,woo-pagarme-payments.php
108-
-Dsonar.tests=tests/
109-
-Dsonar.sources=src,assets,templates,woo-pagarme-payments.php
110-
111-
- name: Delete coverage artifact
112-
uses: geekyeggo/delete-artifact@v4
113-
with:
114-
token: ${{ secrets.GITHUB_TOKEN }}
115-
name: woo-coverage-${{ github.sha }}
81+
path: lcov.info
11682

83+
mega_linter:
84+
uses: ./.github/workflows/mega-linter.yml
85+
with:
86+
RUNS_ON: ubuntu-latest

.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)