From ce94b21b0382738c798c41eaf522c1dc19756bfc Mon Sep 17 00:00:00 2001 From: carbotaniuman Date: Sat, 2 Oct 2021 03:54:09 +0000 Subject: [PATCH] Update CI --- .gitlab-ci.yml | 74 +++++++++++++++++++++++++++++++++++++++----------- build.gradle | 14 ++++++---- 2 files changed, 67 insertions(+), 21 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0c3765e..edf99a6 100755 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,14 +1,19 @@ stages: - build - publish - - publish_docker + - docker + - push -build: +Gradle Build: image: openjdk:8 stage: build + only: + - branches + - tags + - merge_requests before_script: - - export VERSION="$CI_COMMIT_REF_NAME" + - export VERSION="${CI_COMMIT_TAG:-$CI_COMMIT_SHORT_SHA}" script: - ./gradlew build artifacts: @@ -16,18 +21,20 @@ build: paths: - "build/libs/mangadex_at_home-*-all.jar" -publish: +Publish Artifacts: image: alpine stage: publish + needs: + - Gradle Build + variables: + GIT_STRATEGY: none before_script: - apk update && apk add zip - - export VERSION="$CI_COMMIT_REF_NAME" + - export VERSION="${CI_COMMIT_TAG:-$CI_COMMIT_SHORT_SHA}" script: - cp build/libs/mangadex_at_home-${VERSION}-all.jar ./ - zip -r9 mangadex_at_home-${VERSION}.zip mangadex_at_home-${VERSION}-all.jar settings.sample.yaml - dependencies: - - build artifacts: name: "mangadex_at_home" paths: @@ -35,20 +42,55 @@ publish: - "mangadex_at_home-*.zip" - "settings.sample.yaml" -publish_docker: +Docker Build: image: docker:20.10.8 services: - docker:20.10.8-dind - stage: publish - only: - - tags + stage: docker + needs: + - Gradle Build before_script: - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin ${CI_REGISTRY} - - export VERSION="$CI_COMMIT_REF_NAME" - dependencies: - - build + - export VERSION="${CI_COMMIT_TAG:-$CI_COMMIT_SHORT_SHA}" + - export BASE_TAG="$CI_COMMIT_SHORT_SHA" + script: - mv build/libs/mangadex_at_home-${VERSION}-all.jar build/libs/mangadex_at_home.jar - - docker build . -t ${CI_REGISTRY_IMAGE}:${VERSION} - - docker push ${CI_REGISTRY_IMAGE}:${VERSION} + - docker build . -t $CI_REGISTRY_IMAGE:$BASE_TAG + - docker push $CI_REGISTRY_IMAGE:$BASE_TAG + +.docker_push: &docker_push + image: docker:20.10.8 + services: + - docker:20.10.8-dind + stage: push + variables: + GIT_STRATEGY: none + + before_script: + - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin ${CI_REGISTRY} + - export BASE_TAG="$CI_COMMIT_SHORT_SHA" + + script: + - docker pull $CI_REGISTRY_IMAGE:$BASE_TAG + - docker tag $CI_REGISTRY_IMAGE:$BASE_TAG $CI_REGISTRY_IMAGE:$NEW_TAG + - docker push $CI_REGISTRY_IMAGE:$NEW_TAG + +Push Latest: + <<: *docker_push + needs: + - Docker Build + only: + - master + variables: + NEW_TAG: latest + +Push Tags: + <<: *docker_push + needs: + - Docker Build + only: + - tags + variables: + NEW_TAG: $CI_COMMIT_TAG \ No newline at end of file diff --git a/build.gradle b/build.gradle index 7ea9d2c..448033e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,17 +1,21 @@ plugins { id "jacoco" id "java" - id "org.jetbrains.kotlin.jvm" version "1.5.21" - id "org.jetbrains.kotlin.kapt" version "1.5.21" + id "org.jetbrains.kotlin.jvm" version "1.5.31" + id "org.jetbrains.kotlin.kapt" version "1.5.31" id "application" - id "com.github.johnrengelman.shadow" version "5.2.0" + id "com.github.johnrengelman.shadow" version "7.0.0" id "com.diffplug.spotless" version "5.8.2" id "net.afanasev.sekret" version "0.1.0" + id "com.palantir.git-version" version "0.12.3" } group = "com.mangadex" -version = System.getenv().getOrDefault("VERSION", 'git describe --tags --dirty'.execute().text.trim()) -mainClassName = "mdnet.MainKt" +version = System.getenv("VERSION") ?: gitVersion() + +application { + mainClass = "mdnet.MainKt" +} repositories { mavenCentral()