Merge pull request #12 from devgateway/task/DVIZ-24/admin-docker-opti… #7
Workflow file for this run
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: Build and Release | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| - release/* | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| packages: write | |
| jobs: | |
| release-and-tag: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.release.outputs.version }} | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: '0' | |
| - name: Set up JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '21' | |
| distribution: 'corretto' | |
| cache: 'maven' | |
| - name: Cache Maven packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.m2/repository | |
| !~/.m2/repository/org/devgateway/tcdi | |
| key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-maven- | |
| - name: Configure Git user | |
| run: | | |
| git config user.email "[email protected]" | |
| git config user.name "Timothy Mugo Gachengo" | |
| - name: Prepare Release | |
| id: release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| # Get current version from pom.xml | |
| CURRENT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) | |
| echo "Current version: $CURRENT_VERSION" | |
| # Remove -SNAPSHOT and calculate next version | |
| VERSION=${CURRENT_VERSION%-SNAPSHOT} | |
| IFS='.' read -r major minor patch <<< "$VERSION" | |
| NEXT_VERSION="$major.$minor.$((patch + 1))-SNAPSHOT" | |
| # Perform release | |
| mvn -B release:prepare release:perform \ | |
| -DreleaseVersion=$VERSION \ | |
| -DdevelopmentVersion=$NEXT_VERSION \ | |
| -DtagNameFormat=v@{project.version} \ | |
| -DpushChanges=true \ | |
| -DlocalCheckout=true \ | |
| -DpreparationGoals="clean verify -Dcheckstyle.skip -DskipTests" \ | |
| -DcompletionGoals="verify -Dcheckstyle.skip -DskipTests" \ | |
| -Darguments="-DskipTests -Dcheckstyle.skip" | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Released version $VERSION" | |
| build-and-push-docker-image: | |
| needs: release-and-tag | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| with: | |
| platforms: linux/amd64,linux/arm64 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Login to Docker Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ vars.DOCKER_REGISTRY }} | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| platforms: linux/amd64,linux/arm64 | |
| cache-from: type=gha, scope=data-viz-admin | |
| cache-to: type=gha, scope=data-viz-admin | |
| context: . | |
| push: true | |
| build-args: | | |
| VERSION=${{ needs.release-and-tag.outputs.version }} | |
| TAG=${{ needs.release-and-tag.outputs.version }} | |
| tags: | | |
| ${{ vars.DOCKER_REGISTRY }}/data-viz-admin:latest | |
| ${{ vars.DOCKER_REGISTRY }}/data-viz-admin:v${{ needs.release-and-tag.outputs.version }} |