115 lines
3.0 KiB
YAML
115 lines
3.0 KiB
YAML
default:
|
|
image: maven:3-amazoncorretto-17-alpine
|
|
|
|
stages:
|
|
- build
|
|
- on_commit
|
|
- sonarcloud_scan
|
|
- deploy
|
|
- release
|
|
|
|
variables:
|
|
GITLAB_CLONE_DIR: "/builds/th-schwarz/CloudflareDNS-java"
|
|
GITLAB_USERNAME: $GITLAB_USERNAME
|
|
GITLAB_USEREMAIL: GITLAB_USEREMAIL
|
|
SONAR_HOST_URL: $SONAR_HOST_URL
|
|
SONAR_PROJECT_KEY: "thischwa_CloudflareDNS-java"
|
|
SONAR_ORGANIZATION: "thischwa"
|
|
SONAR_TOKEN: $SONAR_TOKEN
|
|
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
|
|
GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task
|
|
API_EMAIL: $API_EMAIL
|
|
API_KEY: $API_KEY
|
|
API_TOKEN: $API_TOKEN
|
|
|
|
build:
|
|
stage: build
|
|
script:
|
|
- echo "Running package..."
|
|
- cd ${GITLAB_CLONE_DIR}
|
|
- mvn clean package
|
|
- echo "Preparing GitLab Pages from docs/ (javadoc)"
|
|
- mkdir public
|
|
- cp -rv docs/* public/
|
|
- mkdir public/apidocs
|
|
- cp -rv target/apidocs public/
|
|
artifacts:
|
|
paths:
|
|
- target/surefire-reports/*.xml
|
|
- target/
|
|
- public/
|
|
except:
|
|
- tags
|
|
|
|
on_commits:
|
|
stage: on_commit
|
|
dependencies:
|
|
- build
|
|
script:
|
|
- echo "on_commit DONE"
|
|
only:
|
|
- /^feature.*$/
|
|
- merge_request
|
|
- develop
|
|
|
|
pages:
|
|
# triggers the page deployment of gitlab
|
|
stage: deploy
|
|
script:
|
|
- echo "Publishing to GitLab Pages ..."
|
|
artifacts:
|
|
paths:
|
|
- public
|
|
only:
|
|
- develop
|
|
- tags
|
|
|
|
sonarcloud_scan:
|
|
stage: sonarcloud_scan
|
|
dependencies:
|
|
- build
|
|
script:
|
|
- mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
|
|
only:
|
|
- merge_requests
|
|
- develop
|
|
|
|
perform_release:
|
|
stage: release
|
|
script: |
|
|
cd ${GITLAB_CLONE_DIR}
|
|
git config --global user.name "${GITLAB_USERNAME}"
|
|
git config --global user.email "${GITLAB_USEREMAIL}"
|
|
|
|
# config auth
|
|
git remote set-url origin "https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/${CI_PROJECT_PATH}.git"
|
|
|
|
# build versions
|
|
CURRENT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
|
|
RELEASE_VERSION=$(echo $CURRENT_VERSION | sed 's/-SNAPSHOT//')
|
|
MINOR_VERSION=$(echo $RELEASE_VERSION | awk -F. '{print $2}')
|
|
NEXT_MINOR_VERSION=$((MINOR_VERSION + 1))
|
|
NEXT_VERSION=$(echo $RELEASE_VERSION | awk -F. -v minor="$NEXT_MINOR_VERSION" '{print $1"."minor".0-SNAPSHOT"}')
|
|
|
|
echo "current version: $CURRENT_VERSION"
|
|
echo "release version: $RELEASE_VERSION"
|
|
echo "next version: $NEXT_VERSION"
|
|
|
|
# process maven release ...
|
|
mvn release:clean release:prepare release:perform \
|
|
-B \
|
|
-DreleaseVersion=$RELEASE_VERSION \
|
|
-DdevelopmentVersion=$NEXT_VERSION \
|
|
-Darguments="-DskipTests" \
|
|
-DscmCommentPrefix="[ci skip] " \
|
|
-DpreparationGoals="clean verify"
|
|
|
|
# generate release
|
|
curl --header "PRIVATE-TOKEN: ${GITLAB_API_TOKEN}" \
|
|
--data "name=v${RELEASE_VERSION}" \
|
|
--data "tag_name=v${RELEASE_VERSION}" \
|
|
--data "description=Release v${RELEASE_VERSION} of CloudflareDNS-java" \
|
|
"https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/releases"
|
|
|
|
only:
|
|
- /^pre-v\d+\.\d+\.\d+$/ |