From 87da23fb5e663d77434ab954ad2d8cb67b0b75dc Mon Sep 17 00:00:00 2001 From: sovitybot <107936402+sovitybot@users.noreply.github.com> Date: Wed, 15 Jan 2025 15:03:51 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=84=20GitBook=20Release-Branch=20actio?= =?UTF-8?q?n:=20synced=20local=20'.github/workflows/release-branch.yml'=20?= =?UTF-8?q?with=20remote=20'.github/workflows/release-branch.yml'=20(#1109?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release-branch.yml | 38 +++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release-branch.yml b/.github/workflows/release-branch.yml index 47fd41026..02a92410b 100644 --- a/.github/workflows/release-branch.yml +++ b/.github/workflows/release-branch.yml @@ -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: @@ -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."