Skip to content

Commit

Permalink
feat: initial prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroTroller committed Mar 27, 2024
0 parents commit 1068103
Show file tree
Hide file tree
Showing 77 changed files with 8,637 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.php-cs-fixer.cache
/.prettier.cache

/vendor/
/coverage/
/phpmetrics/
/tests/
27 changes: 27 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
version: 2
updates:
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'daily'

- package-ecosystem: 'composer'
directory: '/'
schedule:
interval: 'daily'

- package-ecosystem: 'docker'
directory: '/'
schedule:
interval: 'daily'

- package-ecosystem: 'npm'
directory: '/tests/prettier'
schedule:
interval: 'daily'

- package-ecosystem: 'docker'
directory: '/tests/prettier'
schedule:
interval: 'daily'
29 changes: 29 additions & 0 deletions .github/workflows/example-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
on:
workflow_call:
inputs:
command:
type: string
required: true

jobs:
phpspec:
runs-on: ubuntu-latest
env:
COMPOSE_FILE: tests/compose.yaml
steps:
- uses: actions/checkout@v4
- run: make phpspec
- name: XPath
id: xpath
run: |
sudo apt-get install -y libxml-xpath-perl
PERCENT=$(cat coverage/phpspec/index.xml | xpath -q -e '/phpunit/project/directory[@name="/"]/totals/lines/@percent' | cut -f 2 -d "=" | tr -d \")
echo "phpspec=${PERCENT}" > $GITHUB_OUTPUT
- uses: KnpLabs/[email protected]
with:
report: coverage
command: ${{ inputs.command }}
values: ${{ toJson(steps.xpath.outputs) }}
59 changes: 59 additions & 0 deletions .github/workflows/example-github-security.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
on: workflow_call

jobs:
metric:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
id: script
with:
script: |
const query = `
query($cursor: String, $owner: String!, $repo: String!) {
repository(owner: $owner, name: $repo) {
vulnerabilityAlerts(states: OPEN, first: 100, after: $cursor) {
pageInfo {
endCursor
}
nodes {
securityVulnerability {
severity
}
}
}
}
}
`;
let cursor = null;
const countBySeverity = {CRITICAL: 0, HIGH: 0, MODERATE: 0, LOW: 0};
do {
const result = await github.graphql(
query,
{
owner: context.repo.owner,
repo: context.repo.repo,
cursor: cursor,
}
);
for(const alert of result.repository.vulnerabilityAlerts.nodes) {
if (!countBySeverity[alert.securityVulnerability.severity]) {
countBySeverity[alert.securityVulnerability.severity] = 0;
}
countBySeverity[alert.securityVulnerability.severity]++;
}
cursor = result.repository.vulnerabilityAlerts.pageInfo.endCursor;
} while(null !== cursor)
return countBySeverity;
- uses: actions/checkout@v4
- uses: KnpLabs/[email protected]
with:
report: github-security
command: compile
values: ${{ steps.script.outputs.result }}
57 changes: 57 additions & 0 deletions .github/workflows/example-phpmetrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
on:
workflow_call:
inputs:
command:
type: string
required: true

jobs:
phpmetrics:
runs-on: ubuntu-latest
outputs:
report: ${{ steps.phpmetrics.outputs.result }}
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: latest
tools: phpmetrics/phpmetrics
- name: Compile
run: |
mkdir phpmetrics -p
phpmetrics src --report-html=phpmetrics --report-json=phpmetrics/report.json
echo "report=$(cat phpmetrics/report.json | jq . --compact-output)" > $GITHUB_OUTPUT
- name: Dump
id: phpmetrics
uses: actions/github-script@v7
with:
script: return require('./phpmetrics/report.json');

report:
name: ${{ matrix.report }}
runs-on: ubuntu-latest
needs: phpmetrics
strategy:
matrix:
include:
- report: outdated-dependencies
query: '{"composer.json": .composer.packages|map(select(.status=="outdated"))|length}'
- report: class-bugs
query: '. | to_entries | map({key: .key, value: .value.bugs}) | map(select(.value != null)) | from_entries'
steps:
- name: jq
id: jq
env:
QUERY: ${{ matrix.query }}
REPORT: ${{ needs.phpmetrics.outputs.report }}
run: |
echo $REPORT > /tmp/report.json
echo report=$(cat /tmp/report.json | jq "$QUERY" --compact-output --raw-output) > $GITHUB_OUTPUT
- uses: actions/checkout@v4
- uses: KnpLabs/[email protected]
with:
report: ${{ matrix.report }}
command: ${{ inputs.command }}
values: ${{ steps.jq.outputs.report }}
39 changes: 39 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
on: pull_request

permissions:
statuses: write

jobs:
autoformat:
runs-on: ubuntu-latest
env:
COMPOSE_FILE: tests/compose.yaml
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: make autoformat
run: make autoformat > /dev/null
- name: git status
run: |
if [ -z $(git status --porcelain) ];
then
echo "Looks good"
else
echo "Some files need to be corrected, so run 'make autoformat' to apply a correction"
echo git status
exit 1
fi
phpmetrics:
uses: ./.github/workflows/example-phpmetrics.yaml
with:
command: check
coverage:
uses: ./.github/workflows/example-coverage.yaml
with:
command: check
17 changes: 17 additions & 0 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
on:
push:
branches:
- main

jobs:
github-security:
uses: ./.github/workflows/example-github-security.yaml
phpmetrics:
uses: ./.github/workflows/example-phpmetrics.yaml
with:
command: compile
coverage:
uses: ./.github/workflows/example-coverage.yaml
with:
command: compile
16 changes: 16 additions & 0 deletions .github/workflows/schedule.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
on:
schedule:
- cron: '0 6 * * 1-5' # Mon to Fri at 8:00 (Paris GMT+2)

jobs:
github-security:
uses: ./.github/workflows/example-github-security.yaml
phpmetrics:
uses: ./.github/workflows/example-phpmetrics.yaml
with:
command: compile
coverage:
uses: ./.github/workflows/example-coverage.yaml
with:
command: compile
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.php-cs-fixer.cache
/.prettier.cache

/phpmetrics/
/vendor/
43 changes: 43 additions & 0 deletions .k-pi.dist.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
reports:
github-security:
extra:
Total: total
colors:
LOW: '#808080'
MODERATE: '#FFFF00'
HIGH: '#FFC100'
CRITICAL: '#FF0000'
storage:
github-discussion:
url: https://github.com/KnpLabs/K-pi/discussions/4
coverage:
storage:
github-discussion:
url: https://github.com/KnpLabs/K-pi/discussions/1
check-reporter:
github-status:
states: higher-is-better
unit: '%'
outdated-dependencies:
storage:
github-discussion:
url: https://github.com/KnpLabs/K-pi/discussions/2
check-reporter:
github-status:
states: lower-is-better
unit:
singular: ' dependency'
plural: ' dependencies'
class-bugs:
storage:
github-discussion:
url: https://github.com/KnpLabs/K-pi/discussions/3
check-reporter:
github-status:
states:
on-lower: success
on-higher: success
unit:
singular: ' bug'
plural: ' bugs'
Loading

0 comments on commit 1068103

Please sign in to comment.