Skip to content

Commit

Permalink
ci(pr): use pnpm
Browse files Browse the repository at this point in the history
  • Loading branch information
liweijie0812 committed Mar 2, 2025
1 parent dd4c832 commit 92b6cf3
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 7 deletions.
86 changes: 82 additions & 4 deletions .github/workflows/preview-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,85 @@ on:
- completed

jobs:
call-preview:
uses: Tencent/tdesign/.github/workflows/preview.yml@main
secrets:
TDESIGN_SURGE_TOKEN: ${{ secrets.TDESIGN_SURGE_TOKEN }}
preview-success:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- name: download pr artifact
uses: dawidd6/action-download-artifact@v6
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
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
run_id: ${{ github.event.workflow_run.id }}
name: _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 ./_site --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 -->"

- run: |
rm -rf _site/
- 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:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'failure'
steps:
- name: download pr artifact
uses: dawidd6/action-download-artifact@v6
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
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 -->"
147 changes: 144 additions & 3 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 文件名建议统一为 pull-request.yml
# 文件名建议统一为 pull-request.yml
# 应用 test-build.yml 的 demo

name: MAIN_PULL_REQUEST
Expand All @@ -9,5 +9,146 @@ on:
types: [opened, synchronize, reopened]

jobs:
call-test-build:
uses: Tencent/tdesign/.github/workflows/test-build.yml@main
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: check_github_primary_email
run: |
log_emails=$(git log --pretty=format:"%ae %ce" -1)
if [[ ${log_emails} =~ 'tdesign@tencent.com' ]];then
echo "$log_emails 跳过验证"
exit 0
fi
if [[ ${log_emails} =~ '@tencent.com' ]];then
echo "默认邮箱 $log_emails 校验非法,可以去 https://github.com/settings/emails 更改"
exit 2;
else
echo "邮箱 $log_emails 校验通过";
fi
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: check_local_email
run: |
log_emails=$(git log --pretty=format:"%ae %ce" -1)
if [[ ${log_emails} =~ 'tdesign@tencent.com' ]];then
echo "$log_emails 跳过验证"
exit 0
fi
if [[ ${log_emails} =~ '@tencent.com' ]];then
echo "本地提交邮箱 $log_emails 校验非法,需要本地更改重新提交"
exit 2;
else
echo "邮箱 $log_emails 校验通过";
fi
test:
# needs: check
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-file: .node-version

- 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
- run: pnpm run lint
- run: pnpm run test
# upload report to codecov
- uses: codecov/codecov-action@v2
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

- 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 _site
- 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
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: pnpm/action-setup@v4

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

- 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
run: pnpm run build
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "tdesign-react",
"packageManager": "pnpm@9.5.0",
"purename": "tdesign",
"version": "1.11.1",
"description": "TDesign Component for React",
Expand Down

0 comments on commit 92b6cf3

Please sign in to comment.