-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #173 from pantheon-systems/BUGS-6560-Tag-Branches
[BUGS-6560]: Provides creation of branch on tag push.
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |