-
Notifications
You must be signed in to change notification settings - Fork 421
98 lines (83 loc) · 2.84 KB
/
pr-test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
name: PR Test
on:
pull_request_target:
branches: [main, dev]
paths: # 这里是用来指定哪个文件更改,才会触发的
- "src/**"
- "package.json"
- "types/**"
- "examples/**"
- "test/**"
jobs:
build:
# 不需要在fork仓库的pr中运行
if: github.repository == 'Tencent/cherry-markdown' && github.event.pull_request.draft == false
runs-on: ubuntu-latest
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
steps:
- uses: actions/checkout@v2
with:
ref: "${{ env.HEAD_SHA }}"
- name: Get changed files and operations
run: |
# 使用 GitHub API 获取变更文件列表及其操作
DIFF_DOCUMENTS=$(gh api repos/${{ github.repository }}/compare/${{ env.BASE_SHA }}...${{ env.HEAD_SHA }} \
--jq '.files | .[] | select(.status|IN("added", "modified", "renamed", "copied", "changed")) | .filename')
echo "Changed files and operations: ${DIFF_DOCUMENTS}"
# Eslint 检查js文件
LINT_FILES=$(echo "${DIFF_DOCUMENTS}" | grep -E '^.*\.js$' | xargs)
echo "LINT_FILES=${LINT_FILES}" >> $GITHUB_ENV
# 忽略 .github/workflows 下的文件
GIT_DIFF_FILES=$(echo "${DIFF_DOCUMENTS}" | grep -vE '^\.github\/workflows\/.*' | xargs)
echo "GIT_DIFF_FILES=${GIT_DIFF_FILES}" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v2
if: ${{ env.GIT_DIFF_FILES }}
with:
repository: ${{ github.repository }}
ref: "${{ env.BASE_SHA }}"
path: base-repo
- name: Replace changed files
if: ${{ env.GIT_DIFF_FILES }}
run: |
for file in ${{ env.GIT_DIFF_FILES }}; do
mkdir -p "base-repo/$(dirname "$file")"
cp "$file" "base-repo/$file"
done
- name: Use Node.js 16.x
uses: actions/setup-node@v2
with:
node-version: 16.x
cache: "yarn"
- name: Install dependencies
uses: borales/[email protected]
with:
cmd: install
- name: Lint Changed Files
if: ${{ env.LINT_FILES }}
run: |
for file in ${{ env.LINT_FILES }}; do
yarn eslint "$file"
done
- name: Run Build
uses: borales/[email protected]
with:
cmd: build
- name: Archive build dist
uses: actions/upload-artifact@v4
with:
name: build-dist
path: dist
- name: Archive examples
uses: actions/upload-artifact@v4
with:
name: build-examples
path: examples
review:
needs: build
permissions: write-all
uses: ./.github/workflows/pr-reviewer-COS.yml
secrets: inherit