Skip to content

Commit d57ff4d

Browse files
committed
optimize opcache:clear
1 parent 2922e53 commit d57ff4d

3 files changed

Lines changed: 99 additions & 6 deletions

File tree

.github/workflows/release.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- '**'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Check out tagged revision
17+
uses: actions/checkout@v4
18+
with:
19+
ref: ${{ github.ref }}
20+
21+
- name: Create or update release
22+
env:
23+
GH_TOKEN: ${{ github.token }}
24+
TAG: ${{ github.ref_name }}
25+
shell: bash
26+
run: |
27+
set -euo pipefail
28+
29+
notes_file="${RUNNER_TEMP}/release-notes.md"
30+
31+
awk -v tag="${TAG}" '
32+
function changelog_tag(line, closing_bracket) {
33+
closing_bracket = index(line, "]")
34+
35+
if (closing_bracket == 0) {
36+
return ""
37+
}
38+
39+
return substr(line, 5, closing_bracket - 5)
40+
}
41+
42+
/^## \[/ {
43+
if (in_section) {
44+
exit
45+
}
46+
47+
if (tag != "Unreleased" && changelog_tag($0) == tag) {
48+
in_section = 1
49+
}
50+
51+
next
52+
}
53+
54+
in_section {
55+
lines[++line_count] = $0
56+
}
57+
58+
END {
59+
while (line_count > 0 && lines[line_count] == "") {
60+
--line_count
61+
}
62+
63+
for (line_number = 1; line_number <= line_count; ++line_number) {
64+
print lines[line_number]
65+
}
66+
}
67+
' CHANGELOG.md > "${notes_file}"
68+
69+
if existing_notes="$(gh release view "${TAG}" --json body --jq '.body')"; then
70+
if [[ -n "${existing_notes}" ]]; then
71+
echo "Release ${TAG} already has notes; leaving it unchanged."
72+
elif [[ -s "${notes_file}" ]]; then
73+
gh release edit "${TAG}" --notes-file "${notes_file}"
74+
else
75+
echo "Release ${TAG} has no notes and no matching changelog section."
76+
fi
77+
78+
exit 0
79+
fi
80+
81+
gh release create "${TAG}" --title "${TAG}" --notes-file "${notes_file}"

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ dep cache:clear
209209
dep opcache:clear
210210
```
211211

212+
If the automatic request fails, for example because the website is protected by HTTP Basic Authentication,
213+
the task prints the temporary opcache-clear URL so it can be opened in an authenticated browser. It then asks
214+
whether the temporary file should be deleted.
215+
212216
### Deploy assets only (encore build folder)
213217

214218
```bash

recipe-huh/contao/tasks.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,18 @@
113113

114114
writeln('Execute cache clear file', OutputInterface::VERBOSITY_VERBOSE);
115115
$url = rtrim(parse('{{public_url}}'), '/').'/'.$tmpFileName;
116-
$result = run("cd $path && curl -kL -A \"deployer/clear_opt_cache\" $url");
116+
$result = run("cd $path && curl -kL -A \"deployer/clear_opt_cache\" $url", ['no_throw' => true]);
117+
118+
if (!in_array((int) $result, [1, 2], true)) {
119+
warning('Failed to clear opcache automatically.');
120+
writeln('Open the following URL in a browser to clear it manually:');
121+
writeln($url);
122+
123+
if (!askConfirmation('Delete the temporary opcache clear file?', true)) {
124+
warning('The temporary opcache clear file was not deleted.');
125+
return;
126+
}
127+
}
117128

118129
writeln('Remove tmp cache clear file', OutputInterface::VERBOSITY_VERBOSE);
119130
run("cd $path && rm $tmpFileName");
@@ -123,12 +134,9 @@
123134
return;
124135
}
125136

126-
if (1 !== (int)$result) {
127-
warning('Failed to clear opcache.');
128-
return;
137+
if (1 === (int)$result) {
138+
info('Opcache cleared!');
129139
}
130-
131-
info('Opcache cleared!');
132140
});
133141

134142
desc('Alias for opcache:clear');

0 commit comments

Comments
 (0)