Skip to content

Commit 160d348

Browse files
authored
chore: require approval via environments for PR preview (#217)
1 parent cda94b2 commit 160d348

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

.github/workflows/pr-preview.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,52 @@ on:
55
types: [opened, synchronize, reopened]
66

77
jobs:
8+
request-approval:
9+
name: Request Approval
10+
runs-on: ubuntu-latest
11+
permissions:
12+
pull-requests: write
13+
steps:
14+
- name: Comment requesting approval
15+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
16+
with:
17+
script: |
18+
// Check if approval comment already exists
19+
const { data: comments } = await github.rest.issues.listComments({
20+
owner: context.repo.owner,
21+
repo: context.repo.repo,
22+
issue_number: context.issue.number,
23+
});
24+
25+
const approvalComment = comments.find(comment =>
26+
comment.body.includes('<!-- approval-request-comment -->')
27+
);
28+
29+
// Only create comment if it doesn't exist
30+
if (!approvalComment) {
31+
await github.rest.issues.createComment({
32+
owner: context.repo.owner,
33+
repo: context.repo.repo,
34+
issue_number: context.issue.number,
35+
body: `<!-- approval-request-comment -->
36+
## ⚠️ &nbsp;Manual approval required
37+
38+
A repository owner must approve the Docker preview deployment for this PR.
39+
40+
**PR Author:** @${{ github.event.pull_request.user.login }}
41+
**Head SHA:** \`${{ github.event.pull_request.head.sha }}\`
42+
43+
[Review and approve in Actions →](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})`
44+
});
45+
}
46+
847
pr-preview:
948
name: Deploy on Docker
1049
runs-on: ubuntu-latest
50+
needs: request-approval
51+
environment:
52+
name: "PR Preview"
53+
url: https://github.com/${{ github.repository }}/pkgs/container/actions-clever-cloud
1154
permissions:
1255
contents: read
1356
packages: write

0 commit comments

Comments
 (0)