📤 Preview Deploy #11366
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 📤 Preview Deploy | |
on: | |
workflow_run: | |
workflows: | |
- 🎬 Setup | |
types: | |
- completed | |
permissions: | |
contents: read | |
pull-requests: write | |
jobs: | |
setup: | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
runs-on: ubuntu-latest | |
outputs: | |
id: ${{ steps.pr.outputs.value }} | |
ref: ${{ steps.ref.outputs.value }} | |
repo: ${{ steps.repo.outputs.value }} | |
steps: | |
# Get PR id from artifact | |
- name: download pr artifact | |
uses: dawidd6/action-download-artifact@v2 | |
with: | |
workflow: ${{ github.event.workflow_run.workflow_id }} | |
run_id: ${{ github.event.workflow_run.id }} | |
name: pr-id | |
- name: get PR id | |
id: pr | |
run: echo "value=$(<pr-id.txt)" >> $GITHUB_OUTPUT | |
# Get PR ref from artifact | |
- name: download pr artifact | |
uses: dawidd6/action-download-artifact@v2 | |
with: | |
workflow: ${{ github.event.workflow_run.workflow_id }} | |
run_id: ${{ github.event.workflow_run.id }} | |
name: pr-ref | |
- name: get PR ref | |
id: ref | |
run: echo "value=$(<pr-ref.txt)" >> $GITHUB_OUTPUT | |
# Get PR repo from artifact | |
- name: download pr artifact | |
uses: dawidd6/action-download-artifact@v2 | |
with: | |
workflow: ${{ github.event.workflow_run.workflow_id }} | |
run_id: ${{ github.event.workflow_run.id }} | |
name: pr-repo | |
- name: get PR repo | |
id: repo | |
run: echo "value=$(<pr-repo.txt)" >> $GITHUB_OUTPUT | |
prepare: | |
runs-on: ubuntu-latest | |
needs: [setup] | |
steps: | |
# ================= Create Comment ================= | |
- name: 🧽 Find And Delete Comment | |
uses: peter-evans/find-comment@v2 | |
if: ${{ needs.setup.outputs.id != '' }} | |
id: fc | |
with: | |
issue-number: ${{ needs.setup.outputs.id }} | |
comment-author: 'github-actions[bot]' | |
body-includes: View Deployment | |
- name: 📝 Create or update comment | |
uses: peter-evans/create-or-update-comment@v3 | |
if: ${{ needs.setup.outputs.id != '' }} | |
with: | |
comment-id: ${{ steps.fc.outputs.comment-id }} | |
issue-number: ${{ needs.setup.outputs.id }} | |
body: | | |
## View Deployment | |
[#${{ github.run_id }}](https://github.com/dream-num/univer/actions/runs/${{ github.run_id }}) | |
<p align="center"> | |
🥐 🍔 🥓 🥗 🥘 🌯 🍚 🍛 🍖 🍭 🍧 🍝 🥪 🥖 🍪 <br /> | |
Still cooking, please come back later <br /> | |
🥙 🥮 🥨 🌭 🍦 🍙 🍕 🍰 🍮 🍜 🍡 🍱 🍿 🍕 🥟 | |
</p> | |
edit-mode: replace | |
build-demo: | |
runs-on: ubuntu-latest | |
needs: [setup] | |
outputs: | |
preview-url: ${{ steps.vercel-demo-dev.outputs.preview-url == '' && steps.vercel-demo.outputs.preview-url || steps.vercel-demo-dev.outputs.preview-url }} | |
commit-message: ${{ steps.commit-message.outputs.value }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
repository: ${{ needs.setup.outputs.repo }} | |
ref: ${{ needs.setup.outputs.ref }} | |
- name: Setup pnpm | |
uses: pnpm/action-setup@v4 | |
with: | |
run_install: false | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
cache: pnpm | |
- name: Install dependencies | |
run: pnpm install | |
- name: Get commit message | |
id: commit-message | |
run: echo "value=$(git log -1 --pretty=%s)" >> $GITHUB_OUTPUT | |
# ================= Deploy Demo ================= | |
- name: 📦 Build demo | |
run: pnpm build:demo | |
- name: Copy demo to workspace | |
run: | | |
mkdir .workspace | |
cp -r ./examples/local/* .workspace | |
- name: 🚀 Deploy to Vercel (demo) | |
uses: amondnet/vercel-action@v25 | |
if: ${{ needs.setup.outputs.ref == '' }} | |
id: vercel-demo | |
with: | |
vercel-token: ${{ secrets.VERCEL_TOKEN }} | |
vercel-org-id: ${{ secrets.ORG_ID }} | |
vercel-project-id: ${{ secrets.PROJECT_ID}} | |
vercel-args: --prod | |
- name: 🚀 Deploy to Vercel (demo) | |
uses: amondnet/vercel-action@v25 | |
if: ${{ needs.setup.outputs.ref != '' }} | |
id: vercel-demo-dev | |
with: | |
vercel-token: ${{ secrets.VERCEL_TOKEN }} | |
vercel-org-id: ${{ secrets.ORG_ID }} | |
vercel-project-id: ${{ secrets.PROJECT_ID}} | |
build-storybook: | |
runs-on: ubuntu-latest | |
needs: [setup] | |
outputs: | |
preview-url: ${{ steps.vercel-storybook-dev.outputs.preview-url == '' && steps.vercel-storybook.outputs.preview-url || steps.vercel-storybook-dev.outputs.preview-url }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
repository: ${{ needs.setup.outputs.repo }} | |
ref: ${{ needs.setup.outputs.ref }} | |
- name: Setup pnpm | |
uses: pnpm/action-setup@v4 | |
with: | |
run_install: false | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
cache: pnpm | |
- name: Install dependencies | |
run: pnpm install | |
# ================= Deploy Storybook ================= | |
- name: 📦 Build storybook | |
run: pnpm storybook:build | |
- name: 🚀 Deploy to Vercel (demo) | |
uses: amondnet/vercel-action@v25 | |
if: ${{ needs.setup.outputs.ref == '' }} | |
id: vercel-storybook | |
with: | |
vercel-token: ${{ secrets.VERCEL_TOKEN }} | |
vercel-org-id: ${{ secrets.ORG_ID }} | |
vercel-project-id: ${{ secrets.PROJECT_ID_STORYBOOK}} | |
vercel-args: --prod | |
- name: 🚀 Deploy to Vercel (storybook) | |
uses: amondnet/vercel-action@v25 | |
if: ${{ needs.setup.outputs.ref != '' }} | |
id: vercel-storybook-dev | |
with: | |
vercel-token: ${{ secrets.VERCEL_TOKEN }} | |
vercel-org-id: ${{ secrets.ORG_ID }} | |
vercel-project-id: ${{ secrets.PROJECT_ID_STORYBOOK}} | |
notify: | |
runs-on: ubuntu-latest | |
needs: [setup, build-demo, build-storybook] | |
steps: | |
- name: Invoke deployment hook | |
uses: distributhor/workflow-webhook@v3 | |
with: | |
webhook_url: ${{ secrets.WEBHOOK_URL }} | |
data: > | |
{ | |
"type": "build", | |
"workflow": { | |
"id": "${{ github.run_id }}" | |
}, | |
"commit": { | |
"ref": "${{ needs.setup.outputs.ref }}", | |
"message": "${{ needs.build-demo.outputs.commit-message }}", | |
"id": "${{ github.event.workflow_run.head_commit.id }}", | |
"author": "${{ github.event.workflow_run.head_commit.author.name }}" | |
}, | |
"preview": { | |
"📑 Examples": "${{ needs.build-demo.outputs.preview-url }}/", | |
"📚 Storybook": "${{ needs.build-storybook.outputs.preview-url }}/" | |
} | |
} | |
# ================= Create Comment ================= | |
- name: 🧽 Find And Delete Comment | |
uses: peter-evans/find-comment@v2 | |
if: ${{ needs.setup.outputs.id != '' }} | |
id: fc | |
with: | |
issue-number: ${{ needs.setup.outputs.id }} | |
comment-author: 'github-actions[bot]' | |
body-includes: View Deployment | |
- name: 📝 Create or update comment | |
uses: peter-evans/create-or-update-comment@v3 | |
if: ${{ needs.setup.outputs.id != '' }} | |
with: | |
comment-id: ${{ steps.fc.outputs.comment-id }} | |
issue-number: ${{ needs.setup.outputs.id }} | |
body: | | |
## View Deployment | |
| 📑 Examples | 📚 Storybook | | |
| --- | --- | | |
| [🔗 Preview link](${{ needs.build-demo.outputs.preview-url }}/) | [🔗 Preview link](${{ needs.build-storybook.outputs.preview-url }}/) | | |
edit-mode: replace |