Skip to content

Commit 6beda55

Browse files
committed
ci: README deploy URL with conflict handling, main-only homepage update; fix: mismatched button/Link tag in header
1 parent 528c13b commit 6beda55

2 files changed

Lines changed: 104 additions & 1 deletion

File tree

.github/workflows/nextjs-static-gh-pages.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,29 @@ jobs:
2323
steps:
2424
- name: 🔍 Checkout repository
2525
uses: actions/checkout@v4
26+
with:
27+
token: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: 🧹 Strip stale deployment markers from README
30+
if: github.event_name == 'push'
31+
run: |
32+
if [ -f README.md ] && grep -q '<!-- DEPLOYMENT-URL:START -->' README.md; then
33+
echo "Stripping stale deployment markers from README..."
34+
# Remove everything between markers (inclusive), handling duplicates
35+
sed -i '/<!-- DEPLOYMENT-URL:START -->/,/<!-- DEPLOYMENT-URL:END -->/d' README.md
36+
# Also clean up any git conflict markers that might be left over
37+
sed -i '/^<<<<<<</d; /^=======/d; /^>>>>>>>/d' README.md
38+
# Remove resulting double-blank-lines
39+
sed -i '/^$/N;/^\n$/d' README.md
40+
if ! git diff --quiet README.md; then
41+
git config user.name "github-actions"
42+
git config user.email "github-actions@github.com"
43+
git add README.md
44+
git commit -m "ci: clean stale deployment markers from README [skip ci]"
45+
git push
46+
echo "Cleaned up stale deployment markers."
47+
fi
48+
fi
2649
2750
- name: 🔧 Set deployment variables
2851
id: vars
@@ -186,3 +209,83 @@ jobs:
186209
body,
187210
});
188211
}
212+
213+
- name: 📝 Update README with deployment URL
214+
if: github.event_name == 'push'
215+
uses: actions/github-script@v7
216+
with:
217+
script: |
218+
const owner = context.repo.owner;
219+
const repo = context.repo.repo;
220+
const branch = '${{ steps.vars.outputs.branch }}';
221+
const previewUrl = '${{ steps.vars.outputs.preview_url }}';
222+
const sha = context.sha.substring(0, 7);
223+
const date = new Date().toISOString().split('T')[0];
224+
225+
// Fetch current README from the source branch
226+
let readmeData;
227+
try {
228+
readmeData = await github.rest.repos.getContent({
229+
owner, repo, path: 'README.md', ref: branch,
230+
});
231+
} catch (e) {
232+
console.log('No README.md found, skipping update.');
233+
return;
234+
}
235+
236+
const content = Buffer.from(readmeData.data.content, 'base64').toString('utf8');
237+
238+
const marker = {
239+
start: '<!-- DEPLOYMENT-URL:START -->',
240+
end: '<!-- DEPLOYMENT-URL:END -->',
241+
};
242+
243+
const section = [
244+
marker.start,
245+
`> **🌐 Live Preview:** [${previewUrl}](${previewUrl})`,
246+
`> Deployed from \`${sha}\` on ${date}`,
247+
marker.end,
248+
].join('\n');
249+
250+
let updated;
251+
if (content.includes(marker.start)) {
252+
// Replace existing section
253+
const re = new RegExp(
254+
`${marker.start}[\\s\\S]*?${marker.end}`,
255+
);
256+
updated = content.replace(re, section);
257+
} else {
258+
// Insert after the first heading line
259+
const lines = content.split('\n');
260+
const headingIdx = lines.findIndex(l => l.startsWith('# '));
261+
if (headingIdx !== -1) {
262+
lines.splice(headingIdx + 1, 0, '', section, '');
263+
updated = lines.join('\n');
264+
} else {
265+
updated = section + '\n\n' + content;
266+
}
267+
}
268+
269+
if (updated !== content) {
270+
await github.rest.repos.createOrUpdateFileContents({
271+
owner, repo, path: 'README.md',
272+
message: `docs: update deployment URL for ${branch} [skip ci]`,
273+
content: Buffer.from(updated).toString('base64'),
274+
sha: readmeData.data.sha,
275+
branch,
276+
});
277+
console.log(`README updated with preview URL: ${previewUrl}`);
278+
}
279+
280+
- name: 🌐 Update GitHub repo homepage URL
281+
if: github.event_name == 'push' && steps.vars.outputs.is_main == 'true'
282+
uses: actions/github-script@v7
283+
with:
284+
script: |
285+
const previewUrl = '${{ steps.vars.outputs.preview_url }}';
286+
await github.rest.repos.update({
287+
owner: context.repo.owner,
288+
repo: context.repo.repo,
289+
homepage: previewUrl,
290+
});
291+
console.log(`Repository homepage updated to: ${previewUrl}`);

src/components/layout/header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ const StickyHeader: React.FC = () => {
170170
</Link>
171171
)
172172
})}
173-
<button className="flex items-center justify-center text-white bg-[rgba(0,0,0,0.2)] border border-[rgba(0,0,0,0.1)] px-4 py-[5px] text-[12px] leading-[1.4666667] rounded-[3px] my-[5px] transition-transform duration-200 ease-in-out hover:bg-[rgba(0,0,0,0.3)] hover:scale-105 focus:outline-none">
173+
<Link href="/invoice" className="flex items-center justify-center text-white bg-[rgba(0,0,0,0.2)] border border-[rgba(0,0,0,0.1)] px-4 py-[5px] text-[12px] leading-[1.4666667] rounded-[3px] my-[5px] transition-transform duration-200 ease-in-out hover:bg-[rgba(0,0,0,0.3)] hover:scale-105 focus:outline-none">
174174
<svg
175175
xmlns="http://www.w3.org/2000/svg"
176176
className="w-4 h-4 mr-2"

0 commit comments

Comments
 (0)