forked from faker-js/faker
-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (102 loc) · 3.81 KB
/
pr.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: PR
on:
pull_request_target:
permissions: {} # Permissions per job
jobs:
check-code-generation:
runs-on: ubuntu-latest
timeout-minutes: 10
name: 'Check Code Generation: node-22, ubuntu-latest'
permissions:
# Do not add any additional permissions here, as these can be used by third-party contributors
contents: read # to fetch code (actions/checkout)
outputs:
generate: ${{ steps.generate.outcome }}
diff: ${{ steps.diff.outcome }}
steps:
- name: Checkout
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Install pnpm
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
- name: Set node version to 22
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
with:
node-version: 22
cache: 'pnpm'
- name: Install deps
run: pnpm install
env:
CYPRESS_INSTALL_BINARY: 0
- name: Generate code
id: generate
run: |
pnpm run generate:locales
pnpm run generate:api-docs
pnpm run build
pnpm run test -u
continue-on-error: true
env:
CI_PREFLIGHT: true
- name: Check diff
id: diff
run: |
git add .
git diff --cached --name-only | sed -E 's/^(.*)$/::error file=\1,title=Diff detected::Please run `pnpm run preflight` and commit the changes./'
git diff --cached --name-only --exit-code
continue-on-error: true
- name: Status
if: ${{ steps.generate.outcome == 'failure' || steps.diff.outcome == 'failure' }}
run: exit 1
write-comment:
runs-on: ubuntu-latest
timeout-minutes: 5
name: 'Comment Code Generation'
permissions:
pull-requests: write # to write the comment
needs: check-code-generation
if: ${{ always() }}
steps:
- name: Write comment
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const repoArgs = { owner: context.repo.owner, repo: context.repo.repo };
const issue_number = context.issue.number;
// Check if the PR already has a comment from the bot
const { data: comments } = await github.rest.issues.listComments({
...repoArgs,
issue_number,
});
const body = `GitHub Actions has found some problems running the preflight checks.
Please make sure to:
- run \`pnpm run preflight\` locally
- fix all issues until the command completes without errors
- commit and push the changes
`;
const botComment = comments.find(
(comment) => comment.user?.type === 'Bot' && comment.body?.includes(body)
);
const generateSuccess = ${{ needs.check-code-generation.outputs.generate == 'success' }};
const diffSuccess = ${{ needs.check-code-generation.outputs.diff == 'success' }};
if (generateSuccess && diffSuccess) {
// Delete the bot comment if present
if (botComment != null) {
await github.rest.issues.deleteComment({
...repoArgs,
comment_id: botComment.id,
});
}
} else {
// Create the comment if missing
if (botComment == null) {
await github.rest.issues.createComment({
...repoArgs,
issue_number,
body,
});
}
}