diff --git a/.github/workflows/03-preview-url-pr-description.yml b/.github/workflows/03-preview-url-pr-description.yml new file mode 100644 index 000000000000..42acf55389f5 --- /dev/null +++ b/.github/workflows/03-preview-url-pr-description.yml @@ -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}); diff --git a/.github/workflows/99-add-url-comment.yml b/.github/workflows/99-add-url-comment.yml deleted file mode 100644 index fd75b72d4e68..000000000000 --- a/.github/workflows/99-add-url-comment.yml +++ /dev/null @@ -1,29 +0,0 @@ ---- -name: 💬 Add url for gh-page as issue comment to PR - -permissions: - contents: read - pull-requests: write - -on: - workflow_call: -jobs: - url: - name: 💬 Add url for gh-page as issue comment to PR - runs-on: ubuntu-24.04 # Use Ubuntu 24.04 explicitly - steps: - - name: ⏬ Checkout repo - uses: actions/checkout@v5 - - - name: 📡 Add comment - uses: actions/github-script@v8 - with: - script: | - const body = `🔭🐙🐈 Test this branch here: https://${context.repo.owner}.github.io/${context.repo.repo}/review/${context.payload.pull_request.head.ref}`; - - github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - body - }); diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml index 5296db00eb52..199c0b971825 100644 --- a/.github/workflows/default.yml +++ b/.github/workflows/default.yml @@ -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 diff --git a/.github/workflows/pull-request-opened.yml b/.github/workflows/pull-request-opened.yml deleted file mode 100644 index 618fa37f7806..000000000000 --- a/.github/workflows/pull-request-opened.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- -name: On-Pull-Request opened - -on: - pull_request: - types: [opened] - -permissions: - pull-requests: write - contents: write - -jobs: - add-url-comment: - if: github.event.pull_request.head.repo.owner.login == 'db-ux-design-system' - uses: ./.github/workflows/99-add-url-comment.yml diff --git a/__snapshots__/input/showcase/mobile-chrome/DBInput-should-match-screenshot-1/DBInput-should-match-screenshot.png b/__snapshots__/input/showcase/mobile-chrome/DBInput-should-match-screenshot-1/DBInput-should-match-screenshot.png index 0b872a2a13c5..2b03e301b2ee 100644 Binary files a/__snapshots__/input/showcase/mobile-chrome/DBInput-should-match-screenshot-1/DBInput-should-match-screenshot.png and b/__snapshots__/input/showcase/mobile-chrome/DBInput-should-match-screenshot-1/DBInput-should-match-screenshot.png differ diff --git a/scripts/github/preview-url-pr-description.js b/scripts/github/preview-url-pr-description.js new file mode 100644 index 000000000000..fea20d2651c7 --- /dev/null +++ b/scripts/github/preview-url-pr-description.js @@ -0,0 +1,43 @@ +/* eslint-disable camelcase */ +// Usage: node update-pr-description.js +// 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'; + const urlSectionEnd = '\n'; + 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;