release: Merge branch 'develop' of github.com:flexcodelabs/flextuma i… #94
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI/CD Pipeline | |
| on: | |
| pull_request: | |
| branches: ['main'] | |
| push: | |
| branches: [develop] | |
| tags-ignore: | |
| - 'v*' | |
| jobs: | |
| PR: | |
| if: | | |
| contains(github.event.head_commit.message, 'release') && github.event_name == 'push' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Create Pull Request | |
| uses: BaharaJr/create-pr@0.0.1 | |
| with: | |
| GITHUB_TOKEN: ${{secrets.TOKEN}} | |
| DESTINATION_BRANCH: main | |
| KEYWORD: release | |
| CHECK_MESSAGE: | |
| if: github.event_name == 'pull_request' | |
| name: COMMIT CHECK | |
| runs-on: ubuntu-latest | |
| outputs: | |
| sms: ${{ steps.sms_id.outputs.sms }} | |
| steps: | |
| - name: Checkout PR Head | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| - name: Get Commit Message | |
| id: sms_id | |
| run: echo "sms=$(git show -s --format=%s)" >> "$GITHUB_OUTPUT" | |
| DEPLOY: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| needs: CHECK_MESSAGE | |
| # Only run if the PR commit message contains 'release' | |
| if: ${{ contains(needs.CHECK_MESSAGE.outputs.sms, 'release') }} | |
| steps: | |
| - name: Checkout Source Branch | |
| uses: actions/checkout@v4 | |
| with: | |
| # Check out the actual branch (develop), not the merge commit | |
| ref: ${{ github.head_ref }} | |
| fetch-depth: 0 | |
| token: ${{ secrets.TOKEN }} | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| cache: gradle | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x gradlew | |
| - name: Automate Versioning | |
| id: versioning | |
| run: | | |
| GRADLE_FILE="build.gradle" | |
| # 1. Read current version | |
| CURRENT_VERSION=$(grep "version = " $GRADLE_FILE | sed -E "s/.*version = '([0-9]+\.[0-9]+\.[0-9]+)'.*/\1/") | |
| echo "Current Version: $CURRENT_VERSION" | |
| # 2. Parse and Increment | |
| IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION" | |
| MAJOR=${VERSION_PARTS[0]} | |
| MINOR=${VERSION_PARTS[1]} | |
| PATCH=${VERSION_PARTS[2]} | |
| PATCH=$((PATCH + 1)) | |
| if [ "$PATCH" -gt 99 ]; then | |
| PATCH=0 | |
| MINOR=$((MINOR + 1)) | |
| fi | |
| NEW_VERSION="$MAJOR.$MINOR.$PATCH" | |
| echo "New Version: $NEW_VERSION" | |
| echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| # 3. Update build.gradle | |
| sed -i "s/version = '$CURRENT_VERSION'/version = '$NEW_VERSION'/" $GRADLE_FILE | |
| # 4. Commit and Tag | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| git add $GRADLE_FILE | |
| git commit -m "Release v$NEW_VERSION [skip ci]" | |
| git tag "v$NEW_VERSION" | |
| # 5. Push changes back to the source branch (develop) | |
| # Use HEAD:${{ github.head_ref }} to ensure it pushes to the PR source branch | |
| git push origin HEAD:${{ github.head_ref }} | |
| git push origin "v$NEW_VERSION" | |
| - name: Build with Gradle | |
| run: ./gradlew clean bootWar -x test | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build and Push Docker Image | |
| env: | |
| VERSION: ${{ steps.versioning.outputs.version }} | |
| IMAGE_NAME: flexcodelabs/flextuma | |
| run: | | |
| echo "Building Docker image for version $VERSION..." | |
| docker build --target prod \ | |
| -t $IMAGE_NAME:$VERSION \ | |
| -t $IMAGE_NAME:latest \ | |
| . | |
| echo "Pushing images..." | |
| docker push $IMAGE_NAME:$VERSION | |
| docker push $IMAGE_NAME:latest | |
| - name: 🔀 | |
| uses: BaharaJr/merge-pr@0.0.1 | |
| with: | |
| GITHUB_TOKEN: ${{ secrets.TOKEN }} |