Skip to content

Commit

Permalink
Merge pull request #173 from pantheon-systems/BUGS-6560-Tag-Branches
Browse files Browse the repository at this point in the history
[BUGS-6560]: Provides creation of branch on tag push.
  • Loading branch information
rwagner00 authored Jan 24, 2024
2 parents 81ad81f + 883534a commit 966b24d
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/create-branch-on-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Create Branch on Tag Push

on:
push:
tags:
- '*'

jobs:
create-branch:
runs-on: ubuntu-latest
if: ${{ github.repository == 'pantheon-systems/search_api_pantheon' }}
env:
BRANCH: ${{ github.ref_name }}
WORKSPACE: ${{ github.workspace }}
DRUPAL_ORG_REMOTE: ${{ secrets.DRUPAL_ORG_REMOTE }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}
if_key_exists: ignore
- name: Extract tag name
id: tag_name
run: |
FULL_TAG=${GITHUB_REF#refs/tags/}
MAJOR_MINOR="$(echo $FULL_TAG | cut -d '.' -f 1,2).x"
MAJOR_ONLY="$(echo $FULL_TAG | cut -d '.' -f 1).x"
echo "BRANCH_NAME=$MAJOR_MINOR" >> $GITHUB_OUTPUT
echo "MAJOR_BRANCH_NAME=$MAJOR_ONLY" >> $GITHUB_OUTPUT
- name: Check if branch exists
id: check_branch
run: |
git fetch
branch_existence=$(git ls-remote --heads origin ${{ steps.tag_name.outputs.BRANCH_NAME }})
if [[ -z ${branch_existence} ]]; then
echo "Branch for tag does not exist."
echo "exists=false" >> $GITHUB_OUTPUT
else
echo "Branch for tag already exists."
echo "exists=true" >> $GITHUB_OUTPUT
fi
- name: Create branch
if: steps.check_branch.outputs.exists == 'false'
run: |
git checkout -b ${{ steps.tag_name.outputs.BRANCH_NAME }} origin/${{ steps.tag_name.outputs.MAJOR_BRANCH_NAME }}
git push origin ${{ steps.tag_name.outputs.BRANCH_NAME }}
- name: Merge changes from current default branch
if: steps.check_branch.outputs.exists == 'true'
run: |
git fetch
git checkout -b ${{ steps.tag_name.outputs.BRANCH_NAME }} origin/${{ steps.tag_name.outputs.BRANCH_NAME }}
git merge origin/${{ steps.tag_name.outputs.MAJOR_BRANCH_NAME }}
git push origin HEAD:${{ steps.tag_name.outputs.BRANCH_NAME }}
- name: Pushes to drupal.org repository
run: |
cd $WORKSPACE
git remote add drupalorg $DRUPAL_ORG_REMOTE
git push drupalorg HEAD:${{ steps.tag_name.outputs.BRANCH_NAME }}

0 comments on commit 966b24d

Please sign in to comment.