PREVIEW_PUBLISH #6754
This file contains hidden or 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_PUBLISH | |
on: | |
workflow_run: | |
workflows: | |
- PREVIEW_BUILD | |
types: | |
- completed | |
jobs: | |
preview-context: | |
if: github.event.workflow_run.conclusion == 'success' | |
runs-on: ubuntu-latest | |
outputs: | |
pr_id: ${{ steps.pr.outputs.id }} | |
tdesign_vue_next_domain: ${{ steps.tdesign-vue-next-domain.outputs.tdesign_vue_next_domain }} | |
tdesign_vue_next_chat_domain: ${{ steps.tdesign-vue-next-chat-domain.outputs.tdesign_vue_next_chat_domain }} | |
steps: | |
- name: Download pr id | |
uses: dawidd6/action-download-artifact@v8 | |
with: | |
workflow: ${{ github.event.workflow_run.workflow_id }} | |
run_id: ${{ github.event.workflow_run.id }} | |
name: pr-id | |
- name: Set pr id | |
id : pr | |
run: echo "id=$(cat pr-id.txt)" >> $GITHUB_OUTPUT | |
- name: tdesign-vue-next-domain | |
id: tdesign-vue-next-domain | |
run: echo "tdesign_vue_next_domain=https://preview-pr-${{ steps.pr.outputs.id }}-tdesign-vue-next.surge.sh" >> $GITHUB_OUTPUT | |
- name: tdesign-vue-next-chat-domain | |
id: tdesign-vue-next-chat-domain | |
run: echo "tdesign_vue_next_chat_domain=https://preview-pr-${{ steps.pr.outputs.id }}-tdesign-vue-next-chat.surge.sh" >> $GITHUB_OUTPUT | |
tdesign-vue-next: | |
if: github.event.workflow_run.conclusion == 'success' | |
runs-on: ubuntu-latest | |
needs: preview-context | |
steps: | |
- uses: dawidd6/action-download-artifact@v8 | |
with: | |
workflow: ${{ github.event.workflow_run.workflow_id }} | |
run_id: ${{ github.event.workflow_run.id }} | |
name: tdesign-vue-next-site | |
- run: | | |
export DEPLOY_DOMAIN=${{ needs.preview-context.outputs.tdesign_vue_next_domain }} | |
npx surge --project ./ --domain $DEPLOY_DOMAIN --token ${{ secrets.TDESIGN_SURGE_TOKEN }} | |
tdesign-vue-next-chat: | |
if: github.event.workflow_run.conclusion == 'success' | |
runs-on: ubuntu-latest | |
needs: preview-context | |
steps: | |
- uses: dawidd6/action-download-artifact@v8 | |
with: | |
workflow: ${{ github.event.workflow_run.workflow_id }} | |
run_id: ${{ github.event.workflow_run.id }} | |
name: tdesign-vue-next-chat-site | |
- run: | | |
export DEPLOY_DOMAIN=${{ needs.preview-context.outputs.tdesign_vue_next_chat_domain }} | |
npx surge --project ./ --domain $DEPLOY_DOMAIN --token ${{ secrets.TDESIGN_SURGE_TOKEN }} | |
preview-comment: | |
if: always() | |
needs: | |
- preview-context | |
- tdesign-vue-next | |
- tdesign-vue-next-chat | |
runs-on: ubuntu-latest | |
steps: | |
- name: jobs report | |
id: report | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const pr_id = ${{ needs.preview-context.outputs.pr_id }}; | |
const tdesign_vue_next_domain = "${{ needs.preview-context.outputs.tdesign_vue_next_domain }}"; | |
const tdesign_vue_next_chat_domain = "${{ needs.preview-context.outputs.tdesign_vue_next_chat_domain }}"; | |
const { data: { jobs } } = await github.rest.actions.listJobsForWorkflowRun({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: context.runId, | |
per_page: 100 | |
}) | |
const tdesign = { | |
"tdesign-vue-next": { status: "", report_url: "" }, | |
"tdesign-vue-next-chat": { status: "", report_url: "" }, | |
}; | |
const preview_success = `<img width="300" alt="完成" src="https://user-images.githubusercontent.com/15634204/150816437-9f5bb788-cd67-4cbc-9897-b82d74e9aa65.png" />`; | |
const preview_failure = `<img width="300" alt="失败" src="https://user-images.githubusercontent.com/5378891/75333447-1e63a280-58c1-11ea-975d-235367fd1522.png" />`; | |
jobs | |
.filter((job) => job.name.startsWith("tdesign-")) | |
.map((job) => { | |
tdesign[job.name].status = preview_failure; | |
tdesign[job.name].report_url = job.html_url; | |
if (job.conclusion === "success") { | |
tdesign[job.name].status = preview_success; | |
if (job.name === "tdesign-vue-next") { | |
tdesign[job.name].report_url = tdesign_vue_next_domain; | |
} | |
if (job.name === "tdesign-vue-next-chat") { | |
tdesign[job.name].report_url = tdesign_vue_next_chat_domain; | |
} | |
} | |
}); | |
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; | |
const comment = ` | |
# TDesign Component Site Preview [Open](${runUrl}) | |
| Component | Preview | | |
| --------- | :--: | | |
${Object.keys(tdesign) | |
.map((component) => { | |
const preview_text = `[${tdesign[component].status}](${tdesign[component].report_url})`; | |
let package_name = component; | |
if (component === "tdesign-vue-next-chat") { | |
package_name = "@tdesign-vue-next/chat"; | |
} | |
return `| ${package_name} | ${preview_text} | `; | |
}) | |
.join("\n")} | |
<!-- AUTO_PREVIEW_HOOK --> | |
`; | |
core.setOutput('comment', comment); | |
- name: comment | |
uses: actions-cool/maintain-one-comment@v3 | |
with: | |
token: ${{ secrets.TDESIGN_BOT_TOKEN }} | |
number: ${{needs.preview-context.outputs.pr_id}} | |
body: ${{ steps.report.outputs.comment }} | |
body-include: '<!-- AUTO_PREVIEW_HOOK -->' |