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' (#14)
  • Loading branch information
sovitybot authored Feb 4, 2025
1 parent 73d9183 commit 5f177ff
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 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,13 +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: |
BRANCH_NAME="release/${{ github.event.release.tag_name }}"
# 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 "Branch release/${{ github.event.release.tag_name }} created successfully."

0 comments on commit 5f177ff

Please sign in to comment.