Skip to content

Create PR, Approve with User PAT, and Auto-Merge #41

Create PR, Approve with User PAT, and Auto-Merge

Create PR, Approve with User PAT, and Auto-Merge #41

Workflow file for this run

name: Create PR, Merge, and Deploy
on:
workflow_dispatch:
inputs:
target_branch:
description: "Rama desde la cual quieres crear el PR (ej. dev)"
required: true
default: "dev"
jobs:
create-merge-deploy:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
# Paso 1: Checkout del repositorio
- name: Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 0 # Necesario para operaciones completas de Git
# Paso 3: Autenticar GitHub CLI usando GITHUB_TOKEN
- name: Authenticate GitHub CLI
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
# Paso 4: Crear el Pull Request
- name: Create Pull Request
id: create_pr
run: |
PR_OUTPUT=$(gh pr create \
--base main \
--head ${{ github.event.inputs.target_branch }} \
--title "Fusionar ${{ github.event.inputs.target_branch }} a main" \
--body "Este PR se crea y fusionará automáticamente mediante el workflow." \
--label automerge)
# Extraer la URL del PR creado
PR_URL=$(echo "$PR_OUTPUT" | grep -Eo 'https://[^ ]+')
echo "PR_URL=$PR_URL" >> $GITHUB_ENV
# Extraer el número del PR de la URL
PR_NUMBER="${PR_URL##*/}"
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
# Paso 6: Fusionar el Pull Request
- name: Merge Pull Request
run: |
PR_NUMBER=${{ env.PR_NUMBER }}
echo "Fusionando el PR #$PR_NUMBER..."
gh pr merge $PR_NUMBER --merge --admin