-
Notifications
You must be signed in to change notification settings - Fork 0
101 lines (90 loc) · 3.69 KB
/
Copy pathpreview.yml
File metadata and controls
101 lines (90 loc) · 3.69 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
name: Preview Environment
# Workflow para deploy do ambiente de preview/staging
# Executado em:
# - Pull Requests (para preview de mudanças)
# - Push em branches release/* (para testes de release)
# Realiza testes, linting, build, deploy para Vercel (ambiente preview)
# e atualização automática de comentários nos PRs
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
# ✅ MÁGICA 1: Adicionado 'concurrency' para evitar disparos duplos
# (push + synchronize) no mesmo commit.
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.head.sha || github.sha }}
cancel-in-progress: true
on:
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
jobs:
test-and-lint:
name: CI - Test & Lint
# Este job SEMPRE roda (para satisfazer o check obrigatório)
# O 'dummy pass' acontece DENTRO do 'reusable-lint'
uses: ./.github/workflows/reusable-test-and-lint.yml
with:
node-version: "22.x"
deploy-preview:
name: CI - Deploy to Vercel
needs: test-and-lint
# ❌ REMOVIDO: O 'if: needs.test-and-lint.outputs.code-changed == 'true''
# Este job TEM que rodar sempre para o status check
uses: ./.github/workflows/reusable-deploy-vercel.yml
with:
environment: Preview
vercel-environment: preview
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
prebuilt: true
prod: false
secrets:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
validate-release-branch:
name: Validate Release Branch for Main
# ✅ SEGUINDO O TUTORIAL: 'if:' sem aspas
if: github.event_name == 'pull_request' && github.base_ref == 'main'
runs-on: ubuntu-latest
steps:
- name: Check source branch name
run: |
SOURCE_BRANCH="${{ github.head_ref }}"
echo "Source branch: $SOURCE_BRANCH"
if [[ "$SOURCE_BRANCH" != release/* && "$SOURCE_BRANCH" != hotfix/* ]]; then
echo "::error::Pull Request from branch '$SOURCE_BRANCH' cannot be merged into 'main'. Only branches starting with 'release/' or 'hotfix/' are allowed."
exit 1
else
echo "Source branch '$SOURCE_BRANCH' is a valid release or hotfix branch."
fi
update-pr-comment:
# ✅ SEGUINDO O TUTORIAL: 'if:' sem aspas
if: github.event_name == 'pull_request'
name: Update PR Comment
# Este 'needs' garante que ele espere o deploy terminar (ou ser pulado)
needs: deploy-preview
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Find Previous Comment
uses: peter-evans/find-comment@v3
id: find_comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: "🚀 Vercel Preview Deployment"
- name: Create or Update PR Comment
uses: peter-evans/create-or-update-comment@v5
with:
comment-id: ${{ steps.find_comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
### 🚀 Vercel Preview Deployment
A pré-visualização para este PR foi atualizada.
| Recurso | Link |
|---|---|
| **🔗 URL de Preview** | [URL de Preview](${{ needs.deploy-preview.outputs.deployment_url }}) |
| **📜 Logs do Deploy** | [Ver logs da Action](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) |
---
*Commit: `${{ github.event.pull_request.head.sha }}`*
edit-mode: replace