Skip to content

๐Ÿ“ค Preview Deploy #65

๐Ÿ“ค Preview Deploy

๐Ÿ“ค Preview Deploy #65

name: ๐Ÿ“ค Preview Deploy
on:
workflow_run:
workflows:
- ๐Ÿ“ฆ Build
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-icons/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.outputs.preview-url }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
repository: ${{ needs.setup.outputs.repo }}
ref: ${{ needs.setup.outputs.ref }}
- name: Setup Node.js
uses: ./.github/actions/setup-node
- name: ๐Ÿ“ฆ Build @univerjs/icons
run: pnpm generate && pnpm build
# ================= Deploy Demo =================
- name: ๐Ÿ“ฆ Build site
run: pnpm run build:site
- name: Copy demo to workspace
run: |
mkdir .workspace
cp -r ./doc/build/* .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.VERCEL_ORG_ID }}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID}}
notify:
runs-on: ubuntu-latest
needs: [setup, build-demo]
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": "${{ github.event.workflow_run.head_commit.message }}",
"id": "${{ github.event.workflow_run.head_commit.id }}",
"author": "${{ github.event.workflow_run.head_commit.author.name }}"
},
"preview": {
"๐Ÿ“‘ Preview": "${{ needs.build-demo.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
| ๐Ÿ“‘ Preview |
| --- |
| [๐Ÿ”— Preview link](${{ needs.build-demo.outputs.preview-url }}/) |
edit-mode: replace