Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/03-preview-url-pr-description.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Preview URL PR Description

permissions:
pull-requests: write

on:
workflow_call:

jobs:
preview-url-pr-description:
runs-on: ubuntu-24.04 # Use Ubuntu 24.04 explicitly
steps:
- name: ⏬ Checkout repo
uses: actions/checkout@v5

- name: 🔭 Add url for preview page
uses: actions/github-script@v8
with:
script: |
const { default: previewUrlPrDescription } = await import('${{ github.workspace }}/scripts/github/preview-url-pr-description.js');
return await previewUrlPrDescription({github, context});
29 changes: 0 additions & 29 deletions .github/workflows/99-add-url-comment.yml

This file was deleted.

5 changes: 5 additions & 0 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,8 @@ jobs:
with:
release: false
preRelease: false

preview-url-pr-description:
if: ${{ !cancelled() && github.event.pull_request != null }}
needs: [deploy]
uses: ./.github/workflows/03-preview-url-pr-description.yml
15 changes: 0 additions & 15 deletions .github/workflows/pull-request-opened.yml

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions scripts/github/preview-url-pr-description.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* eslint-disable camelcase */
// Usage: node update-pr-description.js <owner> <repo> <pull_number> <head_ref>
// Requires: GITHUB_TOKEN in env

/**
* Update PR description with a test URL section.
* @param {import('@actions/github').GitHub} github - Octokit client from actions/github-script
* @param {object} context - GitHub Actions context
*/
async function previewUrlPrDescription({ github, context }) {
const { owner, repo } = context.repo;
const pullNumber = context.payload.pull_request.number;
const headRef = context.payload.pull_request.head.ref;

// Fetch current PR
const pr = await github.rest.pulls.get({
owner,
repo,
pull_number: pullNumber
});
const urlSectionStart = '\n<!-- DBUX-TEST-URL-START -->';
const urlSectionEnd = '\n<!-- DBUX-TEST-URL-END -->';
const testUrl = `🔭🐙🐈 Test this branch here: https://${owner}.github.io/${repo}/review/${headRef}`;
let body = pr.data.body || '';
// Remove any existing test URL section
const startIdx = body.indexOf(urlSectionStart);
const endIdx = body.indexOf(urlSectionEnd);
if (startIdx !== -1 && endIdx !== -1 && endIdx > startIdx) {
body =
body.slice(0, startIdx) + body.slice(endIdx + urlSectionEnd.length);
}

// Add the new test URL section at the end
body = body.trim() + `${urlSectionStart}\n${testUrl}${urlSectionEnd}`;
await github.rest.pulls.update({
owner,
repo,
pull_number: pullNumber,
body
});
}

export default previewUrlPrDescription;