ci(pr): use pnpm #4452
This file contains 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
# 文件名建议统一为 pull-request.yml | |
# 应用 test-build.yml 的 demo | |
name: MAIN_PULL_REQUEST | |
on: | |
pull_request: | |
branches: [develop, main] | |
types: [opened, synchronize, reopened] | |
jobs: | |
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 | |
- 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 | |
- 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 | |
- 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 _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 | |
- 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 | |
run: pnpm run build |