Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/preview-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: preview-build

on:
pull_request:
branches: [develop, main]
types: [opened, synchronize, reopened]

jobs:
tdesign-react-site:
runs-on: ubuntu-latest
steps:
- run: echo ${{ github.event.number }} > pr-id.txt
- uses: actions/upload-artifact@v4
with:
name: pr-id
path: pr-id.txt
retention-days: 5

- uses: actions/checkout@v4
with:
submodules: recursive

- uses: pnpm/action-setup@v4

- uses: actions/setup-node@v4
with:
node-version: 18

- run: pnpm install

- run: pnpm -C packages/tdesign-react/site run preview

- uses: actions/upload-artifact@v4
with:
name: tdesign-react-site
path: packages/tdesign-react/site/dist
retention-days: 5

tdesign-react-chat-site:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: pnpm/action-setup@v4

- uses: actions/setup-node@v4
with:
node-version: 18

- run: pnpm install

- run: pnpm -C packages/tdesign-react-aigc/site run preview

- uses: actions/upload-artifact@v4
with:
name: tdesign-react-chat-site
path: packages/tdesign-react-aigc/site/dist
retention-days: 5
187 changes: 120 additions & 67 deletions .github/workflows/preview-publish.yml
Original file line number Diff line number Diff line change
@@ -1,90 +1,143 @@
# 文件名建议统一为 preview-publish
# 应用 preview.yml 的 demo
name: PREVIEW_PUBLISH
name: preview-publish

on:
workflow_run:
workflows: ["MAIN_PULL_REQUEST"]
workflows:
- preview-build
types:
- completed

jobs:
preview-success:
preview-context:
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
outputs:
pr_id: ${{ steps.pr.outputs.id }}
tdesign_react_domain: ${{ steps.tdesign-react-domain.outputs.tdesign_react_domain }}
tdesign_react_chat_domain: ${{ steps.tdesign-react-chat-domain.outputs.tdesign_react_chat_domain }}
steps:
- name: download pr artifact
uses: dawidd6/action-download-artifact@v6
- 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
- name: save PR id
id: pr
run: echo "id=$(<pr-id.txt)" >> $GITHUB_OUTPUT
- name: download site artifact
uses: dawidd6/action-download-artifact@v6
name: pr-id

- name: Set pr id
id : pr
run: echo "id=$(cat pr-id.txt)" >> $GITHUB_OUTPUT

- name: tdesign-react-domain
id: tdesign-react-domain
run: echo "tdesign_react_domain=https://preview-pr-${{ steps.pr.outputs.id }}-tdesign-react.surge.sh" >> $GITHUB_OUTPUT

- name: tdesign-react-chat-domain
id: tdesign-react-chat-domain
run: echo "tdesign_react_chat_domain=https://preview-pr-${{ steps.pr.outputs.id }}-tdesign-react-chat.surge.sh" >> $GITHUB_OUTPUT

tdesign-react:
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: site
name: tdesign-react-site
- run: |
unzip site.zip

- name: Upload surge service and generate preview URL
id: deploy
run: |
repository=${{github.repository}}
project_name=${repository#*/}
export DEPLOY_DOMAIN=https://preview-pr-${{ steps.pr.outputs.id }}-$project_name.surge.sh
npx surge --project ./packages/tdesign-react/site/dist --domain $DEPLOY_DOMAIN --token ${{ secrets.TDESIGN_SURGE_TOKEN }}
echo the preview URL is $DEPLOY_DOMAIN
echo "url=$DEPLOY_DOMAIN" >> $GITHUB_OUTPUT
- name: update status comment
uses: actions-cool/maintain-one-comment@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
<a href="${{steps.deploy.outputs.url}}"><img height="96" alt="完成" src="https://user-images.githubusercontent.com/15634204/150816437-9f5bb788-cd67-4cbc-9897-b82d74e9aa65.png" /></a>
<!-- [工作流地址](${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}) -->
<!-- AUTO_PREVIEW_HOOK -->
number: ${{ steps.pr.outputs.id }}
body-include: "<!-- AUTO_PREVIEW_HOOK -->"

- name: The job failed
if: ${{ failure() }}
uses: actions-cool/maintain-one-comment@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
[<img height="96" alt="失败" src="https://user-images.githubusercontent.com/5378891/75333447-1e63a280-58c1-11ea-975d-235367fd1522.png">](${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}})
<!-- AUTO_PREVIEW_HOOK -->
number: ${{ steps.pr.outputs.id }}
body-include: "<!-- AUTO_PREVIEW_HOOK -->"

preview-failed:
export DEPLOY_DOMAIN=${{ needs.preview-context.outputs.tdesign_react_domain }}
npx surge --project ./ --domain $DEPLOY_DOMAIN --token ${{ secrets.TDESIGN_SURGE_TOKEN }}

tdesign-react-chat:
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'failure'
needs: preview-context
steps:
- name: download pr artifact
uses: dawidd6/action-download-artifact@v6
- uses: dawidd6/action-download-artifact@v8
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
run_id: ${{ github.event.workflow_run.id }}
name: pr
- name: save PR id
id: pr
run: echo "id=$(<pr-id.txt)" >> $GITHUB_OUTPUT
- name: The job failed
name: tdesign-react-chat-site
- run: |
export DEPLOY_DOMAIN=${{ needs.preview-context.outputs.tdesign_react_chat_domain }}
npx surge --project ./ --domain $DEPLOY_DOMAIN --token ${{ secrets.TDESIGN_SURGE_TOKEN }}

preview-comment:
if: always()
needs:
- preview-context
- tdesign-react
- tdesign-react-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_react_domain = "${{ needs.preview-context.outputs.tdesign_react_domain }}";
const tdesign_react_chat_domain = "${{ needs.preview-context.outputs.tdesign_react_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-react": { status: "", report_url: "" },
"tdesign-react-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-react") {

tdesign[job.name].report_url = tdesign_react_domain;
}
if (job.name === "tdesign-react-chat") {
tdesign[job.name].report_url = tdesign_react_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-react-chat") {
package_name = "@tdesign-react/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.GITHUB_TOKEN }}
body: |
[<img height="96" alt="失败" src="https://user-images.githubusercontent.com/5378891/75333447-1e63a280-58c1-11ea-975d-235367fd1522.png">](${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}})
<!-- AUTO_PREVIEW_HOOK -->
number: ${{ steps.pr.outputs.id }}
body-include: "<!-- AUTO_PREVIEW_HOOK -->"
token: ${{ secrets.TDESIGN_BOT_TOKEN }}
number: ${{needs.preview-context.outputs.pr_id}}
body: ${{ steps.report.outputs.comment }}
body-include: '<!-- AUTO_PREVIEW_HOOK -->'
55 changes: 0 additions & 55 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,61 +79,6 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}

site:
runs-on: ubuntu-latest
# needs: test
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: pnpm/action-setup@v4

- uses: actions/setup-node@v4
with:
node-version-file: .node-version

- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT

- uses: actions/cache@v4
with:
# 缓存路径
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
# 缓存键
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
# 恢复缓存的备用键
restore-keys: |
${{ runner.os }}-pnpm-store-

- run: pnpm install

- name: Build site
run: pnpm site:preview

- run: |
zip -r site.zip packages/tdesign-react/site/dist

- name: upload site artifact
uses: actions/upload-artifact@v4
with:
name: site
path: site.zip
retention-days: 5

- name: Save PR number
if: ${{ always() }}
run: echo ${{ github.event.number }} > ./pr-id.txt

- name: Upload PR number
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: pr
path: ./pr-id.txt

build:
runs-on: ubuntu-latest
# needs: build
Expand Down
Loading