|
1 | 1 | name: Deploy Preview Environment |
2 | 2 |
|
3 | 3 | on: |
4 | | - pull_request_target: # zizmor: ignore[dangerous-triggers] # We have a check disabling external forks. |
| 4 | + pull_request_target: # zizmor: ignore[dangerous-triggers] - Mitigated with label-based approval |
| 5 | + types: [labeled, synchronize, opened, reopened] |
5 | 6 | branches: |
6 | 7 | - main |
7 | 8 | paths: ['examples/homepage/**', 'packages/vechain-kit/**', 'yarn.lock'] |
8 | 9 |
|
9 | 10 | permissions: |
10 | 11 | contents: read |
11 | | - id-token: write |
12 | | - pull-requests: write |
13 | 12 |
|
14 | 13 | jobs: |
| 14 | + # Job 1: Post instruction comment for external PRs |
| 15 | + comment-external-pr: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + permissions: |
| 18 | + pull-requests: write |
| 19 | + if: | |
| 20 | + github.event.pull_request.head.repo.full_name != github.repository && |
| 21 | + github.event.action == 'opened' |
| 22 | + steps: |
| 23 | + - name: Comment on external PR |
| 24 | + uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0 |
| 25 | + with: |
| 26 | + issue-number: ${{ github.event.pull_request.number }} |
| 27 | + body: | |
| 28 | + ## 👋 Thanks for your contribution! |
| 29 | + |
| 30 | + Since this PR comes from a forked repository, preview deployment requires approval from a maintainer for security reasons. |
| 31 | + |
| 32 | + **Next steps:** |
| 33 | + 1. A maintainer will review your code |
| 34 | + 2. If approved, they'll add the `safe-to-deploy` label to trigger deployment |
| 35 | + 3. **After each new commit**, the maintainer will need to remove and re-add the label for security |
| 36 | + |
| 37 | + This ensures every version of the code is explicitly reviewed before deployment. Thank you for your patience! 🙏 |
| 38 | +
|
| 39 | + # Job 2: Deploy (runs for internal PRs OR when external PR gets labeled) |
15 | 40 | deploy: |
16 | 41 | runs-on: ubuntu-latest |
| 42 | + permissions: |
| 43 | + id-token: write |
| 44 | + pull-requests: write |
| 45 | + # Security gate: Only run when 'safe-to-deploy' label is ADDED OR from internal branch |
| 46 | + if: | |
| 47 | + (github.event.label.name == 'safe-to-deploy') || |
| 48 | + (github.event.pull_request.head.repo.full_name == github.repository) |
17 | 49 | env: |
18 | 50 | NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID: ${{ secrets.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID }} |
19 | 51 | NEXT_PUBLIC_PRIVY_APP_ID: ${{ secrets.NEXT_PUBLIC_PRIVY_APP_ID }} |
|
24 | 56 | AWS_REGION: eu-west-1 |
25 | 57 | BRANCH_NAME: ${{ github.event.pull_request.head.ref }} |
26 | 58 | steps: |
27 | | - - name: Security - Block external forks |
28 | | - run: | |
29 | | - if [ "$REPO_FULL_NAME" != "${{ github.repository }}" ]; then |
30 | | - echo "::error::Security Policy: PRs from forked repositories cannot run this workflow due to secret access requirements." |
31 | | - echo "::error::VeChain Team Members: Please create branches in the main repository instead of forking." |
32 | | - exit 1 |
33 | | - fi |
34 | | - env: |
35 | | - REPO_FULL_NAME: ${{ github.event.pull_request.head.repo.full_name }} |
36 | | - |
37 | 59 | - name: Checkout |
38 | 60 | uses: actions/checkout@v4 |
39 | 61 | with: |
|
76 | 98 | AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_PREVIEW_CLOUDFRONT_DISTRIBUTION_ID }} --paths '/' '/*' |
77 | 99 |
|
78 | 100 | - name: Create Deployment Comment |
79 | | - if: github.event.action == 'opened' || github.event.action == 'reopened' |
80 | 101 | uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0 |
81 | 102 | with: |
82 | 103 | issue-number: ${{ github.event.pull_request.number }} |
|
0 commit comments