Skip to content
Snippets Groups Projects
Commit b52168fa authored by Miguel Angel Reina Ortega's avatar Miguel Angel Reina Ortega
Browse files

Adding script to handle deployment of spec in gitlab pages

parent f02b6f04
No related branches found
No related tags found
No related merge requests found
......@@ -136,6 +136,7 @@ pages:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
PAGES_BRANCH: gl-pages
HTTPS_REMOTE: https://gitlab-ci-token:${MIKE_ACCESS_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git
TAG_NAME: ""
rules:
- if: ($CLEAN_WEB_PAGES == 'false' || $CLEAN_WEB_PAGES == 'true') && $CI_COMMIT_TAG
......@@ -149,7 +150,7 @@ pages:
TAG_NAME: "upgrade"
before_script:
- pip install -q mkdocs-material mike rich mkdocs-rss-plugin
# - pip install -q mkdocs-material mike rich mkdocs-rss-plugin
- apt-get update -qq && apt-get -qq install -y git curl > /dev/null
- |
curl "${CI_API_V4_URL}/projects/$TOOLS_SCRIPTS_PROJECT_ID/repository/files/toMkdocs%2Fimages%2Ffavicon%2Eico/raw?ref=toMkdocs" >> favicon.html
......@@ -172,16 +173,20 @@ pages:
curl "${CI_API_V4_URL}/projects/$TOOLS_SCRIPTS_PROJECT_ID/repository/files/toMkdocs%2FtoMkdocs%2Epy/raw?ref=toMkdocs" >> toMkdocs.py
- |
export SPEC_NAME=$(ls | grep T*.md | cut -d'.' -f1)
- echo $GITLAB_USER_NAME
- echo $GITLAB_USER_EMAIL
- git config --global --replace-all user.name "$GITLAB_USER_NAME"
- git config --global --replace-all user.email $GITLAB_USER_EMAIL
- git fetch origin $PAGES_BRANCH && git checkout $PAGES_BRANCH || git checkout -b $PAGES_BRANCH origin/$PAGES_BRANCH || echo "Pages branch not deployed yet."
- git checkout $CI_COMMIT_SHA
- |
curl "${CI_API_V4_URL}/projects/$TOOLS_SCRIPTS_PROJECT_ID/repository/files/spec_on_pages%2Esh/raw?ref=toMkdocs" >> spec_on_pages.sh
- chmod +x spec_on_pages.sh
- echo "'$TAG_NAME'"
# - echo $GITLAB_USER_NAME
# - echo $GITLAB_USER_EMAIL
# - git config --global --replace-all user.name "$GITLAB_USER_NAME"
# - git config --global --replace-all user.email $GITLAB_USER_EMAIL
# - git fetch origin $PAGES_BRANCH && git checkout $PAGES_BRANCH || git checkout -b $PAGES_BRANCH origin/$PAGES_BRANCH || echo "Pages branch not deployed yet."
# - git checkout $CI_COMMIT_SHA
script:
- python3 toMkdocs.py --title ${CI_PROJECT_NAME^^} "./$SPEC_NAME.md"
- mv ${CI_PROJECT_NAME^^}/ docs/
- cat _nav.yml >> mkdocs.yml
# - python3 toMkdocs.py --title ${CI_PROJECT_NAME^^} "./$SPEC_NAME.md"
# - mv ${CI_PROJECT_NAME^^}/ docs/
# - cat _nav.yml >> mkdocs.yml
# - |
# if [ -n "$TAG_NAME" ]; then
# mike deploy --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH -u $TAG_NAME latest
......@@ -189,16 +194,17 @@ pages:
# elif [ "$CI_COMMIT_REF_NAME" == "develop" ]; then
# mike deploy --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH -u $CI_COMMIT_BRANCH
# fi
- mike deploy --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH -u $TAG_NAME latest
- mike set-default --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH latest
- git checkout $PAGES_BRANCH -- public/
# - mike deploy --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH -u $TAG_NAME latest
# - mike set-default --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH latest
# - git checkout $PAGES_BRANCH -- public/
- ./spec_on_pages.sh toMkdocs.py $MIKE_ACCESS_TOKEN $CI_SERVER_HOST $CI_PROJECT_PATH "$GITLAB_USER_NAME" $GITLAB_USER_EMAIL $CI_COMMIT_SHA $SPEC_NAME $CI_PROJECT_NAME $TAG_NAME
artifacts:
paths:
- public/
rules:
- if: '$CI_PIPELINE_SOURCE == "web"'
when: always
- if: '$CI_COMMIT_TAG'
- if: '$CI_COMMIT_REF_NAME == "develop"'
when: always
- when: never
# rules:
# - if: '$CI_PIPELINE_SOURCE == "web"'
# when: always
# - if: '$CI_COMMIT_TAG'
# - if: '$CI_COMMIT_REF_NAME == "develop"'
# when: always
# - when: never
#!/bin/bash
#Parameters
#toMkdocs.py -> 1
echo "toMkdocs.py:" $1
#$MIKE_ACCESS_TOKEN -> 2
echo "MIKE_ACCESS_TOKEN:" $2
#CI_SERVER_HOST -> 3
echo "CI_SERVER_HOST:" $3
#CI_PROJECT_PATH -> 4
echo "CI_PROJECT_PATH:" $4
#GITLAB_USER_NAME -> 5
echo "GITLAB_USER_NAME:" $5
#GITLAB_USER_EMAIL -> 6
echo "GITLAB_USER_EMAIL:" $6
#CI_COMMIT_SHA -> 7
echo "CI_COMMIT_SHA:" $7
#$SPEC_NAME -> 8
echo "SPEC_NAME:" $8
#$CI_PROJECT_NAME -> 9
echo "CI_PROJECT_NAME:" $9
#$TAG_NAME ->10
echo "TAG_NAME:" ${10}
#BACKUP=false
PAGES_BRANCH=gl-pages
HTTPS_REMOTE=https://gitlab-ci-token:${2}@${3}/${4}.git
echo "\n------ Install necessary packages --------"
pip install -q mkdocs-material mike rich mkdocs-rss-plugin
#apt-get update -qq && apt-get -qq install -y git curl > /dev/null
echo "------ Get the previous GitLab Pages content --------"
git config --global --replace-all user.name "$5"
git config --global --replace-all user.email $6
git fetch origin $PAGES_BRANCH && git checkout $PAGES_BRANCH || git checkout -b $PAGES_BRANCH origin/$PAGES_BRANCH || echo "Pages branch not deployed yet."
git checkout $7
echo "------ Process published baselines --------"
# Move all folders except the "baselines" folder if baselines folder exists
# if [ -d "public/baselines" ]; then
# echo "Baselines already moved to baselines/";
# else
# mkdir -p "public/baselines"
# for folder in public/*; do
# if [ -d "$folder" ] && [ "$(basename "$folder")" != "baselines" ]; then
# mv "$folder" "public/baselines/"
# echo "Moved $(basename "$folder") to public/baselines"
# fi
# done
# # Move index.html with new location
# mv "public/index.html" "public/baselines/"
#
# fi
# echo "------ Add/update content --------"
# if [ $4 == 'upgrade' ]; then
# echo 'Upgrading index.html...'
# docker run --rm -v $(pwd):/tmp -w /tmp "$DOCKER_IMAGE" python3 $1 -u "$7_$4" "$4/$7_$4.docx" "$5"
# elif [ $6 == 'true' ]; then
# echo 'Removing all baselines ...'
# rm -r public/baselines/*;
# mkdir -p "public/baselines/$4"
# ls public/
# cp -r -f "$7_$4.docx" public/baselines/$4
# docker run --rm -v $(pwd):/tmp -w /tmp "$DOCKER_IMAGE" python3 $1 "$7_$4" "$4/$7_$4.docx" "$5"
# elif [ $6 == 'false' ]; then
# mkdir -p "public/baselines/$4"
# ls public/
# cp -r -f "$7_$4.docx" public/baselines/$4
# docker run --rm -v $(pwd):/tmp -w /tmp "$DOCKER_IMAGE" python3 $1 "$7_$4" "$4/$7_$4.docx" "$5"
# else
# echo 'Removing entry for ' $6
# rm -r -f public/baselines/$6
# docker run --rm -v $(pwd):/tmp -w /tmp "$DOCKER_IMAGE" python3 $1 -re "$7_$4" "$4/$7_$4.docx" "$5"
# fi
####### GENERATE NAV SPEC #######
echo "------ Generate input for mkdocs --------"
python3 $1 --title ${9^^} "./$8.md"
echo "------ Move to docs folder --------"
mv ${9^^}/ docs/
cat _nav.yml >> mkdocs.yml
echo "------ Generating site --------"
mike list
mike delete latest --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH
mike deploy --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH -u ${10} latest
mike set-default --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH latest
git checkout $PAGES_BRANCH -- public/
exit 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment