From c2df77e547404e48cc021a0f40119547ef08fdc0 Mon Sep 17 00:00:00 2001 From: Miguel Angel Reina Ortega <miguelangel.reinaortega@etsi.org> Date: Tue, 14 Feb 2023 12:43:57 +0100 Subject: [PATCH] Adding publication scripts --- .gitlab-ci.yml | 20 ++++++++++++++++++++ publish_spec.sh | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100755 publish_spec.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 43e6c1c..7794a27 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,11 +7,13 @@ workflow: rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" + - if: $CI_COMMIT_TAG variables: stages: - generation + - publication Word CR text: stage: generation @@ -35,3 +37,21 @@ Word CR text: paths: - docs/ expose_as: 'Word CR text' + +Publish spec: + stage: publication + only: + - tags + before_script: + - | + curl "${CI_API_V4_URL}/projects/$TOOLS_SCRIPTS_PROJECT_ID/repository/files/publish_spec%2Esh/raw?ref=publication" >> publish_spec.sh + - chmod +x publish_spec.sh + #- | + # curl "${CI_API_V4_URL}/projects/$TOOLS_SCRIPTS_PROJECT_ID/repository/files/onem2m_spec_template%2Edocx/raw?ref=master" >> onem2m_coversheet_template.docx + script: + - echo 'Publishing spec' + - ./publish_spec.sh ${CI_PROJECT_URL} ${CI_COMMIT_TAG} #onem2m_spec_template.docx + artifacts: + name: "${CI_PROJECT_NAME}_${CI_COMMIT_TAG}" + paths: + - "${CI_PROJECT_NAME}_${CI_COMMIT_TAG}.docx" \ No newline at end of file diff --git a/publish_spec.sh b/publish_spec.sh new file mode 100755 index 0000000..41cbbde --- /dev/null +++ b/publish_spec.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +DOCKER_IMAGE=pandoc/core:3.0 + +echo "\n------ Checking for docker image --------" +docker pull "$DOCKER_IMAGE" + +echo "------ Removing previous outputs --------" +rm **/*.docx + +echo "------ Parsing repo URL --------" + +HOST_URL=$(echo $1 | cut -d'/' -f 1-3) +PROJECT_NAME=$(echo $1 | cut -d'/' -f 5- | cut -d'.' -f 1) +echo "HOST URL:" $HOST_URL +echo "PROJECT NAME:" $PROJECT_NAME +echo "TAG NAME:" $2 + +echo "------ Getting .md file(s) ------" +# If there are no .md files, then simply exit +ls | grep -q 'md' +specs=$? +if [ ! $specs ] ; then + echo "-- No Markdown files." + exit 0 +fi + +for i in *.md ; do + echo "\n------ Publishing spec --------" + docker run --rm -v $(pwd):/data -u $(id -u):$(id -g) "$DOCKER_IMAGE" "/data/$i" -f markdown -t docx --reference-doc "Spec-template.docx" -o "${PROJECT_NAME}_${2}.docx" +done + +echo "\n------ Publishing spec --------" + +exit 0 \ No newline at end of file -- GitLab