|
| 1 | +name: Increment tag for patch or minor |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + types: |
| 8 | + - closed # Trigger only when a PR is closed (merged or not) |
| 9 | + |
| 10 | +jobs: |
| 11 | + tag: |
| 12 | + if: github.event.pull_request.merged == true |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout repository |
| 16 | + uses: actions/checkout@v3 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Create new tag |
| 21 | + env: |
| 22 | + TOKEN: ${{ secrets.TAG_CREATION_TOKEN_PUBLIC }} |
| 23 | + run: | |
| 24 | + echo $TOKEN | gh auth login --with-token |
| 25 | + latest_tag=$(git tag | sort -V | tail -n 1) |
| 26 | + echo "Latest tag: $latest_tag" |
| 27 | +
|
| 28 | + # Extract major and minor versions |
| 29 | + version=$(echo $latest_tag | cut -d. -f1-2) |
| 30 | + # Extract patch version |
| 31 | + patch=$(echo $latest_tag | cut -d. -f3) |
| 32 | + # Extract minor version |
| 33 | + minor=$(echo $latest_tag | cut -d. -f2) |
| 34 | + major=$(echo $latest_tag | cut -d. -f1) |
| 35 | +
|
| 36 | + # Check if the incoming branch starts with 'release-candidate-' |
| 37 | + incoming_branch="${{ github.head_ref }}" |
| 38 | + if [[ "$incoming_branch" == release-candidate-* ]]; then |
| 39 | + # Increment minor version and reset patch |
| 40 | + new_minor=$((minor+1)) |
| 41 | + new_tag="$major.$new_minor.0" |
| 42 | + echo "New tag will be (minor increment): $new_tag" |
| 43 | + else |
| 44 | + # Increment patch version |
| 45 | + new_tag="$version.$((patch+1))" |
| 46 | + echo "New tag will be (patch increment): $new_tag" |
| 47 | + fi |
| 48 | +
|
| 49 | + git config --global user.email "devops@devtron.ai" |
| 50 | + git config --global user.name "systemsdt" |
| 51 | + git tag $new_tag |
| 52 | + git push origin $new_tag |
0 commit comments