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."