From 2061b8e7f547b8af80bffedc9e874912843403f9 Mon Sep 17 00:00:00 2001 From: Pedro Lucca Date: Thu, 30 Oct 2025 19:23:43 -0300 Subject: [PATCH 1/2] [Added] - workflow --- .github/workflows/validate-branch.yml | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/validate-branch.yml diff --git a/.github/workflows/validate-branch.yml b/.github/workflows/validate-branch.yml new file mode 100644 index 0000000..9326367 --- /dev/null +++ b/.github/workflows/validate-branch.yml @@ -0,0 +1,41 @@ +name: Validate Branch Merge + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + branches: + - main + - dev + - release/** + +jobs: + validate-branch: + runs-on: ubuntu-latest + steps: + - name: Check branch merge direction + run: | + echo "🔍 Validating merge direction..." + SOURCE_BRANCH="${{ github.head_ref }}" + TARGET_BRANCH="${{ github.base_ref }}" + + echo "Source: $SOURCE_BRANCH → Target: $TARGET_BRANCH" + + # Regra 1: feature/* só pode ir pra dev + if [[ "$SOURCE_BRANCH" == feature/* && "$TARGET_BRANCH" != "dev" ]]; then + echo "❌ Features só podem ser mergeadas em dev." + exit 1 + fi + + # Regra 2: dev só pode ir pra release/* + if [[ "$SOURCE_BRANCH" == "dev" && "$TARGET_BRANCH" != release/* ]]; then + echo "❌ Dev só pode ser mergeado em release/*." + exit 1 + fi + + # Regra 3: release/* só pode ir pra main + if [[ "$SOURCE_BRANCH" == release/* && "$TARGET_BRANCH" != "main" ]]; then + echo "❌ Release só pode ser mergeada em main." + exit 1 + fi + + echo "✅ Merge direction is valid!" From 9cb190cad1062b6a5696cffeb0a1c04c725d0a19 Mon Sep 17 00:00:00 2001 From: Pedro Lucca Date: Thu, 30 Oct 2025 19:50:58 -0300 Subject: [PATCH 2/2] [Added] - teste --- .github/workflows/validate-branch.yml | 6 ++-- .github/workflows/version-bump.yml | 40 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/version-bump.yml diff --git a/.github/workflows/validate-branch.yml b/.github/workflows/validate-branch.yml index 9326367..4d1c8b6 100644 --- a/.github/workflows/validate-branch.yml +++ b/.github/workflows/validate-branch.yml @@ -2,14 +2,15 @@ name: Validate Branch Merge on: pull_request: - types: [opened, synchronize, reopened, ready_for_review] branches: - main - dev - release/** + types: [opened, synchronize, reopened, ready_for_review] jobs: validate-branch: + name: Validate Branch Merge runs-on: ubuntu-latest steps: - name: Check branch merge direction @@ -17,7 +18,6 @@ jobs: echo "🔍 Validating merge direction..." SOURCE_BRANCH="${{ github.head_ref }}" TARGET_BRANCH="${{ github.base_ref }}" - echo "Source: $SOURCE_BRANCH → Target: $TARGET_BRANCH" # Regra 1: feature/* só pode ir pra dev @@ -38,4 +38,4 @@ jobs: exit 1 fi - echo "✅ Merge direction is valid!" + echo "✅ Merge direction is valid!" \ No newline at end of file diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml new file mode 100644 index 0000000..7fb76ad --- /dev/null +++ b/.github/workflows/version-bump.yml @@ -0,0 +1,40 @@ +name: Version Bump + +on: + pull_request: + types: [closed] + branches: + - main + +permissions: + contents: write + +jobs: + bump-version: + if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/') + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get latest tag + id: get_tag + run: | + LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") + echo "last_tag=$LAST_TAG" >> $GITHUB_OUTPUT + + - name: Calculate next version + id: bump + run: | + IFS='.' read -r major minor patch <<<"${{ steps.get_tag.outputs.last_tag#v }}" + patch=$((patch + 1)) + NEW_TAG="v${major}.${minor}.${patch}" + echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT + + - name: Create new tag + run: | + git tag ${{ steps.bump.outputs.new_tag }} + git push origin ${{ steps.bump.outputs.new_tag }} \ No newline at end of file