SIENTIAPDE-1327
SIENTIAPDE-1312: Enhance quality gate workflow to determine next version based on branch type - Added steps to fetch the branch name and calculate the next version based on the latest tag. - Implemented versioning logic to increment major, minor, or patch numbers depending on the branch type (release, feature, fix). - Updated SonarQube analysis step to use the dynamically calculated version.
This commit is contained in:
62
.github/workflows/quality-gate.yml
vendored
62
.github/workflows/quality-gate.yml
vendored
@@ -95,8 +95,70 @@ jobs:
|
||||
run: |
|
||||
pytest tests --junitxml=pytest.xml --cov=ingestor --cov-report=xml --cov-report=term
|
||||
|
||||
- name: Get branch name
|
||||
id: branch_name
|
||||
run: |
|
||||
# Obtém o nome da branch da PR
|
||||
BRANCH_NAME=${GITHUB_HEAD_REF}
|
||||
echo "Branch da PR: $BRANCH_NAME"
|
||||
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Determine next version
|
||||
id: next_version
|
||||
run: |
|
||||
BRANCH_NAME=${{ steps.branch_name.outputs.branch_name }}
|
||||
|
||||
# Baixa todas as tags
|
||||
git fetch --tags
|
||||
|
||||
# Pega a última tag sem filtro
|
||||
LAST_TAG=$(git tag --sort=-v:refname | head -n1)
|
||||
echo "Última tag encontrada: $LAST_TAG"
|
||||
|
||||
# Se não houver tags, assume 0.0.0
|
||||
if [ -z "$LAST_TAG" ]; then
|
||||
LAST_TAG="0.0.0"
|
||||
fi
|
||||
|
||||
# Extrai major, minor, patch
|
||||
IFS='.' read -r MAJOR MINOR PATCH <<< "$LAST_TAG"
|
||||
|
||||
echo "Versão atual: $MAJOR.$MINOR.$PATCH"
|
||||
|
||||
# Incrementa conforme tipo de branch
|
||||
if [[ "$BRANCH_NAME" == release/* ]]; then
|
||||
NEW_MAJOR=$((MAJOR + 1))
|
||||
NEW_MINOR=0
|
||||
NEW_PATCH=0
|
||||
elif [[ "$BRANCH_NAME" == feature/* ]]; then
|
||||
NEW_MAJOR=$MAJOR
|
||||
NEW_MINOR=$((MINOR + 1))
|
||||
NEW_PATCH=0
|
||||
elif [[ "$BRANCH_NAME" == fix/* ]]; then
|
||||
NEW_MAJOR=$MAJOR
|
||||
NEW_MINOR=$MINOR
|
||||
NEW_PATCH=$((PATCH + 1))
|
||||
elif [[ "$BRANCH_NAME" == "main" ]]; then
|
||||
NEW_MAJOR=$MAJOR
|
||||
NEW_MINOR=$MINOR
|
||||
NEW_PATCH=$PATCH
|
||||
else
|
||||
echo "Tipo de branch desconhecido. Abortando."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
NEXT_VERSION="${NEW_MAJOR}.${NEW_MINOR}.${NEW_PATCH}"
|
||||
VERSION=$NEXT_VERSION
|
||||
echo "Nova versão calculada: $NEXT_VERSION"
|
||||
|
||||
echo "version=$NEXT_VERSION" >> $GITHUB_OUTPUT
|
||||
|
||||
|
||||
- name: Run SonarQube Analysis
|
||||
uses: SonarSource/sonarqube-scan-action@v5
|
||||
with:
|
||||
args: >
|
||||
-Dsonar.projectVersion=$VERSION
|
||||
env:
|
||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
|
||||
|
||||
Reference in New Issue
Block a user