Skip to content

Refactor GitHub Actions for branches #821

Refactor GitHub Actions for branches

Refactor GitHub Actions for branches #821

Workflow file for this run

# This workflow builds SNAPSHOT releases
name: Build snapshot release
on:
push:
branches:
- "*"
tags-ignore:
- "*"
jobs:
# Job 1: Build job (runs by default for non-deployment)
build:
if: "!contains(github.event.head_commit.message, 'skip ci')"
runs-on: ubuntu-22.04
strategy:
matrix:
include:
- mongodb-version: ["5.0", "6.0"]
timeout-minutes: 20
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_OUTPUT
echo "SHA=$(echo ${GITHUB_SHA:0:7})" >> $GITHUB_OUTPUT
echo "VERSION=${{steps.vars.outputs.VERSION}}"
echo "SHA=${{steps.vars.outputs.SHA}}"
- name: Build and Test
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
run: mvn -B clean verify -Dmongodb.version="${{ matrix.mongodb-version }}"
# Job 2: Deploy job if mongodb-version is 7.0
deploy:
needs: build
runs-on: ubuntu-22.04
if: ${{ always() && matrix.mongodb-version == '7.0' }}

Check failure on line 54 in .github/workflows/branch.yml

View workflow run for this annotation

GitHub Actions / Build snapshot release

Invalid workflow file

The workflow is not valid. .github/workflows/branch.yml (Line: 54, Col: 9): Unrecognized named-value: 'matrix'. Located at position 13 within expression: always() && matrix.mongodb-version == '7.0'
strategy:
matrix:
include:
- mongodb-version: ["7.0"]
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 the VERSION
id: vars
run: |
echo "VERSION=$(echo ${GITHUB_REF:10})" >> $GITHUB_OUTPUT
- name: Import private gpg key
run: |
printf "%s" "$GPG_PRIVATE_KEY" > private.key
gpg --pinentry-mode=loopback --batch --yes --fast-import private.key
env:
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
- name: Deploy to Maven Central
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 clean deploy -Pdeploy -Dmongodb.version="${{ matrix.mongodb-version }}" -s settings.xml
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
GPG_KEY_NAME: ${{ secrets.GPG_KEY_NAME }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Build and Push multi-arch Docker images
uses: docker/build-push-action@v6
with:
context: ./core/
platforms: |
linux/amd64,
linux/arm64,
linux/ppc64le,
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}}
- name: Build and Push GraalVM Docker image
uses: docker/build-push-action@v6
with:
context: ./core/
file: ./core/Dockerfile.graalvm
platforms: |
linux/amd64,
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
- name: Build and Push distroless docker image
uses: docker/build-push-action@v6
with:
context: ./core/
file: ./core/Dockerfile.distroless
platforms: |
linux/amd64,
linux/arm64,
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