Skip to content

Instantly share code, notes, and snippets.

@sebmellen
Created April 14, 2023 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebmellen/01213d7bfc950eda4214fd2318efb047 to your computer and use it in GitHub Desktop.
Save sebmellen/01213d7bfc950eda4214fd2318efb047 to your computer and use it in GitHub Desktop.
Create Pull Request from Tag Action
name: Create Pull Request from Tag
on:
workflow_dispatch:
inputs:
tag_name:
description: 'Tag Name'
required: true
target_branch:
description: 'Target Branch'
required: true
jobs:
create_pr:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install GitHub CLI
run: |
sudo apt-get install -y gh
- name: Authenticate GitHub CLI
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
- name: Create new branch from tag and push
run: |
TAG_NAME="${{ github.event.inputs.tag_name }}"
TARGET_BRANCH="${{ github.event.inputs.target_branch }}"
NEW_BRANCH_NAME="pr-for-tag-$TAG_NAME"
# Create a new branch from the tag
git checkout -b $NEW_BRANCH_NAME $TAG_NAME
# Push the new branch to the remote repository
git push origin $NEW_BRANCH_NAME
- name: Create pull request
run: |
NEW_BRANCH_NAME="pr-for-tag-${{ github.event.inputs.tag_name }}"
TARGET_BRANCH="${{ github.event.inputs.target_branch }}"
PR_TITLE="Pull request for tag ${{ github.event.inputs.tag_name }}"
# Create a pull request
gh pr create --title "$PR_TITLE" --body "Creating a pull request from tag ${{ github.event.inputs.tag_name }}" --base $TARGET_BRANCH --head $NEW_BRANCH_NAME --repo ${{ github.repository }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment