From bd6933754f4ffb20e71566bb9823661def5c02e7 Mon Sep 17 00:00:00 2001 From: Martin Kuba Date: Tue, 17 Jan 2023 16:10:57 +0100 Subject: [PATCH] added .gitlab-ci.yml --- .gitlab-ci.yml | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..df4fb27 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,57 @@ +# tags must be X.Y.Z ! +# +# following https://gitlab.com/gitlab-org/release-cli/-/tree/master/docs/examples/release-assets-as-generic-package/ +# and https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Maven.gitlab-ci.yml +stages: + - build + - upload + - release + +variables: + # variable read by Maven for JVM options, see https://maven.apache.org/configure.html#maven_opts-environment-variable + MAVEN_OPTS: " -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository " + # our own variable for repeated options + MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version " + # URL for uploading files + PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/chat/${CI_COMMIT_TAG}" + +build: + stage: build + image: maven:latest + rules: + - if: $CI_COMMIT_TAG + script: + - "mvn versions:set -DnewVersion=${CI_COMMIT_TAG}" + - "mvn versions:commit" + - 'mvn $MAVEN_CLI_OPTS install' + cache: + # caches maven repo between runs + paths: + - .m2/repository + artifacts: + # keeps produced files for the next job + paths: + - chat-server/target/chat_service.jar + - chat-client-java-lib/target/chat-client-java-lib.jar + +upload: + stage: upload + image: curlimages/curl:latest + rules: + - if: $CI_COMMIT_TAG + script: + - | + curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file chat-server/target/chat_service.jar ${PACKAGE_REGISTRY_URL}/chat_service.jar + - | + curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file chat-client-java-lib/target/chat-client-java-lib.jar ${PACKAGE_REGISTRY_URL}/chat-client-java-lib.jar + +release: + stage: release + image: registry.gitlab.com/gitlab-org/release-cli:latest + rules: + - if: $CI_COMMIT_TAG + script: + - | + release-cli create --name "Release $CI_COMMIT_TAG" --tag-name $CI_COMMIT_TAG \ + --assets-link "{\"name\":\"chat_service.jar\",\"url\":\"${PACKAGE_REGISTRY_URL}/chat_service.jar\"}" \ + --assets-link "{\"name\":\"chat-client-java-lib.jar\",\"url\":\"${PACKAGE_REGISTRY_URL}/chat-client-java-lib.jar\"}"