Skip to content

Commit

Permalink
🔄 GitBook Release-Branch action: synced local '.github/workflows/rele…
Browse files Browse the repository at this point in the history
…ase-branch.yml' with remote '.github/workflows/release-branch.yml' (#1109)
  • Loading branch information
sovitybot authored Jan 15, 2025
1 parent b0a9f12 commit 87da23f
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions .github/workflows/release-branch.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
name: Create Release Branch
# GitBook external customer documentation: This action creates a branch for each release, which can optionally be used in GitBook to maintain service-versioned documentation streamlined with service-releases.
# If an existing release is deleted and re-released, the original release-branch is deleted and recreated with the re-release.
# Simply deleting a release without re-releasing does not delete the release-branch, as it could already be used by GitBook.

name: Create Release Branch for GitBook

on:
release:
Expand All @@ -18,15 +22,37 @@ jobs:
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
- name: Create a new branch from the release
- name: Check if branch already exists
id: check-branch
run: |
# Normalize the release tag to ensure it is a valid branch name
SAFE_TAG_NAME=$(echo "${{ github.event.release.tag_name }}" | sed 's/[^a-zA-Z0-9._-]/-/g')
BRANCH_NAME="release/$SAFE_TAG_NAME"
if git ls-remote --heads origin $BRANCH_NAME | grep -q $BRANCH_NAME; then
echo "Branch $BRANCH_NAME already exists."
echo "branch-exists=true" >> $GITHUB_ENV
else
echo "Branch $BRANCH_NAME does not exist."
echo "branch-exists=false" >> $GITHUB_ENV
fi
- name: Delete existing branch if it exists (re-release?)
if: env.branch-exists == 'true'
run: |
# Normalize the release tag to ensure it is a valid branch name
SAFE_TAG_NAME=$(echo "${{ github.event.release.tag_name }}" | sed 's/[^a-zA-Z0-9._-]/-/g')
BRANCH_NAME="release/$SAFE_TAG_NAME"
echo "Deleting existing branch $BRANCH_NAME."
git push origin --delete $BRANCH_NAME || echo "Branch $BRANCH_NAME could not be deleted (might not exist on remote)."
- name: Create and push the new branch
run: |
# Normalize the release tag to ensure it is a valid branch name
SAFE_TAG_NAME=$(echo "${{ github.event.release.tag_name }}" | sed 's/[^a-zA-Z0-9._-]/-/g')
BRANCH_NAME="release/$SAFE_TAG_NAME"
echo "Creating branch $BRANCH_NAME"
git branch $BRANCH_NAME
git push origin $BRANCH_NAME
- name: Confirm branch creation
run: |
echo "Release-Branch created successfully."

0 comments on commit 87da23f

Please sign in to comment.