-
-
Notifications
You must be signed in to change notification settings - Fork 2
112 lines (94 loc) · 3.75 KB
/
composer-dependency-health.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: Composer Dependency Health Check
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
schedule:
- cron: '0 0 * * 1' # Run weekly on Mondays
jobs:
dependency-check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, dom, filter, gd, iconv, json, mbstring, pdo
coverage: none
- name: Validate composer.json and composer.lock
run: composer validate
- name: Get Composer Cache Directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
run: composer install --prefer-dist --no-progress
continue-on-error: true
- name: Capture dependency versions
if: always()
run: |
echo "# Installed Packages" > dependency_versions.txt
composer show >> dependency_versions.txt
echo "# composer.json" >> dependency_versions.txt
cat composer.json >> dependency_versions.txt
echo "# composer.lock" >> dependency_versions.txt
cat composer.lock >> dependency_versions.txt
- name: Check for outdated dependencies
if: always()
run: |
composer outdated --direct --format=json > outdated.json || echo '{"installed":[]}' > outdated.json
- name: Security Check
if: always()
uses: symfonycorp/security-checker-action@v5
continue-on-error: true
- name: Process and Output Dependency Health Results
if: always()
run: |
OUTDATED=$(jq '.installed | length' outdated.json)
if [ ! -f security-checker.json ]; then
VULNERABILITIES=0
else
VULNERABILITIES=$(jq 'length' security-checker.json)
fi
if [ "$OUTDATED" != "0" ] || [ "$VULNERABILITIES" != "0" ]; then
echo "status=issues_found" >> $GITHUB_OUTPUT
else
echo "status=healthy" >> $GITHUB_OUTPUT
fi
echo "# Composer Dependency Health Report" >> $GITHUB_STEP_SUMMARY
echo "## Outdated Packages:" >> $GITHUB_STEP_SUMMARY
if [ "$OUTDATED" != "0" ]; then
jq -r '.installed[] | "- \(.name) (current: \(.version), latest: \(.latest))"' outdated.json >> $GITHUB_STEP_SUMMARY
else
echo "No outdated packages found." >> $GITHUB_STEP_SUMMARY
fi
echo "## Security Vulnerabilities:" >> $GITHUB_STEP_SUMMARY
if [ -f security-checker.json ] && [ -s security-checker.json ]; then
jq -r 'to_entries[] | "- \(.key): \(.value.advisories | map(.title) | join(", "))"' security-checker.json >> $GITHUB_STEP_SUMMARY
else
echo "No security vulnerabilities detected." >> $GITHUB_STEP_SUMMARY
fi
- name: Upload artifact
uses: actions/upload-artifact@v4
if: always()
with:
name: composer-dependency-report
path: |
outdated.json
security-checker.json
dependency_versions.txt
- name: Check status
if: always()
run: |
if [ "${{ steps.process-results.outputs.status }}" = "issues_found" ]; then
echo "Issues found in dependency health check. Please review the artifact for details."
exit 1
fi