Skip to content

Commit

Permalink
feat: better support for GitLab CI
Browse files Browse the repository at this point in the history
  • Loading branch information
WoozyMasta committed Dec 19, 2021
1 parent 3edb237 commit 3499320
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,29 +194,27 @@ pages:
- /opt/Archi/entrypoint.sh
variables:
ARCHI_PROJECT_PATH: "$CI_PROJECT_DIR"
ARCHI_REPORT_PATH: "$CI_PROJECT_DIR/public"
ARCHI_HTML_REPORT_ENABLED: "true"
ARCHI_HTML_REPORT_PATH: "$CI_PROJECT_DIR/public"
ARCHI_JASPER_REPORT_ENABLED: "false"
ARCHI_JASPER_REPORT_ENABLED: "true"
ARCHI_JASPER_REPORT_FORMATS: "PDF,DOCX"
ARCHI_JASPER_REPORT_TITLE: "false"
ARCHI_CSV_REPORT_ENABLED: "false"
ARCHI_EXPORT_MODEL_ENABLED: "true"
rules:
# Run only if roles exist or changed
- if: $CI_COMMIT_BRANCH != null || $CI_PIPELINE_SOURCE == "merge_request_event"
exists:
- model/folder.xml
artifacts:
name: "$CI_JOB_NAME from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
expire_in: never
expire_in: 30d
paths:
- public
```

In GitLab CI if `ARCHI_PROJECT_PATH` is undefined is set to `$CI_PROJECT_DIR`
and all report paths are automatically set to `$CI_PROJECT_DIR/public`

## Build Container

```bash
Expand Down
29 changes: 28 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euo pipefail
# ----

# Script environments
: "${ARCHI_PROJECT_PATH:=${GITHUB_WORKSPACE:-/archi/project}}"
: "${ARCHI_PROJECT_PATH:=${GITHUB_WORKSPACE:-${CI_PROJECT_DIR:-/archi/project}}}"
: "${ARCHI_REPORT_PATH:=/archi/report}"
: "${ARCHI_HTML_REPORT_ENABLED:=true}"
: "${ARCHI_JASPER_REPORT_ENABLED:=false}"
Expand Down Expand Up @@ -126,6 +126,15 @@ update_html() {
# Git clone wrap
git_clone() { git clone "${1:?Repo url not set}" "$ARCHI_PROJECT_PATH"; }

# GitLab log separator
section_start () {
printf '\e[0Ksection_start:%s:%s[collapsed=true]\r\e[0K\e[1;36m%s\e[0m\n' \
"$(date +%s)" "$1" "${*:2}"
}
section_end () {
printf '\e[0Ksection_end:%s:%s\r\e[0K\n' "$(date +%s)" "$*"
}

# Fail message to stder and exit 1
fail() { printf >&2 '%s\n' "$*"; exit 1; }

Expand Down Expand Up @@ -207,6 +216,24 @@ if [ "${GITHUB_ACTIONS:-}" == true ]; then

fi

# Run in GitLab CI
if [ "${GITLAB_CI:-}" == true ]; then
echo "Run Archi report generation in GitLab CI"
section_start 'archi_report' 'Render ArchiMate report'

# Set actions specified paths
ARCHI_REPORT_PATH="$CI_PROJECT_DIR/public"
ARCHI_HTML_REPORT_PATH="$CI_PROJECT_DIR/public"
ARCHI_CSV_REPORT_PATH="$CI_PROJECT_DIR/public"
ARCHI_JASPER_REPORT_PATH="$CI_PROJECT_DIR/public"
ARCHI_EXPORT_MODEL_PATH="$CI_PROJECT_DIR/public"
cd "$ARCHI_PROJECT_PATH" && mkdir -p "$ARCHI_REPORT_PATH"

# Create report
archi_run
section_end 'Render ArchiMate report complete'
exit 0
fi

# Check and use exist or mounted model
if [ -f "$ARCHI_PROJECT_PATH/model/folder.xml" ]; then
Expand Down

0 comments on commit 3499320

Please sign in to comment.