Skip to content

Commit

Permalink
Add github workflow for CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
Malte-Hansen committed Jan 8, 2025
1 parent 5a5f18f commit 2551d38
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 50 deletions.
132 changes: 132 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: CI Pipeline

on:
push:
branches:
- main
pull_request:
branches:
- "**"

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: "graalvm"
java-version: "21"
- name: Cache Gradle Packages
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
- name: Build Project
run: ./gradlew assemble
env:
GRADLE_OPTS: "-Dorg.gradle.daemon=false"

pmd:
name: PMD Analysis
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: "graalvm"
java-version: "21"
- name: Cache Gradle Packages
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
- name: Run PMD Analysis
run: ./gradlew pmdMain

checkstyle:
name: Checkstyle Analysis
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: "graalvm"
java-version: "21"
- name: Cache Gradle Packages
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
- name: Run Checkstyle
run: ./gradlew checkstyleMain

unit-test:
name: Unit Tests
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: "graalvm"
java-version: "21"
- name: Cache Gradle Packages
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
- name: Run Unit Tests
run: ./gradlew test

tests-terminated:
name: test end node
runs-on: ubuntu-latest
needs: [build, pmd, checkstyle, unit-test]
steps:
- run: echo "finished test stage" # this is a indirection to the previous test steps

docker-image-native:
name: Docker image native
if: github.event_name == 'push' && github.ref_name == 'main'
needs: [tests-terminated]
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Build and Push Image
uses: explorviz/deployment/.github/actions/build-and-deploy-quarkus-native@main
with:
platforms: "linux/amd64,linux/arm64/v8"
docker-username: ${{ secrets.DOCKER_USERNAME }}
docker-password: ${{ secrets.DOCKER_PASSWORD }}
image-name: ${{ vars.DOCKER_NATIVE_IMAGE_NAME }}
image-tag: "latest"

docker-image-jvm:
name: Docker image JVM
if: github.event_name == 'push' && github.ref_name == 'main'
needs: [tests-terminated]
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Build and Push Image
uses: explorviz/deployment/.github/actions/build-and-deploy-quarkus-jvm@main
with:
platforms: "linux/amd64,linux/arm64/v8"
docker-username: ${{ secrets.DOCKER_USERNAME }}
docker-password: ${{ secrets.DOCKER_PASSWORD }}
image-name: ${{ vars.DOCKER_JVM_IMAGE_NAME }}
image-tag: "latest"
50 changes: 0 additions & 50 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ stages:
- coverage
- visualize
- deploy:images
- deploy:retagging

build:
stage: build
Expand Down Expand Up @@ -103,65 +102,16 @@ coverage:
coverage_format: cobertura
path: build/cobertura.xml

push-dockerhub-native-main-amd64:
extends: .build-and-deploy-quarkus-native
variables:
IMAGE_TAG: "amd64"

push-dockerhub-native-main-arm64:
extends: .build-and-deploy-quarkus-native
rules:
- if: $MULTI_ARCH_BUILD || $ARM64_BUILD
variables:
IMAGE_TAG: "arm64"
tags:
- arm64

push-dockerhub-native-mr:
extends: .build-and-deploy-quarkus-native
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
variables:
IMAGE_TAG: mr-${CI_MERGE_REQUEST_IID}-native

push-dockerhub-main-amd64:
extends: .build-and-deploy-quarkus-jvm
variables:
IMAGE_TAG: "amd64"

push-dockerhub-main-arm64:
extends: .build-and-deploy-quarkus-jvm
rules:
- if: $MULTI_ARCH_BUILD || $ARM64_BUILD
variables:
IMAGE_TAG: "arm64"
tags:
- arm64

push-dockerhub-mr:
extends: .build-and-deploy-quarkus-jvm
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
variables:
IMAGE_TAG: mr-${CI_MERGE_REQUEST_IID}-jvm

retag-amd64-as-latest-jvm:
extends: .retag-dockerhub-image
variables:
SOURCE_TAG: "amd64"
TARGET_TAG: "latest"

retag-amd64-as-latest-native:
extends: .retag-dockerhub-image
variables:
IMAGE_NAME: $DOCKERHUB_IMAGE_NAME_NATIVE
SOURCE_TAG: "amd64"
TARGET_TAG: "latest"

publish-multi-arch-manifest-jvm:
extends: .retag-as-multi-arch-dockerhub-image

publish-multi-arch-manifest-native:
extends: .retag-as-multi-arch-dockerhub-image
variables:
IMAGE_NAME: $DOCKERHUB_IMAGE_NAME_NATIVE

0 comments on commit 2551d38

Please sign in to comment.