Skip to content

Commit 1068103

Browse files
committed
feat: initial prototype
0 parents  commit 1068103

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+8637
-0
lines changed

Diff for: .dockerignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.php-cs-fixer.cache
2+
/.prettier.cache
3+
4+
/vendor/
5+
/coverage/
6+
/phpmetrics/
7+
/tests/

Diff for: .github/dependabot.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
version: 2
3+
updates:
4+
- package-ecosystem: 'github-actions'
5+
directory: '/'
6+
schedule:
7+
interval: 'daily'
8+
9+
- package-ecosystem: 'composer'
10+
directory: '/'
11+
schedule:
12+
interval: 'daily'
13+
14+
- package-ecosystem: 'docker'
15+
directory: '/'
16+
schedule:
17+
interval: 'daily'
18+
19+
- package-ecosystem: 'npm'
20+
directory: '/tests/prettier'
21+
schedule:
22+
interval: 'daily'
23+
24+
- package-ecosystem: 'docker'
25+
directory: '/tests/prettier'
26+
schedule:
27+
interval: 'daily'

Diff for: .github/workflows/example-coverage.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
on:
3+
workflow_call:
4+
inputs:
5+
command:
6+
type: string
7+
required: true
8+
9+
jobs:
10+
phpspec:
11+
runs-on: ubuntu-latest
12+
env:
13+
COMPOSE_FILE: tests/compose.yaml
14+
steps:
15+
- uses: actions/checkout@v4
16+
- run: make phpspec
17+
- name: XPath
18+
id: xpath
19+
run: |
20+
sudo apt-get install -y libxml-xpath-perl
21+
22+
PERCENT=$(cat coverage/phpspec/index.xml | xpath -q -e '/phpunit/project/directory[@name="/"]/totals/lines/@percent' | cut -f 2 -d "=" | tr -d \")
23+
24+
echo "phpspec=${PERCENT}" > $GITHUB_OUTPUT
25+
- uses: KnpLabs/[email protected]
26+
with:
27+
report: coverage
28+
command: ${{ inputs.command }}
29+
values: ${{ toJson(steps.xpath.outputs) }}

Diff for: .github/workflows/example-github-security.yaml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
on: workflow_call
3+
4+
jobs:
5+
metric:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/github-script@v7
9+
id: script
10+
with:
11+
script: |
12+
const query = `
13+
query($cursor: String, $owner: String!, $repo: String!) {
14+
repository(owner: $owner, name: $repo) {
15+
vulnerabilityAlerts(states: OPEN, first: 100, after: $cursor) {
16+
pageInfo {
17+
endCursor
18+
}
19+
nodes {
20+
securityVulnerability {
21+
severity
22+
}
23+
}
24+
}
25+
}
26+
}
27+
`;
28+
29+
let cursor = null;
30+
const countBySeverity = {CRITICAL: 0, HIGH: 0, MODERATE: 0, LOW: 0};
31+
32+
do {
33+
const result = await github.graphql(
34+
query,
35+
{
36+
owner: context.repo.owner,
37+
repo: context.repo.repo,
38+
cursor: cursor,
39+
}
40+
);
41+
42+
for(const alert of result.repository.vulnerabilityAlerts.nodes) {
43+
if (!countBySeverity[alert.securityVulnerability.severity]) {
44+
countBySeverity[alert.securityVulnerability.severity] = 0;
45+
}
46+
47+
countBySeverity[alert.securityVulnerability.severity]++;
48+
}
49+
50+
cursor = result.repository.vulnerabilityAlerts.pageInfo.endCursor;
51+
} while(null !== cursor)
52+
53+
return countBySeverity;
54+
- uses: actions/checkout@v4
55+
- uses: KnpLabs/[email protected]
56+
with:
57+
report: github-security
58+
command: compile
59+
values: ${{ steps.script.outputs.result }}

Diff for: .github/workflows/example-phpmetrics.yaml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
on:
3+
workflow_call:
4+
inputs:
5+
command:
6+
type: string
7+
required: true
8+
9+
jobs:
10+
phpmetrics:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
report: ${{ steps.phpmetrics.outputs.result }}
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: shivammathur/setup-php@v2
17+
with:
18+
php-version: latest
19+
tools: phpmetrics/phpmetrics
20+
- name: Compile
21+
run: |
22+
mkdir phpmetrics -p
23+
phpmetrics src --report-html=phpmetrics --report-json=phpmetrics/report.json
24+
25+
echo "report=$(cat phpmetrics/report.json | jq . --compact-output)" > $GITHUB_OUTPUT
26+
- name: Dump
27+
id: phpmetrics
28+
uses: actions/github-script@v7
29+
with:
30+
script: return require('./phpmetrics/report.json');
31+
32+
report:
33+
name: ${{ matrix.report }}
34+
runs-on: ubuntu-latest
35+
needs: phpmetrics
36+
strategy:
37+
matrix:
38+
include:
39+
- report: outdated-dependencies
40+
query: '{"composer.json": .composer.packages|map(select(.status=="outdated"))|length}'
41+
- report: class-bugs
42+
query: '. | to_entries | map({key: .key, value: .value.bugs}) | map(select(.value != null)) | from_entries'
43+
steps:
44+
- name: jq
45+
id: jq
46+
env:
47+
QUERY: ${{ matrix.query }}
48+
REPORT: ${{ needs.phpmetrics.outputs.report }}
49+
run: |
50+
echo $REPORT > /tmp/report.json
51+
echo report=$(cat /tmp/report.json | jq "$QUERY" --compact-output --raw-output) > $GITHUB_OUTPUT
52+
- uses: actions/checkout@v4
53+
- uses: KnpLabs/[email protected]
54+
with:
55+
report: ${{ matrix.report }}
56+
command: ${{ inputs.command }}
57+
values: ${{ steps.jq.outputs.report }}

Diff for: .github/workflows/pull-request.yaml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
on: pull_request
3+
4+
permissions:
5+
statuses: write
6+
7+
jobs:
8+
autoformat:
9+
runs-on: ubuntu-latest
10+
env:
11+
COMPOSE_FILE: tests/compose.yaml
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: actions/cache@v4
15+
with:
16+
path: vendor
17+
key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }}
18+
restore-keys: |
19+
${{ runner.os }}-composer-
20+
- name: make autoformat
21+
run: make autoformat > /dev/null
22+
- name: git status
23+
run: |
24+
if [ -z $(git status --porcelain) ];
25+
then
26+
echo "Looks good"
27+
else
28+
echo "Some files need to be corrected, so run 'make autoformat' to apply a correction"
29+
echo git status
30+
exit 1
31+
fi
32+
phpmetrics:
33+
uses: ./.github/workflows/example-phpmetrics.yaml
34+
with:
35+
command: check
36+
coverage:
37+
uses: ./.github/workflows/example-coverage.yaml
38+
with:
39+
command: check

Diff for: .github/workflows/push.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
github-security:
9+
uses: ./.github/workflows/example-github-security.yaml
10+
phpmetrics:
11+
uses: ./.github/workflows/example-phpmetrics.yaml
12+
with:
13+
command: compile
14+
coverage:
15+
uses: ./.github/workflows/example-coverage.yaml
16+
with:
17+
command: compile

Diff for: .github/workflows/schedule.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
on:
3+
schedule:
4+
- cron: '0 6 * * 1-5' # Mon to Fri at 8:00 (Paris GMT+2)
5+
6+
jobs:
7+
github-security:
8+
uses: ./.github/workflows/example-github-security.yaml
9+
phpmetrics:
10+
uses: ./.github/workflows/example-phpmetrics.yaml
11+
with:
12+
command: compile
13+
coverage:
14+
uses: ./.github/workflows/example-coverage.yaml
15+
with:
16+
command: compile

Diff for: .gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/.php-cs-fixer.cache
2+
/.prettier.cache
3+
4+
/phpmetrics/
5+
/vendor/

Diff for: .k-pi.dist.yaml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
reports:
3+
github-security:
4+
extra:
5+
Total: total
6+
colors:
7+
LOW: '#808080'
8+
MODERATE: '#FFFF00'
9+
HIGH: '#FFC100'
10+
CRITICAL: '#FF0000'
11+
storage:
12+
github-discussion:
13+
url: https://github.com/KnpLabs/K-pi/discussions/4
14+
coverage:
15+
storage:
16+
github-discussion:
17+
url: https://github.com/KnpLabs/K-pi/discussions/1
18+
check-reporter:
19+
github-status:
20+
states: higher-is-better
21+
unit: '%'
22+
outdated-dependencies:
23+
storage:
24+
github-discussion:
25+
url: https://github.com/KnpLabs/K-pi/discussions/2
26+
check-reporter:
27+
github-status:
28+
states: lower-is-better
29+
unit:
30+
singular: ' dependency'
31+
plural: ' dependencies'
32+
class-bugs:
33+
storage:
34+
github-discussion:
35+
url: https://github.com/KnpLabs/K-pi/discussions/3
36+
check-reporter:
37+
github-status:
38+
states:
39+
on-lower: success
40+
on-higher: success
41+
unit:
42+
singular: ' bug'
43+
plural: ' bugs'

0 commit comments

Comments
 (0)