|
| 1 | +name: Dependencies |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Run every Monday at 9 AM UTC |
| 6 | + - cron: "0 9 * * 1" |
| 7 | + workflow_dispatch: # Allow manual triggering |
| 8 | + |
| 9 | +jobs: |
| 10 | + dependencies: |
| 11 | + name: Check Dependencies |
| 12 | + |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout code |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Setup PHP |
| 20 | + uses: shivammathur/setup-php@v2 |
| 21 | + with: |
| 22 | + php-version: 8.3 |
| 23 | + extensions: mbstring, xml, ctype, iconv, intl |
| 24 | + |
| 25 | + - name: Install dependencies |
| 26 | + run: composer install --prefer-dist --no-interaction |
| 27 | + |
| 28 | + - name: Check for outdated packages |
| 29 | + run: composer outdated --direct --format=json --output=composer-outdated.json |
| 30 | + continue-on-error: true |
| 31 | + |
| 32 | + - name: Check for security vulnerabilities |
| 33 | + run: composer audit --format=json --output=composer-audit.json |
| 34 | + continue-on-error: true |
| 35 | + |
| 36 | + - name: Upload dependency check results |
| 37 | + uses: actions/upload-artifact@v4 |
| 38 | + if: always() |
| 39 | + with: |
| 40 | + name: dependency-checks |
| 41 | + path: | |
| 42 | + composer-outdated.json |
| 43 | + composer-audit.json |
| 44 | +
|
| 45 | + - name: Create issue for security vulnerabilities |
| 46 | + if: failure() |
| 47 | + uses: actions/github-script@v7 |
| 48 | + with: |
| 49 | + script: | |
| 50 | + const fs = require('fs'); |
| 51 | + let auditData = {}; |
| 52 | +
|
| 53 | + try { |
| 54 | + const auditContent = fs.readFileSync('composer-audit.json', 'utf8'); |
| 55 | + auditData = JSON.parse(auditContent); |
| 56 | + } catch (error) { |
| 57 | + console.log('No audit data found'); |
| 58 | + } |
| 59 | +
|
| 60 | + if (auditData.advisories && Object.keys(auditData.advisories).length > 0) { |
| 61 | + const issueTitle = '🚨 Security vulnerabilities detected in dependencies'; |
| 62 | + const issueBody = `## Security Alert |
| 63 | + |
| 64 | + Security vulnerabilities were detected in the package dependencies. |
| 65 | + |
| 66 | + ### Vulnerabilities Found: |
| 67 | + ${Object.values(auditData.advisories).map(adv => |
| 68 | + `- **${adv.packageName}** (${adv.affectedVersions}): ${adv.title}` |
| 69 | + ).join('\n')} |
| 70 | + |
| 71 | + ### Recommended Actions: |
| 72 | + 1. Review the vulnerabilities above |
| 73 | + 2. Update affected packages to secure versions |
| 74 | + 3. Test thoroughly after updates |
| 75 | + 4. Consider using \`composer audit --fix\` if available |
| 76 | + |
| 77 | + --- |
| 78 | + *This issue was automatically created by GitHub Actions*`; |
| 79 | + |
| 80 | + await github.rest.issues.create({ |
| 81 | + owner: context.repo.owner, |
| 82 | + repo: context.repo.repo, |
| 83 | + title: issueTitle, |
| 84 | + body: issueBody, |
| 85 | + labels: ['security', 'dependencies', 'automated'] |
| 86 | + }); |
| 87 | + } |
0 commit comments