1
- name : Create PR and Approve
1
+ name : Create PR, Approve, and Auto-Merge
2
2
3
3
on :
4
4
workflow_dispatch :
9
9
default : " dev"
10
10
11
11
jobs :
12
- create-pr-and- approve :
12
+ create-pr-approve-automerge :
13
13
runs-on : ubuntu-latest
14
14
15
15
permissions :
16
16
contents : write
17
17
pull-requests : write
18
18
19
19
steps :
20
+ # Paso 1: Checkout del repositorio
20
21
- name : Checkout Repository
21
22
uses : actions/checkout@v3
22
23
24
+ # Paso 2: Autenticar GitHub CLI
23
25
- name : Authenticate GitHub CLI
24
26
run : |
25
27
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
26
28
29
+ # Paso 3: Crear la Pull Request con una etiqueta específica
27
30
- name : Create Pull Request
28
31
id : create_pr
29
32
run : |
30
33
PR_OUTPUT=$(gh pr create \
31
34
--base main \
32
35
--head ${{ github.event.inputs.target_branch }} \
33
36
--title "Merge ${{ github.event.inputs.target_branch }} into main" \
34
- --body "This PR was created automatically by the workflow.")
37
+ --body "This PR was created automatically by the workflow." \
38
+ --label automerge)
35
39
echo "PR created: $PR_OUTPUT"
36
40
37
41
# Extraer el número del PR
38
42
PR_URL=$(echo "$PR_OUTPUT" | grep -Eo 'https://[^ ]+')
39
43
PR_NUMBER="${PR_URL##*/}"
40
44
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
41
45
42
- - name : Approve Pull Request
43
- run : |
44
- echo "Approving the PR as ${{ github.actor }}..."
45
- gh pr review ${{ env.PR_NUMBER }} --approve
46
-
47
- # Paso 6: Fusionar el Pull Request
48
- - name : Merge Pull Request
46
+ auto-merge :
47
+ runs-on : ubuntu-latest
48
+ if : github.event.pull_request.user.login == 'github-actions[bot]' && contains(github.event.pull_request.labels.*.name, 'automerge')
49
+ steps :
50
+ # Loguear metadata de la PR
51
+ - name : Log Metadata
49
52
run : |
50
- PR_NUMBER=${{ env.PR_NUMBER }}
51
- echo "Fusionando el PR #$PR_NUMBER..."
52
- gh pr merge $PR_NUMBER --merge --admin
53
+ echo "PR created by: ${{ github.event.pull_request.user.login }}"
54
+ echo "Labels: ${{ toJSON(github.event.pull_request.labels) }}"
55
+
56
+ # Habilitar Auto-Merge para PRs con la etiqueta 'automerge'
57
+ - name : Enable auto-merge for PRs with 'automerge' label
58
+ run : gh pr merge --auto --merge "${{ github.event.pull_request.html_url }}"
59
+ env :
60
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments