Skip to content

Commit

Permalink
Refactor GitHub Actions for tags
Browse files Browse the repository at this point in the history
  • Loading branch information
mkjsix committed Oct 15, 2024
1 parent fc2d1e8 commit 78d761b
Showing 1 changed file with 36 additions and 27 deletions.
63 changes: 36 additions & 27 deletions .github/workflows/tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,17 @@ on:
branches:
- "!master" # Ignore the master branch
tags:
- "*"
- "*" # Trigger on any tag

jobs:
# Build and test the project
build:
if: "!contains(github.event.head_commit.message, 'skip ci')"
runs-on: ubuntu-22.04
strategy:
matrix:
include:
- mongodb-version: "5.0"
- mongodb-version: "6.0"
- mongodb-version: "7.0"
deploy: true
timeout-minutes: 20
mongodb-version: ["5.0", "6.0"]
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
Expand All @@ -36,21 +33,41 @@ jobs:
distribution: "temurin"
java-version: "21"

- name: Set the VERSION
id: vars
run: |
echo "VERSION=$(echo ${GITHUB_REF:10})" >> $GITHUB_OUTPUT
echo "VERSION=${{steps.vars.outputs.VERSION}}"
- name: Build and Test
if: ${{ ! matrix.deploy }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
run: |
mvn -B clean verify -Dmongodb.version="${{ matrix.mongodb-version }}"
# Deploy the project to Maven Central and DockerHub
deploy:
if: "!contains(github.event.head_commit.message, 'skip ci')"
runs-on: ubuntu-22.04
strategy:
matrix:
mongodb-version: ["7.0"]
timeout-minutes: 10
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
id: vars
run: |
echo "VERSION=$(echo ${GITHUB_REF:10})" >> $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
Expand All @@ -59,7 +76,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
Expand All @@ -70,22 +86,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/
Expand All @@ -100,10 +112,9 @@ jobs:
softinstigate/restheart:latest,
softinstigate/restheart:8,
softinstigate/restheart:8.1,
softinstigate/restheart:${{steps.vars.outputs.VERSION}}
softinstigate/restheart:${{ env.VERSION }}
- name: Build and Push GraalVM Docker image
if: ${{ matrix.deploy }}
uses: docker/build-push-action@v6
with:
context: ./core/
Expand All @@ -117,10 +128,9 @@ jobs:
softinstigate/restheart:latest-graalvm,
softinstigate/restheart:8-graalvm,
softinstigate/restheart:8.1-graalvm,
softinstigate/restheart:${{steps.vars.outputs.VERSION}}-graalvm
softinstigate/restheart:${{ env.VERSION }}-graalvm
- name: Build and Push distroless docker image
if: ${{ matrix.deploy }}
uses: docker/build-push-action@v6
with:
context: ./core/
Expand All @@ -135,16 +145,15 @@ jobs:
softinstigate/restheart:latest-distroless,
softinstigate/restheart:8-distroless,
softinstigate/restheart:8.1-distroless,
softinstigate/restheart:${{steps.vars.outputs.VERSION}}-distroless
softinstigate/restheart:${{ env.VERSION }}-distroless
- name: Upload GitHub release
if: ${{ matrix.deploy }}
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
body: |
# Release ${{steps.vars.outputs.VERSION}}
# Release ${{ env.VERSION }}
files: |
core/target/restheart.tar.gz
core/target/restheart.zip
Expand Down

0 comments on commit 78d761b

Please sign in to comment.