diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 90ce8787ea33a1e0ca4882044d9c56216a69c0ac..9b96d263b63983411e3e839699f35d51183feb30 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,4 @@ -include: - - project: 'VIPS/vips-common-config' - file: '/gitlab-ci-vips-libraries.yml' - ref: main +image: eclipse-temurin:17.0.9_9-jdk-jammy stages: - build @@ -17,6 +14,13 @@ stages: - models-8 variables: + COMMON_CONFIG_REMOTE: https://oauth2:$CICD_ACCESS_TOKEN@$CI_SERVER_HOST/VIPS/vips-common-config.git + COMMON_CONFIG_LOCAL: "vips-common-config" + SETTINGS_XML: "ci_settings.xml" + MAVEN_CLI_OPTS: "-s $SETTINGS_XML --batch-mode" + MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository -Dmaven.artifact.threads=10" + MAIN_BRANCH: "main" + RELEASE_BRANCH: "release" ALTERNARIA_PROJECT_ID: "173" APPLESCABM_PROJECT_ID: "20" BARLEYNETB_PROJECT_ID: "21" @@ -40,8 +44,102 @@ variables: SEPAPIICOL_PROJECT_ID: "39" SEPTORIAHU_PROJECT_ID: "65" SEPTREFHUM_PROJECT_ID: "135" +cache: + paths: + - .m2/repository/ -# Runs after new SNAPSHOT is deployed to package registry. Triggers job on main branch in model repo, +before_script: + - apt-get update && apt-get install -y git + - git config --global user.name "${GITLAB_USER_NAME}" + - git config --global user.email "${GITLAB_USER_EMAIL}" + - echo "Get common settings" + - git clone --depth=1 "$COMMON_CONFIG_REMOTE" "$COMMON_CONFIG_LOCAL" + - cp $COMMON_CONFIG_LOCAL/$SETTINGS_XML ./$SETTINGS_XML + - rm -rf $COMMON_CONFIG_LOCAL + +build: + stage: build + script: + - ./mvnw $MAVEN_CLI_OPTS $MAVEN_OPTS package + tags: + - java + +test: + stage: test + script: + - ./mvnw $MAVEN_CLI_OPTS $MAVEN_OPTS test + tags: + - java + +deploy-snapshot: + stage: deploy + script: + - export VERSION=$(./mvnw $MAVEN_CLI_OPTS $MAVEN_OPTS --batch-mode --no-transfer-progress --non-recursive help:evaluate -Dexpression=project.version | grep -v "\[.*") + - if ! [[ $VERSION =~ .*SNAPSHOT ]]; then + echo "Version '$VERSION' is not SNAPSHOT"; exit 1; + fi + - ./mvnw $MAVEN_CLI_OPTS $MAVEN_OPTS deploy -DskipTests + - echo "VERSION=$VERSION" >> build.env + artifacts: + reports: + dotenv: build.env + tags: + - java + rules: + - if: '$CI_COMMIT_REF_NAME == $MAIN_BRANCH' + +deploy-release: + stage: deploy + script: + # Use access token given by CI/CD variable CICD_ACCESS_TOKEN to authenticate + - export NEW_REPO_URL=https://oauth2:$CICD_ACCESS_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git + - git remote set-url --push origin $NEW_REPO_URL + - git fetch origin --prune --prune-tags + + # Checkout release branch + - git stash -a + - git checkout $RELEASE_BRANCH + - git reset --hard origin/$RELEASE_BRANCH + - git stash pop + + # Set release version and deploy. Commit, tag and push. + - ./mvnw $MAVEN_CLI_OPTS $MAVEN_OPTS validate -DremoveSnapshot + - export RELEASE_VERSION=$(./mvnw $MAVEN_CLI_OPTS $MAVEN_OPTS --batch-mode --no-transfer-progress --non-recursive help:evaluate -Dexpression=project.version | grep -v "\[.*") + - echo "VERSION=$RELEASE_VERSION" >> build.env + - export RELEASE_TAG="v${RELEASE_VERSION}" + - export EXISTING_TAGS=$(git ls-remote --tags origin | cut -f 2 | grep "refs/tags/$RELEASE_TAG$") + - if [ -n "$EXISTING_TAGS" ]; then + echo "Tag $RELEASE_TAG already exists"; exit 0; + fi + - ./mvnw $MAVEN_CLI_OPTS $MAVEN_OPTS deploy -DskipTests + - git add pom.xml + - git commit -m "[ci skip] Set release version ${RELEASE_VERSION}" + - git tag -a $RELEASE_TAG -m "Tag release ${RELEASE_TAG}" + - git push origin $RELEASE_TAG + - git push origin $RELEASE_BRANCH + + # Checkout main branch + - git stash -a + - git checkout $MAIN_BRANCH + - git reset --hard origin/$MAIN_BRANCH + - git stash pop + + # Merge release branch, bump patch version, push commits. + - git merge -m "[ci skip] Merge branch '${RELEASE_BRANCH}' into ${MAIN_BRANCH}" --no-ff $RELEASE_BRANCH + - ./mvnw $MAVEN_CLI_OPTS $MAVEN_OPTS validate -DbumpPatch + - export SNAPSHOT_VERSION=$(./mvnw $MAVEN_CLI_OPTS $MAVEN_OPTS --batch-mode --no-transfer-progress --non-recursive help:evaluate -Dexpression=project.version | grep -v "\[.*") + - git add pom.xml + - git commit -m "[ci skip] Set snapshot version ${SNAPSHOT_VERSION}" + - git push origin $MAIN_BRANCH + artifacts: + reports: + dotenv: build.env + tags: + - java + rules: + - if: '$CI_COMMIT_REF_NAME == $RELEASE_BRANCH' + +# Jobs below runs after new SNAPSHOT is deployed to package registry. Triggers job on main branch in model repo, # which builds model with the new version of VIPSCommon. This pipeline fails if model build fails. verify_model_ALTERNARIA: @@ -643,4 +741,4 @@ update_model_SEPTREFHUM: dependencies: - deploy-release rules: - - if: '$CI_COMMIT_REF_NAME == $RELEASE_BRANCH' \ No newline at end of file + - if: '$CI_COMMIT_REF_NAME == $RELEASE_BRANCH' diff --git a/pom.xml b/pom.xml index b31ac8c60d9590833e6fb1d36a43ad864aba0de4..0e4d8395689c51766eaa8ee34784eda27f40d9e7 100755 --- a/pom.xml +++ b/pom.xml @@ -5,11 +5,11 @@ <parent> <groupId>no.nibio.vips</groupId> <artifactId>vips-parent-pom</artifactId> - <version>1.1.0</version> + <version>1.1.3</version> </parent> <artifactId>VIPSCommon</artifactId> - <version>3.0.1</version> + <version>3.0.2-SNAPSHOT</version> <packaging>jar</packaging> <name>VIPSCommon</name>