forked from n8n-io/n8n
-
Notifications
You must be signed in to change notification settings - Fork 0
69 lines (58 loc) · 2.08 KB
/
ci-check-release-from-fork.yml
File metadata and controls
69 lines (58 loc) · 2.08 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
name: 'CI: Block fork PRs to release branches'
on:
pull_request:
branches:
- 'release/**'
types:
- opened
- reopened
- synchronize
- ready_for_review
- edited
jobs:
block-fork-prs:
runs-on: ubuntu-slim
permissions:
pull-requests: write
contents: read
steps:
- name: Check if PR is from a fork
id: check
run: |
if [ "${{ github.event.pull_request.head.repo.fork }}" = "true" ]; then
echo "fork=true" >> "$GITHUB_OUTPUT"
else
echo "fork=false" >> "$GITHUB_OUTPUT"
fi
- name: Comment on PR explaining the block
if: steps.check.outputs.fork == 'true'
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
with:
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
});
const alreadyCommented = comments.some(
(c) => c.user.login === 'github-actions[bot]' && c.body.includes('Pull request blocked')
);
if (!alreadyCommented) {
const body = `
🚫 **Pull request blocked**
Pull requests from **forked repositories** are not allowed to target **release branches** in this repository.
**Target branch:** \`${context.payload.pull_request.base.ref}\`
If you believe this was blocked in error, contact the repository maintainers.
`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body
});
}
- name: Fail workflow if from fork
if: steps.check.outputs.fork == 'true'
run: |
echo "PR from fork targeting a release branch is not allowed."
exit 1