-
-
Notifications
You must be signed in to change notification settings - Fork 62
129 lines (111 loc) · 4.2 KB
/
treeshake-test.yml
File metadata and controls
129 lines (111 loc) · 4.2 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: Tree-shake test
on:
pull_request:
workflow_dispatch:
inputs:
target_branch:
description: 'Target branch to compare against'
required: true
default: 'main'
jobs:
treeshake-test:
if: github.event.pull_request.head.repo.full_name == github.repository
permissions:
contents: read
issues: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10.27.0
run_install: false
- name: Checkout PR branch
uses: actions/checkout@v4
with:
path: pr-branch
- name: Checkout target branch
uses: actions/checkout@v4
with:
path: target-branch
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.target_branch || github.base_ref }}
- name: Install dependencies (PR branch)
working-directory: pr-branch
run: pnpm install
- name: Install dependencies (target branch)
working-directory: target-branch
run: pnpm install
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 24.x
cache: 'pnpm'
cache-dependency-path: |
pr-branch/pnpm-lock.yaml
target-branch/pnpm-lock.yaml
- name: Generate import tests on PR branch
working-directory: pr-branch
run: pnpm --filter treeshake-test generate-tests
- name: Generate import tests on target branch
working-directory: target-branch
run: pnpm --filter treeshake-test generate-tests
- name: Run tree-shake test on PR branch
working-directory: pr-branch
run: pnpm --filter treeshake-test test --tsdown ${{ github.event_name == 'workflow_dispatch' && '--webpack' || '' }}
- name: Run tree-shake test on target branch
working-directory: target-branch
run: pnpm --filter treeshake-test test --tsdown ${{ github.event_name == 'workflow_dispatch' && '--webpack' || '' }}
- name: Compare results
run: |
node pr-branch/apps/treeshake-test/compareResults.ts \
pr-branch/apps/treeshake-test/results.json \
target-branch/apps/treeshake-test/results.json \
> comparison.md
- name: Comment PR with results
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const comparison = fs.readFileSync('comparison.md', 'utf8');
const botCommentIdentifier = '<!-- treeshake-test-bot-comment -->';
async function findBotComment(issueNumber) {
if (!issueNumber) return null;
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
});
return comments.data.find((comment) =>
comment.body.includes(botCommentIdentifier)
);
}
async function createOrUpdateComment(issueNumber) {
if (!issueNumber) {
console.log('No issue number provided. Cannot post or update comment.');
return;
}
const existingComment = await findBotComment(issueNumber);
if (existingComment) {
await github.rest.issues.updateComment({
...context.repo,
comment_id: existingComment.id,
body: botCommentIdentifier + '\n' + comparison,
});
} else {
await github.rest.issues.createComment({
...context.repo,
issue_number: issueNumber,
body: botCommentIdentifier + '\n' + comparison,
});
}
}
const issueNumber = context.issue.number;
if (!issueNumber) {
console.log('No issue number found in context. Skipping comment.');
} else {
await createOrUpdateComment(issueNumber);
}
await core.summary
.addRaw(comparison)
.write();