fix: current branch name (#4823)

This commit is contained in:
Dhruwang Jariwala
2025-02-26 19:09:09 +05:30
committed by GitHub
parent 75315ea2c5
commit 1373863af5
6 changed files with 63 additions and 6 deletions

View File

@@ -15,6 +15,55 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # This ensures we get the full git history
- name: Get source branch name
id: branch-name
run: |
# Get the most recent merge commit
MERGE_COMMIT=$(git log --merges -n 1 --format="%H")
if [ -n "$MERGE_COMMIT" ]; then
# Extract the source branch name from the merge commit message
SOURCE_BRANCH=$(git log -1 --format="%s" $MERGE_COMMIT | grep -oP "from '?\K[^']*(?='?)" || echo "")
if [ -z "$SOURCE_BRANCH" ]; then
# Alternative method: get the first parent's branch
SOURCE_BRANCH=$(git name-rev --name-only $(git log -1 --merges --pretty=format:"%P" | cut -d' ' -f1))
SOURCE_BRANCH=${SOURCE_BRANCH#remotes/origin/}
SOURCE_BRANCH=${SOURCE_BRANCH%~*}
fi
# Only remove username prefix if it matches a GitHub username pattern
# GitHub usernames are alphanumeric with hyphens, but cannot start with hyphens
# This regex matches patterns like "username/" but preserves "feature/" prefixes
if [[ "$SOURCE_BRANCH" =~ ^[a-zA-Z0-9][a-zA-Z0-9-]+/ ]]; then
# Check if this looks like a username prefix (not a feature branch prefix)
PREFIX=${SOURCE_BRANCH%%/*}
# Common feature branch prefixes to preserve
if [[ ! "$PREFIX" =~ ^(feature|fix|bugfix|hotfix|release|chore|docs|test|refactor|style|perf|build|ci|revert)$ ]]; then
# If not a common branch prefix, assume it's a username and remove it
SOURCE_BRANCH=${SOURCE_BRANCH#*/}
fi
fi
echo "SOURCE_BRANCH=$SOURCE_BRANCH" >> $GITHUB_ENV
else
echo "No merge commit found, using current branch"
CURRENT_BRANCH=${GITHUB_REF##*/}
# Apply the same username vs feature prefix logic
if [[ "$CURRENT_BRANCH" =~ ^[a-zA-Z0-9][a-zA-Z0-9-]+/ ]]; then
PREFIX=${CURRENT_BRANCH%%/*}
if [[ ! "$PREFIX" =~ ^(feature|fix|bugfix|hotfix|release|chore|docs|test|refactor|style|perf|build|ci|revert)$ ]]; then
CURRENT_BRANCH=${CURRENT_BRANCH#*/}
fi
fi
echo "SOURCE_BRANCH=$CURRENT_BRANCH" >> $GITHUB_ENV
fi
# Log the branch name for debugging
echo "Detected source branch: $SOURCE_BRANCH"
- name: Setup Node.js
uses: actions/setup-node@v4
@@ -26,13 +75,12 @@ jobs:
- name: Tag Production Keys
run: |
BRANCH_NAME=${GITHUB_REF##*/}
npx tolgee tag \
--api-key ${{ secrets.TOLGEE_API_KEY }} \
--filter-extracted \
--filter-tag "draft:${BRANCH_NAME}" \
--filter-tag "draft:${SOURCE_BRANCH}" \
--tag production \
--untag "draft:${BRANCH_NAME}"
--untag "draft:${SOURCE_BRANCH}"
- name: Tag unused production keys as Deprecated
run: |
@@ -43,11 +91,10 @@ jobs:
- name: Tag unused draft:current-branch keys as Deprecated
run: |
BRANCH_NAME=${GITHUB_REF##*/}
npx tolgee tag \
--api-key ${{ secrets.TOLGEE_API_KEY }} \
--filter-not-extracted --filter-tag "draft:${BRANCH_NAME}" \
--tag deprecated --untag "draft:${BRANCH_NAME}"
--filter-not-extracted --filter-tag "draft:${SOURCE_BRANCH}" \
--tag deprecated --untag "draft:${SOURCE_BRANCH}"
- name: Sync with backup
run: |