Repository navigation
201 lines (174 loc) · 7.64 KB
/
Copy pathcheck-php-extensions.yml
File metadata and controls
201 lines (174 loc) · 7.64 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
name: Check PHP extension versions
on:
schedule:
# Run weekly on Monday at 08:00 UTC.
- cron: '0 8 * * 1'
workflow_dispatch: {} # Allow manual trigger from the Actions tab.
permissions:
issues: write
contents: read
jobs:
check:
name: Check for outdated PECL extensions
runs-on: ubuntu-latest
steps:
- name: Checkout binary-builder
uses: actions/checkout@v4
- name: Checkout buildpacks-ci (for bump-versions.rb)
uses: actions/checkout@v4
with:
repository: cloudfoundry/buildpacks-ci
path: buildpacks-ci
- name: Checkout php-buildpack (authoritative extension config)
uses: actions/checkout@v4
with:
repository: cloudfoundry/php-buildpack
path: php-buildpack
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
- name: Install Ruby dependencies
working-directory: buildpacks-ci/scripts/php-modules
run: bundle install --jobs 4 --retry 3
- name: Determine extension config directory
id: ext-dir
run: |
# Prefer php-buildpack (authoritative after Phase 2+3), fall back to
# binary-builder assets/ (pre-Phase 5) or testdata/ (post-Phase 5).
if [ -d "php-buildpack/config/extensions" ]; then
echo "path=php-buildpack/config/extensions" >> "$GITHUB_OUTPUT"
elif [ -d "internal/php/assets" ]; then
echo "path=${{ github.workspace }}/internal/php/assets" >> "$GITHUB_OUTPUT"
elif [ -d "internal/php/testdata" ]; then
echo "path=${{ github.workspace }}/internal/php/testdata" >> "$GITHUB_OUTPUT"
else
echo "::error::No extension YAML directory found"
exit 1
fi
- name: Check for outdated extensions
id: check
working-directory: buildpacks-ci/scripts/php-modules
env:
EXTENSIONS_DIR: ${{ steps.ext-dir.outputs.path }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set +e
bundle exec ruby bump-versions.rb --dry-run --format=json > /tmp/report.json 2>/tmp/check-stderr.log
exit_code=$?
set -e
cat /tmp/check-stderr.log >&2
if [ $exit_code -ne 0 ]; then
echo "bump-versions.rb failed with exit code $exit_code"
echo "has_updates=false" >> "$GITHUB_OUTPUT"
exit 0
fi
# Parse the JSON report to determine if there are outdated extensions.
outdated_count=$(jq '.outdated | length' /tmp/report.json)
error_count=$(jq '.error_count' /tmp/report.json)
echo "outdated_count=${outdated_count}" >> "$GITHUB_OUTPUT"
echo "error_count=${error_count}" >> "$GITHUB_OUTPUT"
if [ "$outdated_count" -gt 0 ]; then
echo "has_updates=true" >> "$GITHUB_OUTPUT"
else
echo "has_updates=false" >> "$GITHUB_OUTPUT"
fi
# Make report available to downstream steps.
cp /tmp/report.json "$GITHUB_WORKSPACE/report.json"
- name: Create or update GitHub issue
if: steps.check.outputs.has_updates == 'true'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const report = JSON.parse(fs.readFileSync('report.json', 'utf8'));
const title = `[Automated] PHP extensions: ${report.outdated.length} outdated version(s) detected`;
const label = 'php-extensions';
// Build the issue body as a markdown table.
let body = `## PHP Extension Version Check\n\n`;
body += `**Checked at:** ${report.checked_at}\n\n`;
if (report.outdated.length > 0) {
body += `### Outdated Extensions\n\n`;
body += `| Extension | Type | Current | Latest |\n`;
body += `|-----------|------|---------|--------|\n`;
for (const item of report.outdated) {
body += `| ${item.name} | ${item.klass} | ${item.current} | ${item.latest} |\n`;
}
}
body += `\n**Up to date:** ${report.up_to_date_count} extension(s)\n`;
if (report.errors.length > 0) {
body += `\n### Errors\n\n`;
for (const err of report.errors) {
body += `- **${err.name}** (${err.klass}): ${err.message}\n`;
}
}
body += `\n---\n`;
body += `*This issue was automatically created by the [Check PHP extension versions](${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}) workflow.*\n`;
body += `\n### Next Steps\n\n`;
body += `1. Review the outdated extensions above\n`;
body += `2. Check PHP version compatibility for each bump\n`;
body += `3. Run \`bump-versions.sh\` locally (in buildpacks-ci/scripts/php-modules/), review the diff\n`;
body += `4. Run \`update-hashes.sh\` to recompute MD5 hashes\n`;
body += `5. Open a PR with the version bumps against the repo that owns the extension YAML files\n`;
// Ensure the label exists.
try {
await github.rest.issues.getLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: label,
});
} catch (e) {
if (e.status === 404) {
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: label,
color: 'c5def5',
description: 'PHP extension version updates',
});
}
}
// Check if an open issue with this label already exists.
const { data: existingIssues } = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
labels: label,
state: 'open',
per_page: 1,
});
if (existingIssues.length > 0) {
// Update the existing issue.
const issue = existingIssues[0];
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
title: title,
body: body,
});
core.info(`Updated existing issue #${issue.number}`);
} else {
// Create a new issue.
const { data: newIssue } = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: title,
body: body,
labels: [label],
});
core.info(`Created issue #${newIssue.number}`);
}
- name: Summary
if: always()
run: |
echo "## PHP Extension Check Results" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "- **Outdated:** ${{ steps.check.outputs.outdated_count || 0 }}" >> "$GITHUB_STEP_SUMMARY"
echo "- **Errors:** ${{ steps.check.outputs.error_count || 0 }}" >> "$GITHUB_STEP_SUMMARY"
if [ "${{ steps.check.outputs.has_updates }}" = "true" ]; then
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "A GitHub issue has been created/updated with details." >> "$GITHUB_STEP_SUMMARY"
else
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "All extensions are up to date." >> "$GITHUB_STEP_SUMMARY"
fi