Skip to content

Commit 608b885

Browse files
committed
feat: filter branches for gitlab pages deployment
1 parent fefbc6f commit 608b885

File tree

1 file changed

+14
-5
lines changed
  • src/fair_python_cookiecutter/template/{{ cookiecutter.project_slug }}

1 file changed

+14
-5
lines changed

src/fair_python_cookiecutter/template/{{ cookiecutter.project_slug }}/.gitlab-ci.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,25 @@ pages:
122122
HTTPS_REMOTE: https://gitlab-ci-token:${PAGES_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git
123123
<<: *prepare-env
124124
script:
125-
- |
126-
if [[ -z "$PAGES_TOKEN" ]]; then
127-
echo "ERROR: CI variable PAGES_TOKEN is missing, cannot proceed!"
128-
exit 1
129-
fi
125+
# Preparation: we need to clone the repository in the job and directly access it via git
130126
- poetry install --with docs
131127
- git config user.name $GITLAB_USER_NAME
132128
- git config user.email $GITLAB_USER_EMAIL
133129
- git fetch origin $PAGES_BRANCH && git -b checkout $PAGES_BRANCH origin/$PAGES_BRANCH || git checkout $PAGES_BRANCH || echo "Pages branch not deployed yet."
134130
- git checkout $CI_COMMIT_SHA
131+
# If triggered by a push, check if the branch is enabled for pages
132+
- |
133+
if [[ -n "$CI_COMMIT_BRANCH" ]] && ! [[ "$CI_COMMIT_BRANCH" =~ ^(main|dev)$ ]]; then
134+
echo "INFO: Branch not enabled for pages, skipping docs deployment ('$PAGES_BRANCH' branch unchanged)."
135+
git checkout $PAGES_BRANCH -- public/
136+
exit 0
137+
fi
138+
# Deploy pages for a tag or enabled branch
139+
- |
140+
if [[ -z "$PAGES_TOKEN" ]]; then
141+
echo "ERROR: CI variable PAGES_TOKEN is missing, cannot proceed!"
142+
exit 1
143+
fi
135144
- DOCS_TAG_RAW=${CI_COMMIT_TAG:=$CI_COMMIT_BRANCH} # get tag (or if not present, current branch)
136145
- DOCS_TAG=${DOCS_TAG_RAW//\//_} # eliminate '/' symbols from branch (or tag) name
137146
- echo Deploying docs for "$DOCS_TAG"

0 commit comments

Comments
 (0)