preview-site-publish #716
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-site-publish | |
| on: | |
| workflow_run: | |
| workflows: | |
| - preview-site-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_miniprogram_domain: ${{ steps.tdesign-miniprogram-domain.outputs.tdesign_miniprogram_domain }} | |
| tdesign_miniprogram_chat_domain: ${{ steps.tdesign-miniprogram-chat-domain.outputs.tdesign_miniprogram_chat_domain }} | |
| tdesign_uniapp_domain: ${{ steps.tdesign-uniapp-domain.outputs.tdesign_uniapp_domain }} | |
| tdesign_uniapp_chat_domain: ${{ steps.tdesign-uniapp-chat-domain.outputs.tdesign_uniapp_chat_domain }} | |
| steps: | |
| - name: Download pr id | |
| uses: dawidd6/action-download-artifact@v12 | |
| 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-miniprogram-domain | |
| id: tdesign-miniprogram-domain | |
| run: echo "tdesign_miniprogram_domain=https://preview-pr-${{ steps.pr.outputs.id }}-tdesign-miniprogram.surge.sh" >> $GITHUB_OUTPUT | |
| - name: tdesign-miniprogram-chat-domain | |
| id: tdesign-miniprogram-chat-domain | |
| run: echo "tdesign_miniprogram_chat_domain=https://preview-pr-${{ steps.pr.outputs.id }}-tdesign-miniprogram-chat.surge.sh" >> $GITHUB_OUTPUT | |
| - name: tdesign-uniapp-domain | |
| id: tdesign-uniapp-domain | |
| run: echo "tdesign_uniapp_domain=https://preview-pr-${{ steps.pr.outputs.id }}-tdesign-uniapp.surge.sh" >> $GITHUB_OUTPUT | |
| - name: tdesign-uniapp-chat-domain | |
| id: tdesign-uniapp-chat-domain | |
| run: echo "tdesign_uniapp_chat_domain=https://preview-pr-${{ steps.pr.outputs.id }}-tdesign-uniapp-chat.surge.sh" >> $GITHUB_OUTPUT | |
| tdesign-miniprogram: | |
| if: github.event.workflow_run.conclusion == 'success' | |
| runs-on: ubuntu-latest | |
| needs: preview-context | |
| steps: | |
| - uses: dawidd6/action-download-artifact@v12 | |
| with: | |
| workflow: ${{ github.event.workflow_run.workflow_id }} | |
| run_id: ${{ github.event.workflow_run.id }} | |
| name: tdesign-miniprogram-site | |
| - run: | | |
| export DEPLOY_DOMAIN=${{ needs.preview-context.outputs.tdesign_miniprogram_domain }} | |
| npx surge --project ./ --domain $DEPLOY_DOMAIN --token ${{ secrets.TDESIGN_SURGE_TOKEN }} | |
| tdesign-miniprogram-chat: | |
| if: github.event.workflow_run.conclusion == 'success' | |
| runs-on: ubuntu-latest | |
| needs: preview-context | |
| steps: | |
| - uses: dawidd6/action-download-artifact@v12 | |
| with: | |
| workflow: ${{ github.event.workflow_run.workflow_id }} | |
| run_id: ${{ github.event.workflow_run.id }} | |
| name: tdesign-miniprogram-chat-site | |
| - run: | | |
| export DEPLOY_DOMAIN=${{ needs.preview-context.outputs.tdesign_miniprogram_chat_domain }} | |
| npx surge --project ./ --domain $DEPLOY_DOMAIN --token ${{ secrets.TDESIGN_SURGE_TOKEN }} | |
| tdesign-uniapp: | |
| if: github.event.workflow_run.conclusion == 'success' | |
| runs-on: ubuntu-latest | |
| needs: preview-context | |
| steps: | |
| - uses: dawidd6/action-download-artifact@v12 | |
| with: | |
| workflow: ${{ github.event.workflow_run.workflow_id }} | |
| run_id: ${{ github.event.workflow_run.id }} | |
| name: tdesign-uniapp-site | |
| - run: | | |
| export DEPLOY_DOMAIN=${{ needs.preview-context.outputs.tdesign_uniapp_domain }} | |
| npx surge --project ./ --domain $DEPLOY_DOMAIN --token ${{ secrets.TDESIGN_SURGE_TOKEN }} | |
| tdesign-uniapp-chat: | |
| if: github.event.workflow_run.conclusion == 'success' | |
| runs-on: ubuntu-latest | |
| needs: preview-context | |
| steps: | |
| - uses: dawidd6/action-download-artifact@v12 | |
| with: | |
| workflow: ${{ github.event.workflow_run.workflow_id }} | |
| run_id: ${{ github.event.workflow_run.id }} | |
| name: tdesign-uniapp-chat-site | |
| - run: | | |
| export DEPLOY_DOMAIN=${{ needs.preview-context.outputs.tdesign_uniapp_chat_domain }} | |
| npx surge --project ./ --domain $DEPLOY_DOMAIN --token ${{ secrets.TDESIGN_SURGE_TOKEN }} | |
| preview-comment: | |
| if: always() | |
| needs: | |
| - preview-context | |
| - tdesign-miniprogram | |
| - tdesign-miniprogram-chat | |
| - tdesign-uniapp | |
| - tdesign-uniapp-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_miniprogram_domain = "${{ needs.preview-context.outputs.tdesign_miniprogram_domain }}"; | |
| const tdesign_miniprogram_chat_domain = "${{ needs.preview-context.outputs.tdesign_miniprogram_chat_domain }}"; | |
| const tdesign_uniapp_domain = "${{ needs.preview-context.outputs.tdesign_uniapp_domain }}"; | |
| const tdesign_uniapp_chat_domain = "${{ needs.preview-context.outputs.tdesign_uniapp_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-miniprogram": { status: "", report_url: "" }, | |
| "tdesign-miniprogram-chat": { status: "", report_url: "" }, | |
| "tdesign-uniapp": { status: "", report_url: "" }, | |
| "tdesign-uniapp-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-miniprogram") { | |
| tdesign[job.name].report_url = tdesign_miniprogram_domain; | |
| } | |
| if (job.name === "tdesign-miniprogram-chat") { | |
| tdesign[job.name].report_url = tdesign_miniprogram_chat_domain; | |
| } | |
| if (job.name === "tdesign-uniapp") { | |
| tdesign[job.name].report_url = tdesign_uniapp_domain; | |
| } | |
| if (job.name === "tdesign-uniapp-chat") { | |
| tdesign[job.name].report_url = tdesign_uniapp_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-miniprogram-chat") { | |
| package_name = "@tdesign-miniprogram/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 -->' |