Dear Gitlab users, due to maintenance reasons, Gitlab will not be available on Thursday 30.09.2021 from 5:00 pm to approximately 5:30 pm.

Verified Commit b8456dfb authored by hynek's avatar hynek 🤤
Browse files

ci(gitlab): refactor ci pipelines

merge build with test; merge release with deploy; use semantic-release
parent 5fb13e40
# This GitLab runner configuration ensures every version of the SADE app is
# working properly before making it public.
#
# Final versions of SADE (i.e. develop or master branches) that have been built
# Release versions of SADE that have been built
# successfully are uploaded to DARIAH-DE's public eXist repository at
# https://ci.de.dariah.eu/exist-repo/index.html where other projects can reuse it.
#
# Please make sure you have all necessary passwords set as secret variables.
#
# In case you're using SADE for an non-DARIAH-DE project, 'upload' should be
# adapted or completely omitted.
#
# Environment variables used:
# * ${EXIST_UPLOAD_PW} - the password needed to push to DARIAH-DE's eXist repo
# * ${FILENAME} - the name if the XAR package created, e.g. SADE-develop-1-1-1.xar
# a general image that contains everything eXist-db needs to run properly
image: docker.gitlab.gwdg.de/fontane-notizbuecher/build:latest
---
# pipelines are only created on commits to open merge request branches and
# merges to the default branch
workflow:
rules:
- if: $CI_MERGE_REQUEST_IID
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
.npm-setup: &npm-setup
- curl -sL https://deb.nodesource.com/setup_14.x | bash -
- apt-get install -y nodejs
- npm ci --unsafe-perm --cache .npm --prefer-offline
stages:
- build
- test
- deploy
- release
# in the build stage eXist-db is (as the name implies) built considering all
# dependencies that are stated in build.properties and/or generic.xml.
# build-develop is triggered after pushing/merging into any branch except master
build-develop:
except:
- master
- tags
stage: build
script:
- ant test
artifacts:
paths:
- build/*.xar
- test/
default:
# a general image that contains everything eXist-db needs to run properly
image: docker.gitlab.gwdg.de/fontane-notizbuecher/build:latest
# build-master is only triggered after pushing/merging into master
build-master:
only:
- master
- tags
stage: build
script:
- cp master.build.properties local.build.properties
- ant test
artifacts:
paths:
- build/*.xar
- test/
# eXist-db is installed and all tests stated in post-install.xq are executed.
# ATTENTION: tests failing in post-install.xq will NOT cause the stage to fail!
installation:
except:
- tags
stage: test
script:
# build the xar-file and prepare a test environment
- ./build_test
- bash test/eXist-db-*/bin/startup.sh | tee output.log &
# wait for eXist to have started
- while [ $(curl --head --silent http://localhost:8080 | grep -c "200 OK") == 0 ]; do sleep 1s; done
......@@ -74,46 +53,12 @@ installation:
reports:
junit: test/tests-*.xml
# upload the EXPath package to the repo
upload:
only:
- master
- develop
except:
- tags
stage: deploy
semantic-release:
stage: release
before_script:
- *npm-setup
script:
- FILENAME=$(ls build/*.xar)
- curl -u ci:${EXIST_UPLOAD_PW} -X POST -F file=@${FILENAME} https://ci.de.dariah.eu/exist-upload
- npx semantic-release
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
# when a git flow release is made, a tag will be pushed starting this job. it
# will keep the resulting artifact from job number one and it will set up a
# Gitlab release at the repo. therefore the merge message starting at the release
# branch should be written in markdown.
release:
stage: deploy
only:
- tags
script:
# get number of first job in pipeline (assuming that this will create the needed artifact)
# it is also possible to query for a job name by altering the jq filter
- 'curl --output jobs.json --header "PRIVATE-TOKEN: $GITLAB_TOKEN" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/pipelines/$CI_PIPELINE_ID/jobs"'
- CI_JOB_TARGET=$(jq ".[0].id" < jobs.json)
- echo $CI_JOB_TARGET
# keep artifact (release will link there)
- 'curl --request POST --header "PRIVATE-TOKEN: $GITLAB_TOKEN" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/jobs/$CI_JOB_TARGET/artifacts/keep"'
# create release data
# parse commit message (markdown, lines starting with “\”)
- MARKDOWN=$(echo "$CI_COMMIT_MESSAGE" | sed 's=^\\==g')
# prepare the json file
- 'jq
".name = \"$CI_PROJECT_PATH $CI_COMMIT_TAG\" |
.tag_name = \"$CI_COMMIT_TAG\" |
.description = \"$MARKDOWN\" |
.assets.links[0].name = \"package\" |
.assets.links[0].url = \"https://gitlab.gwdg.de/$CI_PROJECT_PATH/-/jobs/$CI_JOB_TARGET/artifacts/download\"
" < gitlab-release.json.tmpl > gitlab-release.json'
- 'curl --header "Content-Type: application/json" --header "PRIVATE-TOKEN: $GITLAB_TOKEN" --data @gitlab-release.json --request POST $CI_API_V4_URL/projects/$CI_PROJECT_ID/releases'
artifacts:
paths:
- gitlab-release.json
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment