From bc6394727a59be3a08ca790d0fa00508e154a499 Mon Sep 17 00:00:00 2001 From: Marco Roth Date: Sun, 16 Nov 2025 15:41:21 -0800 Subject: [PATCH 1/3] Playground: Deploy Previews for Pull Requests --- .github/workflows/deploy-preview.yml | 193 +++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 .github/workflows/deploy-preview.yml diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml new file mode 100644 index 000000000..c80d64171 --- /dev/null +++ b/.github/workflows/deploy-preview.yml @@ -0,0 +1,193 @@ +name: Deploy Preview to Cloudflare Pages + +on: + pull_request: + types: [opened, synchronize, closed] + +concurrency: + group: preview-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + build: + if: github.event.action != 'closed' + env: + GH_TOKEN: ${{ github.token }} + + runs-on: ubicloud-standard-2 + timeout-minutes: 10 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: "yarn" + + - name: Add LLVM apt Repo + run: |- + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - + sudo add-apt-repository "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-21 main" + sudo apt update + + - name: Install APT dependencies + run: xargs sudo apt-get install -y --no-install-recommends < Aptfile + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + + - name: bundle install + run: bundle install + + - name: Render Templates + run: bundle exec rake templates + + - name: Compile Herb + run: bundle exec rake make + + - name: Yarn install + run: yarn install --frozen-lockfile + + - name: Build tailwind-class-sorter package + run: yarn nx build @herb-tools/tailwind-class-sorter + + - name: Build all JavaScript packages + run: yarn build + + - name: Build docs site + run: cd docs && yarn build + + - name: Upload docs artifact + uses: actions/upload-artifact@v4 + with: + name: docs-preview + path: docs/.vitepress/dist + retention-days: 1 + + deploy-preview: + name: Deploy to Cloudflare Pages + needs: build + runs-on: ubuntu-latest + + permissions: + contents: read + deployments: write + pull-requests: write + + steps: + - name: Download docs artifact + uses: actions/download-artifact@v4 + with: + name: docs-preview + path: dist + + - name: Deploy to Cloudflare Pages + id: deploy + uses: cloudflare/pages-action@v1 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + projectName: herb-tools + directory: dist + gitHubToken: ${{ secrets.GITHUB_TOKEN }} + + - name: Add comment with preview URL + uses: actions/github-script@v7 + with: + script: | + const previewUrl = '${{ steps.deploy.outputs.url }}'; + const comment = `## 🌿 Interactive Playground and Documentation Preview + + A preview deployment has been built for this pull request. Try out the changes live in the interactive playground: + + - **[Playground Preview](${previewUrl}/playground)** + - **[Documentation Preview](${previewUrl})** + - **[Website Preview](${previewUrl})** + + --- + 🌱 Grown from commit [\`${context.payload.pull_request.head.sha.substring(0, 7)}\`](https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${context.payload.pull_request.head.sha})`; + + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + }); + + const botComment = comments.find(comment => + comment.user.type === 'Bot' && + comment.body.includes('🌿 Interactive Playground and Documentation Preview') + ); + + if (botComment) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: botComment.id, + body: comment + }); + } else { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: comment + }); + } + + cleanup: + name: Cleanup preview deployment + if: github.event.action == 'closed' + runs-on: ubuntu-latest + + permissions: + pull-requests: write + + steps: + - name: Delete Cloudflare Pages deployment + run: | + DEPLOYMENTS=$(curl -s -X GET \ + "https://api.cloudflare.com/client/v4/accounts/${{ secrets.CLOUDFLARE_ACCOUNT_ID }}/pages/projects/herb-tools/deployments" \ + -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}" \ + -H "Content-Type: application/json") + + BRANCH_NAME="${{ github.event.pull_request.head.ref }}" + DEPLOYMENT_ID=$(echo "$DEPLOYMENTS" | jq -r ".result[] | select(.deployment_trigger.metadata.branch == \"$BRANCH_NAME\") | .id" | head -n 1) + + if [ -n "$DEPLOYMENT_ID" ]; then + echo "Deleting deployment $DEPLOYMENT_ID for branch $BRANCH_NAME" + curl -X DELETE \ + "https://api.cloudflare.com/client/v4/accounts/${{ secrets.CLOUDFLARE_ACCOUNT_ID }}/pages/projects/herb-tools/deployments/$DEPLOYMENT_ID" \ + -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}" \ + -H "Content-Type: application/json" + else + echo "No deployment found for branch $BRANCH_NAME" + fi + + - name: Update PR comment + uses: actions/github-script@v7 + with: + script: | + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + }); + + const botComment = comments.find(comment => + comment.user.type === 'Bot' && + comment.body.includes('🌿 Interactive Playground and Documentation Preview') + ); + + if (botComment) { + const updatedComment = botComment.body + '\n\n---\n\nāœ… Preview deployment has been cleaned up.'; + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: botComment.id, + body: updatedComment + }); + } From d72d261c56e0a94e2f6f16bac1403f637ef9b2fd Mon Sep 17 00:00:00 2001 From: Marco Roth Date: Sun, 16 Nov 2025 16:03:04 -0800 Subject: [PATCH 2/3] Merge deploy-preview into javascript and update playground version info --- .github/workflows/deploy-preview.yml | 193 ------------------ .github/workflows/javascript.yml | 138 ++++++++++++- .../src/controllers/playground_controller.js | 24 ++- playground/vite.config.ts | 57 +++--- 4 files changed, 186 insertions(+), 226 deletions(-) delete mode 100644 .github/workflows/deploy-preview.yml diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml deleted file mode 100644 index c80d64171..000000000 --- a/.github/workflows/deploy-preview.yml +++ /dev/null @@ -1,193 +0,0 @@ -name: Deploy Preview to Cloudflare Pages - -on: - pull_request: - types: [opened, synchronize, closed] - -concurrency: - group: preview-${{ github.event.pull_request.number }} - cancel-in-progress: true - -jobs: - build: - if: github.event.action != 'closed' - env: - GH_TOKEN: ${{ github.token }} - - runs-on: ubicloud-standard-2 - timeout-minutes: 10 - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - uses: actions/setup-node@v4 - with: - node-version: 20 - cache: "yarn" - - - name: Add LLVM apt Repo - run: |- - wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - - sudo add-apt-repository "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-21 main" - sudo apt update - - - name: Install APT dependencies - run: xargs sudo apt-get install -y --no-install-recommends < Aptfile - - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - bundler-cache: true - - - name: bundle install - run: bundle install - - - name: Render Templates - run: bundle exec rake templates - - - name: Compile Herb - run: bundle exec rake make - - - name: Yarn install - run: yarn install --frozen-lockfile - - - name: Build tailwind-class-sorter package - run: yarn nx build @herb-tools/tailwind-class-sorter - - - name: Build all JavaScript packages - run: yarn build - - - name: Build docs site - run: cd docs && yarn build - - - name: Upload docs artifact - uses: actions/upload-artifact@v4 - with: - name: docs-preview - path: docs/.vitepress/dist - retention-days: 1 - - deploy-preview: - name: Deploy to Cloudflare Pages - needs: build - runs-on: ubuntu-latest - - permissions: - contents: read - deployments: write - pull-requests: write - - steps: - - name: Download docs artifact - uses: actions/download-artifact@v4 - with: - name: docs-preview - path: dist - - - name: Deploy to Cloudflare Pages - id: deploy - uses: cloudflare/pages-action@v1 - with: - apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} - accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - projectName: herb-tools - directory: dist - gitHubToken: ${{ secrets.GITHUB_TOKEN }} - - - name: Add comment with preview URL - uses: actions/github-script@v7 - with: - script: | - const previewUrl = '${{ steps.deploy.outputs.url }}'; - const comment = `## 🌿 Interactive Playground and Documentation Preview - - A preview deployment has been built for this pull request. Try out the changes live in the interactive playground: - - - **[Playground Preview](${previewUrl}/playground)** - - **[Documentation Preview](${previewUrl})** - - **[Website Preview](${previewUrl})** - - --- - 🌱 Grown from commit [\`${context.payload.pull_request.head.sha.substring(0, 7)}\`](https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${context.payload.pull_request.head.sha})`; - - const { data: comments } = await github.rest.issues.listComments({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - }); - - const botComment = comments.find(comment => - comment.user.type === 'Bot' && - comment.body.includes('🌿 Interactive Playground and Documentation Preview') - ); - - if (botComment) { - await github.rest.issues.updateComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: botComment.id, - body: comment - }); - } else { - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - body: comment - }); - } - - cleanup: - name: Cleanup preview deployment - if: github.event.action == 'closed' - runs-on: ubuntu-latest - - permissions: - pull-requests: write - - steps: - - name: Delete Cloudflare Pages deployment - run: | - DEPLOYMENTS=$(curl -s -X GET \ - "https://api.cloudflare.com/client/v4/accounts/${{ secrets.CLOUDFLARE_ACCOUNT_ID }}/pages/projects/herb-tools/deployments" \ - -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}" \ - -H "Content-Type: application/json") - - BRANCH_NAME="${{ github.event.pull_request.head.ref }}" - DEPLOYMENT_ID=$(echo "$DEPLOYMENTS" | jq -r ".result[] | select(.deployment_trigger.metadata.branch == \"$BRANCH_NAME\") | .id" | head -n 1) - - if [ -n "$DEPLOYMENT_ID" ]; then - echo "Deleting deployment $DEPLOYMENT_ID for branch $BRANCH_NAME" - curl -X DELETE \ - "https://api.cloudflare.com/client/v4/accounts/${{ secrets.CLOUDFLARE_ACCOUNT_ID }}/pages/projects/herb-tools/deployments/$DEPLOYMENT_ID" \ - -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}" \ - -H "Content-Type: application/json" - else - echo "No deployment found for branch $BRANCH_NAME" - fi - - - name: Update PR comment - uses: actions/github-script@v7 - with: - script: | - const { data: comments } = await github.rest.issues.listComments({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - }); - - const botComment = comments.find(comment => - comment.user.type === 'Bot' && - comment.body.includes('🌿 Interactive Playground and Documentation Preview') - ); - - if (botComment) { - const updatedComment = botComment.body + '\n\n---\n\nāœ… Preview deployment has been cleaned up.'; - await github.rest.issues.updateComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: botComment.id, - body: updatedComment - }); - } diff --git a/.github/workflows/javascript.yml b/.github/workflows/javascript.yml index 0017053e3..8ae375857 100644 --- a/.github/workflows/javascript.yml +++ b/.github/workflows/javascript.yml @@ -5,7 +5,7 @@ on: branches: - main pull_request: - types: [opened, synchronize, labeled] + types: [opened, synchronize, labeled, closed] pull_request_review: types: [submitted] release: @@ -17,6 +17,7 @@ permissions: jobs: main: + if: github.event.action != 'closed' env: GH_TOKEN: ${{ github.token }} @@ -71,6 +72,7 @@ jobs: - name: Run `build` for all NX packages env: RELEASE_BUILD: ${{ github.event_name == 'release' && 'true' || 'false' }} + GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }} run: yarn build - name: Run `test` for all NX packages @@ -84,6 +86,15 @@ jobs: if-no-files-found: error retention-days: 1 + - name: Upload docs artifact + if: github.event_name == 'pull_request' + uses: actions/upload-artifact@v4 + with: + name: docs-preview + path: docs/.vitepress/dist + if-no-files-found: error + retention-days: 1 + # NX is not able to properly detect affected changes if things change in C source or the WASM build # # - name: Set NX SHAs @@ -213,3 +224,128 @@ jobs: run: | cd javascript/packages/vscode npx ovsx publish -p $OVSX_PAT + + deploy-preview: + name: Deploy docs preview to Cloudflare Pages + if: github.event_name == 'pull_request' && github.event.action != 'closed' + needs: main + runs-on: ubuntu-latest + + permissions: + contents: read + deployments: write + pull-requests: write + + steps: + - name: Download docs artifact + uses: actions/download-artifact@v4 + with: + name: docs-preview + path: dist + + - name: Deploy to Cloudflare Pages + id: deploy + uses: cloudflare/pages-action@v1 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + projectName: herb-tools + directory: dist + gitHubToken: ${{ secrets.GITHUB_TOKEN }} + + - name: Add comment with preview URL + uses: actions/github-script@v7 + with: + script: | + const previewUrl = '${{ steps.deploy.outputs.url }}'; + const comment = `### 🌿 Interactive Playground and Documentation Preview + + A preview deployment has been built for this pull request. Try out the changes live in the interactive playground: + + - **[Playground Preview](${previewUrl}/playground)** + - **[Documentation Preview](${previewUrl})** + - **[Website Preview](${previewUrl})** + + --- + 🌱 Grown from commit [\`${context.payload.pull_request.head.sha.substring(0, 7)}\`](https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${context.payload.pull_request.head.sha})`; + + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + }); + + const botComment = comments.find(comment => + comment.user.type === 'Bot' && + comment.body.includes('🌿 Interactive Playground and Documentation Preview') + ); + + if (botComment) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: botComment.id, + body: comment + }); + } else { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: comment + }); + } + + cleanup-preview: + name: Cleanup docs preview deployment + if: github.event_name == 'pull_request' && github.event.action == 'closed' + runs-on: ubuntu-latest + + permissions: + pull-requests: write + + steps: + - name: Delete Cloudflare Pages deployment + run: | + DEPLOYMENTS=$(curl -s -X GET \ + "https://api.cloudflare.com/client/v4/accounts/${{ secrets.CLOUDFLARE_ACCOUNT_ID }}/pages/projects/herb-tools/deployments" \ + -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}" \ + -H "Content-Type: application/json") + + BRANCH_NAME="${{ github.event.pull_request.head.ref }}" + DEPLOYMENT_ID=$(echo "$DEPLOYMENTS" | jq -r ".result[] | select(.deployment_trigger.metadata.branch == \"$BRANCH_NAME\") | .id" | head -n 1) + + if [ -n "$DEPLOYMENT_ID" ]; then + echo "Deleting deployment $DEPLOYMENT_ID for branch $BRANCH_NAME" + curl -X DELETE \ + "https://api.cloudflare.com/client/v4/accounts/${{ secrets.CLOUDFLARE_ACCOUNT_ID }}/pages/projects/herb-tools/deployments/$DEPLOYMENT_ID" \ + -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}" \ + -H "Content-Type: application/json" + else + echo "No deployment found for branch $BRANCH_NAME" + fi + + - name: Update PR comment + uses: actions/github-script@v7 + with: + script: | + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + }); + + const botComment = comments.find(comment => + comment.user.type === 'Bot' && + comment.body.includes('🌿 Interactive Playground and Documentation Preview') + ); + + if (botComment) { + const updatedComment = botComment.body + '\n\n---\n\nāœ… Preview deployment has been cleaned up.'; + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: botComment.id, + body: updatedComment + }); + } diff --git a/playground/src/controllers/playground_controller.js b/playground/src/controllers/playground_controller.js index a768c621f..d156f9efb 100644 --- a/playground/src/controllers/playground_controller.js +++ b/playground/src/controllers/playground_controller.js @@ -778,16 +778,26 @@ export default class extends Controller { if (this.hasCommitHashTarget) { if (typeof __COMMIT_INFO__ !== 'undefined') { const commitInfo = __COMMIT_INFO__ - const githubUrl = `https://github.com/marcoroth/herb/commit/${commitInfo.hash}` - if (commitInfo.ahead > 0) { - this.commitHashTarget.textContent = `${commitInfo.tag} (+${commitInfo.ahead} commits) ${commitInfo.hash}` + if (commitInfo.prNumber) { + const prUrl = `https://github.com/marcoroth/herb/pull/${commitInfo.prNumber}` + const commitUrl = `https://github.com/marcoroth/herb/commit/${commitInfo.hash}` + + this.commitHashTarget.textContent = `PR #${commitInfo.prNumber} @ ${commitInfo.hash}` + this.commitHashTarget.href = prUrl + this.commitHashTarget.title = `View PR #${commitInfo.prNumber} on GitHub (commit ${commitInfo.hash})` } else { - this.commitHashTarget.textContent = `${commitInfo.tag} ${commitInfo.hash}` - } + const githubUrl = `https://github.com/marcoroth/herb/commit/${commitInfo.hash}` + + if (commitInfo.ahead > 0) { + this.commitHashTarget.textContent = `${commitInfo.tag} (+${commitInfo.ahead} commits) ${commitInfo.hash}` + } else { + this.commitHashTarget.textContent = `${commitInfo.tag} ${commitInfo.hash}` + } - this.commitHashTarget.href = githubUrl - this.commitHashTarget.title = `View commit ${commitInfo.hash} on GitHub` + this.commitHashTarget.href = githubUrl + this.commitHashTarget.title = `View commit ${commitInfo.hash} on GitHub` + } } else { this.commitHashTarget.textContent = 'unknown' this.commitHashTarget.removeAttribute('href') diff --git a/playground/vite.config.ts b/playground/vite.config.ts index e88cd1be6..a783aa1b7 100644 --- a/playground/vite.config.ts +++ b/playground/vite.config.ts @@ -5,16 +5,34 @@ function getCommitInfo() { let hash = "unknown" let tag = "unknown" let ahead = 0 + let prNumber = null - try { - try { - hash = execSync("git rev-parse --short HEAD", { encoding: "utf8" }).trim() - } catch (hashError) { - if (process.env.GITHUB_SHA) { - hash = process.env.GITHUB_SHA.substring(0, 7) - } + const isGitHubActions = process.env.GITHUB_ACTIONS === 'true' + + if (isGitHubActions) { + hash = process.env.GITHUB_SHA?.substring(0, 8) || "unknown" + + if (process.env.GITHUB_EVENT_NAME === 'pull_request' && process.env.GITHUB_PR_NUMBER) { + prNumber = process.env.GITHUB_PR_NUMBER + tag = `PR #${prNumber}` + ahead = 0 + console.log(`GitHub Actions PR build: hash=${hash}, PR=${prNumber}`) + } else if (process.env.GITHUB_REF?.startsWith('refs/tags/')) { + tag = process.env.GITHUB_REF.replace('refs/tags/', '') + ahead = 0 + console.log(`GitHub Actions tag build: hash=${hash}, tag=${tag}`) + } else { + tag = process.env.GITHUB_REF_NAME || "unknown" + ahead = 0 + console.log(`GitHub Actions branch build: hash=${hash}, ref=${tag}`) } + return { hash, tag, ahead, prNumber } + } + + try { + hash = execSync("git rev-parse --short=8 HEAD", { encoding: "utf8" }).trim() + try { execSync("git fetch --tags --force", { stdio: 'ignore' }) tag = execSync("git describe --tags --abbrev=0", { encoding: "utf8" }).trim() @@ -27,27 +45,17 @@ function getCommitInfo() { } } catch (tagError) { console.warn("Could not get git tag info:", tagError.message) - - if (process.env.GITHUB_REF) { - if (process.env.GITHUB_REF.startsWith('refs/tags/')) { - tag = process.env.GITHUB_REF.replace('refs/tags/', '') - ahead = 0 - } else if (process.env.GITHUB_REF_NAME) { - tag = process.env.GITHUB_REF_NAME - } - } + tag = "dev" } - console.log(`Git info: hash=${hash}, tag=${tag}, ahead=${ahead}`) - return { hash, tag, ahead } + console.log(`Local build: hash=${hash}, tag=${tag}, ahead=${ahead}`) } catch (error) { console.warn("Could not get git commit info:", error.message) - return { - hash: process.env.GITHUB_SHA?.substring(0, 7) || "unknown", - tag: process.env.GITHUB_REF_NAME || "unknown", - ahead: 0 - } + hash = "unknown" + tag = "unknown" } + + return { hash, tag, ahead, prNumber } } export default defineConfig({ @@ -55,8 +63,7 @@ export default defineConfig({ __COMMIT_INFO__: JSON.stringify(getCommitInfo()), }, server: { - port: process.env.PORT ? parseInt(process.env.PORT) : 5173, - allowedHosts: ["playground.herb-tools.dev"], + port: process.env.PORT ? parseInt(process.env.PORT) : 5173 }, plugins: [], }) From 59783ee355fbce89374755cd011dd6b075eb41a6 Mon Sep 17 00:00:00 2001 From: Marco Roth Date: Sun, 16 Nov 2025 16:14:41 -0800 Subject: [PATCH 3/3] Cleanup --- .github/workflows/javascript.yml | 22 +++++++++++----------- playground/vite.config.ts | 11 +++++++---- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/.github/workflows/javascript.yml b/.github/workflows/javascript.yml index 8ae375857..7e36fabc0 100644 --- a/.github/workflows/javascript.yml +++ b/.github/workflows/javascript.yml @@ -6,8 +6,6 @@ on: - main pull_request: types: [opened, synchronize, labeled, closed] - pull_request_review: - types: [submitted] release: types: [published] @@ -73,6 +71,7 @@ jobs: env: RELEASE_BUILD: ${{ github.event_name == 'release' && 'true' || 'false' }} GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }} + GITHUB_PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} run: yarn build - name: Run `test` for all NX packages @@ -147,8 +146,6 @@ jobs: if: | (github.repository == 'marcoroth/herb' && github.event_name == 'pull_request' && github.event.pull_request.user.login == github.repository_owner) || (github.repository == 'marcoroth/herb' && github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'release-preview')) || - (github.repository == 'marcoroth/herb' && github.event_name == 'pull_request_review' && github.event.review.state == 'approved') || - (github.repository == 'marcoroth/herb' && github.event_name == 'pull_request_review' && contains(github.event.pull_request.labels.*.name, 'release-preview')) || (github.repository == 'marcoroth/herb' && github.event_name == 'push' && github.ref == 'refs/heads/main') runs-on: ubuntu-latest @@ -227,8 +224,8 @@ jobs: deploy-preview: name: Deploy docs preview to Cloudflare Pages - if: github.event_name == 'pull_request' && github.event.action != 'closed' - needs: main + needs: [main, preview-check] + if: needs.preview-check.outputs.has-permissions == 'true' runs-on: ubuntu-latest permissions: @@ -306,20 +303,23 @@ jobs: steps: - name: Delete Cloudflare Pages deployment + env: + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + BRANCH_NAME: ${{ github.event.pull_request.head.ref }} run: | DEPLOYMENTS=$(curl -s -X GET \ - "https://api.cloudflare.com/client/v4/accounts/${{ secrets.CLOUDFLARE_ACCOUNT_ID }}/pages/projects/herb-tools/deployments" \ - -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}" \ + "https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/pages/projects/herb-tools/deployments" \ + -H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \ -H "Content-Type: application/json") - BRANCH_NAME="${{ github.event.pull_request.head.ref }}" DEPLOYMENT_ID=$(echo "$DEPLOYMENTS" | jq -r ".result[] | select(.deployment_trigger.metadata.branch == \"$BRANCH_NAME\") | .id" | head -n 1) if [ -n "$DEPLOYMENT_ID" ]; then echo "Deleting deployment $DEPLOYMENT_ID for branch $BRANCH_NAME" curl -X DELETE \ - "https://api.cloudflare.com/client/v4/accounts/${{ secrets.CLOUDFLARE_ACCOUNT_ID }}/pages/projects/herb-tools/deployments/$DEPLOYMENT_ID" \ - -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}" \ + "https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/pages/projects/herb-tools/deployments/$DEPLOYMENT_ID" \ + -H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \ -H "Content-Type: application/json" else echo "No deployment found for branch $BRANCH_NAME" diff --git a/playground/vite.config.ts b/playground/vite.config.ts index a783aa1b7..f6032f88b 100644 --- a/playground/vite.config.ts +++ b/playground/vite.config.ts @@ -10,14 +10,17 @@ function getCommitInfo() { const isGitHubActions = process.env.GITHUB_ACTIONS === 'true' if (isGitHubActions) { - hash = process.env.GITHUB_SHA?.substring(0, 8) || "unknown" - - if (process.env.GITHUB_EVENT_NAME === 'pull_request' && process.env.GITHUB_PR_NUMBER) { + if (process.env.GITHUB_EVENT_NAME === 'pull_request' && process.env.GITHUB_PR_HEAD_SHA) { + hash = process.env.GITHUB_PR_HEAD_SHA.substring(0, 8) prNumber = process.env.GITHUB_PR_NUMBER tag = `PR #${prNumber}` ahead = 0 console.log(`GitHub Actions PR build: hash=${hash}, PR=${prNumber}`) - } else if (process.env.GITHUB_REF?.startsWith('refs/tags/')) { + } else { + hash = process.env.GITHUB_SHA?.substring(0, 8) || "unknown" + } + + if (process.env.GITHUB_REF?.startsWith('refs/tags/')) { tag = process.env.GITHUB_REF.replace('refs/tags/', '') ahead = 0 console.log(`GitHub Actions tag build: hash=${hash}, tag=${tag}`)