From 3b3624a9e2508e377dcacc0e74d6c194c251d8f8 Mon Sep 17 00:00:00 2001 From: Maurizio Turatti Date: Tue, 15 Oct 2024 16:30:53 +0200 Subject: [PATCH] Refactor GitHub Actions for branches --- .github/workflows/branch.yml | 73 +++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 27 deletions(-) diff --git a/.github/workflows/branch.yml b/.github/workflows/branch.yml index 3bc068f26..4596aa597 100644 --- a/.github/workflows/branch.yml +++ b/.github/workflows/branch.yml @@ -1,13 +1,11 @@ -# This workflow builds SNAPSHOT releases - name: Build snapshot release on: push: branches: - - "*" + - "*" # All branches for snapshot builds tags-ignore: - - "*" + - "*" # Ignore all tags jobs: build: @@ -15,11 +13,8 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - include: - - mongodb-version: "5.0" - - mongodb-version: "6.0" - - mongodb-version: "7.0" - deploy: true + mongodb-version: ["5.0", "6.0"] + deploy: [false] # Added here as part of strategy timeout-minutes: 20 steps: - uses: actions/checkout@v4 @@ -39,10 +34,8 @@ jobs: - name: Set VERSION and SHA id: vars run: | - echo "VERSION=$(echo ${GITHUB_REF:10})" >> $GITHUB_OUTPUT - echo "SHA=$(echo ${GITHUB_SHA:0:7})" >> $GITHUB_OUTPUT - echo "VERSION=${{steps.vars.outputs.VERSION}}" - echo "SHA=${{steps.vars.outputs.SHA}}" + echo "VERSION=$(echo ${GITHUB_REF:10})" >> $GITHUB_ENV + echo "SHA=$(echo ${GITHUB_SHA:0:7})" >> $GITHUB_ENV - name: Build and Test if: ${{ ! matrix.deploy }} @@ -50,8 +43,35 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any run: mvn -B clean verify -Dmongodb.version="${{ matrix.mongodb-version }}" + deploy: + needs: build + runs-on: ubuntu-22.04 + strategy: + matrix: + mongodb-version: ["7.0"] + deploy: [true] + steps: + - uses: actions/checkout@v4 + - uses: actions/cache@v4 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + distribution: "temurin" + java-version: "21" + + - name: Set VERSION and SHA + id: vars + run: | + echo "VERSION=$(echo ${GITHUB_REF:10})" >> $GITHUB_ENV + echo "SHA=$(echo ${GITHUB_SHA:0:7})" >> $GITHUB_ENV + - name: Import private gpg key - if: ${{ matrix.deploy }} run: | printf "%s" "$GPG_PRIVATE_KEY" > private.key gpg --pinentry-mode=loopback --batch --yes --fast-import private.key @@ -59,7 +79,6 @@ jobs: GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} - name: Deploy to Maven Central - if: ${{ matrix.deploy }} run: | MAVEN_OPTS="--add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.desktop/java.awt.font=ALL-UNNAMED" \ mvn -B deploy -Pdeploy -Dmongodb.version="${{ matrix.mongodb-version }}" -s settings.xml @@ -70,22 +89,18 @@ jobs: GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} - name: Set up QEMU - if: ${{ matrix.deploy }} uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx - if: ${{ matrix.deploy }} uses: docker/setup-buildx-action@v3 - name: Login to DockerHub - if: ${{ matrix.deploy }} uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USER }} password: ${{ secrets.DOCKER_TOKEN }} - name: Build and Push multi-arch Docker images - if: ${{ matrix.deploy }} uses: docker/build-push-action@v6 with: context: ./core/ @@ -96,11 +111,12 @@ jobs: linux/s390x push: true # push all images built pull: true # pull all required images before building - # NOTE: snapshot images must be tagged with "latest" in master branch only - tags: softinstigate/restheart-snapshot:${{steps.vars.outputs.SHA}} + # Tag with "latest" only if branch is master + tags: | + softinstigate/restheart-snapshot:${{ env.SHA }}, + ${{ github.ref == 'refs/heads/master' && 'softinstigate/restheart-snapshot:latest' || '' }} - name: Build and Push GraalVM Docker image - if: ${{ matrix.deploy }} uses: docker/build-push-action@v6 with: context: ./core/ @@ -110,11 +126,12 @@ jobs: linux/arm64 push: true # push all images built pull: true # pull all required images before building - # NOTE: snapshot images must be tagged with "graalvm" in master branch only - tags: softinstigate/restheart-snapshot:${{steps.vars.outputs.SHA}}-graalvm + # Tag with "graalvm" only if branch is master + tags: | + softinstigate/restheart-snapshot:${{ env.SHA }}-graalvm, + ${{ github.ref == 'refs/heads/master' && 'softinstigate/restheart-snapshot:latest-graalvm' || '' }} - name: Build and Push distroless docker image - if: ${{ matrix.deploy }} uses: docker/build-push-action@v6 with: context: ./core/ @@ -125,5 +142,7 @@ jobs: linux/ppc64le push: true # push all images built pull: true # pull all required images before building - # NOTE: snapshot images must be tagged with "distroless" in master branch only - tags: softinstigate/restheart-snapshot:${{steps.vars.outputs.SHA}}-distroless + # Tag with "distroless" only if branch is master + tags: | + softinstigate/restheart-snapshot:${{ env.SHA }}-distroless, + ${{ github.ref == 'refs/heads/master' && 'softinstigate/restheart-snapshot:latest-distroless' || '' }}