|
| 1 | +name: preview-site-publish |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: |
| 6 | + - preview-site-build |
| 7 | + types: |
| 8 | + - completed |
| 9 | + |
| 10 | +jobs: |
| 11 | + preview-context: |
| 12 | + if: github.event.workflow_run.conclusion == 'success' |
| 13 | + runs-on: ubuntu-latest |
| 14 | + outputs: |
| 15 | + pr_id: ${{ steps.pr.outputs.id }} |
| 16 | + tdesign_miniprogram_domain: ${{ steps.tdesign-miniprogram-domain.outputs.tdesign_miniprogram_domain }} |
| 17 | + tdesign_miniprogram_chat_domain: ${{ steps.tdesign-miniprogram-chat-domain.outputs.tdesign_miniprogram_chat_domain }} |
| 18 | + steps: |
| 19 | + - name: Download pr id |
| 20 | + uses: dawidd6/action-download-artifact@v8 |
| 21 | + with: |
| 22 | + workflow: ${{ github.event.workflow_run.workflow_id }} |
| 23 | + run_id: ${{ github.event.workflow_run.id }} |
| 24 | + name: pr-id |
| 25 | + |
| 26 | + - name: Set pr id |
| 27 | + id: pr |
| 28 | + run: echo "id=$(cat pr-id.txt)" >> $GITHUB_OUTPUT |
| 29 | + |
| 30 | + - name: tdesign-miniprogram-domain |
| 31 | + id: tdesign-miniprogram-domain |
| 32 | + run: echo "tdesign_miniprogram_domain=https://preview-pr-${{ steps.pr.outputs.id }}-tdesign-miniprogram.surge.sh" >> $GITHUB_OUTPUT |
| 33 | + |
| 34 | + - name: tdesign-miniprogram-chat-domain |
| 35 | + id: tdesign-miniprogram-chat-domain |
| 36 | + run: echo "tdesign_miniprogram_chat_domain=https://preview-pr-${{ steps.pr.outputs.id }}-tdesign-miniprogram-chat.surge.sh" >> $GITHUB_OUTPUT |
| 37 | + |
| 38 | + tdesign-miniprogram: |
| 39 | + if: github.event.workflow_run.conclusion == 'success' |
| 40 | + runs-on: ubuntu-latest |
| 41 | + needs: preview-context |
| 42 | + steps: |
| 43 | + - uses: dawidd6/action-download-artifact@v8 |
| 44 | + with: |
| 45 | + workflow: ${{ github.event.workflow_run.workflow_id }} |
| 46 | + run_id: ${{ github.event.workflow_run.id }} |
| 47 | + name: tdesign-miniprogram-site |
| 48 | + - run: | |
| 49 | + export DEPLOY_DOMAIN=${{ needs.preview-context.outputs.tdesign_miniprogram_domain }} |
| 50 | + npx surge --project ./ --domain $DEPLOY_DOMAIN --token ${{ secrets.TDESIGN_SURGE_TOKEN }} |
| 51 | +
|
| 52 | + tdesign-miniprogram-chat: |
| 53 | + if: github.event.workflow_run.conclusion == 'success' |
| 54 | + runs-on: ubuntu-latest |
| 55 | + needs: preview-context |
| 56 | + steps: |
| 57 | + - uses: dawidd6/action-download-artifact@v8 |
| 58 | + with: |
| 59 | + workflow: ${{ github.event.workflow_run.workflow_id }} |
| 60 | + run_id: ${{ github.event.workflow_run.id }} |
| 61 | + name: tdesign-miniprogram-chat-site |
| 62 | + - run: | |
| 63 | + export DEPLOY_DOMAIN=${{ needs.preview-context.outputs.tdesign_miniprogram_chat_domain }} |
| 64 | + npx surge --project ./ --domain $DEPLOY_DOMAIN --token ${{ secrets.TDESIGN_SURGE_TOKEN }} |
| 65 | +
|
| 66 | + preview-comment: |
| 67 | + if: always() |
| 68 | + needs: |
| 69 | + - preview-context |
| 70 | + - tdesign-miniprogram |
| 71 | + - tdesign-miniprogram-chat |
| 72 | + runs-on: ubuntu-latest |
| 73 | + steps: |
| 74 | + - name: jobs report |
| 75 | + id: report |
| 76 | + uses: actions/github-script@v7 |
| 77 | + with: |
| 78 | + script: | |
| 79 | + const pr_id = ${{ needs.preview-context.outputs.pr_id }}; |
| 80 | + const tdesign_miniprogram_domain = "${{ needs.preview-context.outputs.tdesign_miniprogram_domain }}"; |
| 81 | + const tdesign_miniprogram_chat_domain = "${{ needs.preview-context.outputs.tdesign_miniprogram_chat_domain }}"; |
| 82 | +
|
| 83 | + const { data: { jobs } } = await github.rest.actions.listJobsForWorkflowRun({ |
| 84 | + owner: context.repo.owner, |
| 85 | + repo: context.repo.repo, |
| 86 | + run_id: context.runId, |
| 87 | + per_page: 100 |
| 88 | + }) |
| 89 | +
|
| 90 | + const tdesign = { |
| 91 | + "tdesign-miniprogram": { status: "", report_url: "" }, |
| 92 | + "tdesign-miniprogram-chat": { status: "", report_url: "" }, |
| 93 | + }; |
| 94 | + const preview_success = `<img width="300" alt="完成" src="https://user-images.githubusercontent.com/15634204/150816437-9f5bb788-cd67-4cbc-9897-b82d74e9aa65.png" />`; |
| 95 | + const preview_failure = `<img width="300" alt="失败" src="https://user-images.githubusercontent.com/5378891/75333447-1e63a280-58c1-11ea-975d-235367fd1522.png" />`; |
| 96 | + jobs |
| 97 | + .filter((job) => job.name.startsWith("tdesign-")) |
| 98 | + .map((job) => { |
| 99 | + tdesign[job.name].status = preview_failure; |
| 100 | + tdesign[job.name].report_url = job.html_url; |
| 101 | +
|
| 102 | + if (job.conclusion === "success") { |
| 103 | + tdesign[job.name].status = preview_success; |
| 104 | + if (job.name === "tdesign-miniprogram") { |
| 105 | + |
| 106 | + tdesign[job.name].report_url = tdesign_miniprogram_domain; |
| 107 | + } |
| 108 | + if (job.name === "tdesign-miniprogram-chat") { |
| 109 | + tdesign[job.name].report_url = tdesign_miniprogram_chat_domain; |
| 110 | + } |
| 111 | + } |
| 112 | + }); |
| 113 | +
|
| 114 | + const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; |
| 115 | +
|
| 116 | + const comment = ` |
| 117 | + # TDesign Component Site Preview [Open](${runUrl}) |
| 118 | + | Component | Preview | |
| 119 | + | --------- | :--: | |
| 120 | + ${Object.keys(tdesign) |
| 121 | + .map((component) => { |
| 122 | + const preview_text = `[${tdesign[component].status}](${tdesign[component].report_url})`; |
| 123 | + let package_name = component; |
| 124 | + if (component === "tdesign-miniprogram-chat") { |
| 125 | + package_name = "@tdesign-miniprogram/chat"; |
| 126 | + } |
| 127 | +
|
| 128 | + return `| ${package_name} | ${preview_text} | `; |
| 129 | + }) |
| 130 | + .join("\n")} |
| 131 | +
|
| 132 | + <!-- AUTO_PREVIEW_HOOK --> |
| 133 | + `; |
| 134 | +
|
| 135 | + core.setOutput('comment', comment); |
| 136 | +
|
| 137 | + - name: comment |
| 138 | + uses: actions-cool/maintain-one-comment@v3 |
| 139 | + with: |
| 140 | + token: ${{ secrets.TDESIGN_BOT_TOKEN }} |
| 141 | + number: ${{needs.preview-context.outputs.pr_id}} |
| 142 | + body: ${{ steps.report.outputs.comment }} |
| 143 | + body-include: '<!-- AUTO_PREVIEW_HOOK -->' |
0 commit comments