diff --git a/.github/workflows/validate-branch.yml b/.github/workflows/validate-branch.yml new file mode 100644 index 0000000..4d1c8b6 --- /dev/null +++ b/.github/workflows/validate-branch.yml @@ -0,0 +1,41 @@ +name: Validate Branch Merge + +on: + pull_request: + 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 + 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!" \ 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