From 49ba9641622b9b96f43fd5428160baaa3083c5c3 Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Sat, 15 May 2021 19:06:43 +0000 Subject: [PATCH] Configure alternatives to GitHub variables while in GitLab --- _includes/gh_variables.html | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/_includes/gh_variables.html b/_includes/gh_variables.html index 3fdae4ac..bf30548c 100644 --- a/_includes/gh_variables.html +++ b/_includes/gh_variables.html @@ -1,4 +1,11 @@ {% comment %} +This file was initially used to provide access to GitHub variables +available when rendering websites through GitHub Pages. +It has since then been expanded to also work with GitLab Pages, +although with some limitations due to platform differences. +Particularly, the variable "repo_info" is blank when rendering +through GitLab Pages. + When rendering websites locally, `site.github.url` doesn't get resolved properly unless a GitHub Personal Access Token is set up and available in the environment. This leads to warnings and errors when trying to serve the site @@ -7,7 +14,7 @@ GitHub where `site.github.url` is defined. {% endcomment %} -{% if jekyll.environment == "production" %} +{% if jekyll.environment == "production" and site.github %} {% comment %} First, get the name of the repository @@ -33,6 +40,22 @@ {% assign project_title = site.github.project_title %} {% assign source_branch = site.github.source.branch %} +{% elsif jekyll.environment == "production" and site.env.GITLAB_CI %} + +{% comment %} +This block applies when running in a GitLab CI environment +See https://docs.gitlab.com/ee/ci/variables/predefined_variables.html +for GitLab CI specific variables. +{% endcomment %} + +{% assign repo_name = site.env.CI_PROJECT_NAME %} +{% assign repo_info = "" %} +{% assign default_branch = site.env.CI_DEFAULT_BRANCH %} +{% assign repo_url = site.env.CI_REPOSITORY_URL %} +{% assign search_domain_url = site.env.CI_PAGES_URL %} +{% assign project_title = site.env.CI_PROJECT_TITLE %} +{% assign source_branch = site.env.CI_MERGE_REQUEST_SOURCE_BRANCH_NAME %} + {% elsif jekyll.environment == "development" %} {% assign repo_name = "" %}