Enable GitLab pages to provide documentation for multiple versions
Project description
Lightweight versioned GitLab Pages
Generate index page with links to all previously archived folders during a tag build.
This repo developed in and mirrored from GitLab brainelectronics. Please raise your issues and submit your pull requests/merge requests there.
Installation
pip install lightweight-versioned-gitlab-pages
Documentation
📚 The latest documentation is available at
Reasoning
GitLab offers the possibility to create or place a folder named public
in the
root of the repo. The contents of this folder are then displayed by
GitLab pages and is
accessible from outside the repo via a custom URL.
For this package, the URL is
https://brainelectronics.gitlab.io/-/lightweight-versioned-gitlab-pages
.
This is also the location of the (latest) documentation for this package.
Since only only one "thing" can be displayed there, usually only the most
recent content is available at this URL. This is where this package is supposed to help.
Usage
It is assumed that only tagged states of the documentation or other content will be displayed on the GitLab Pages web page, see also chapter Limitations.
The script will use an API token to make all requests through the
python-gitlab
package.
This token must be specified via the --private-token
argument. The token can
be generated via Settings -> Access Tokens
and requires api
scope.
In addition, the unique project ID must be specified with --project-id
.
This ID can be found at the top of each repo. For this repository it is
43170198
.
The last mandatory parameter is --job-name
. This is the name of the job
that generates, for example, the documentation or other content that will be
displayed via the GitLab pages web page.
The generated index.html
is placed in a folder named public
. By default
this folder is created in the same directory from which this script is called.
A different destination folder can be specified with --output-dir
. The folder
does not have to exist, it and its possibly needed parent directories will be
created if necessary.
If a self-hosted GitLab is used, the URL to the instance can be specified with
--url
to not restrict this package to GitLab.com only.
Help
generate-versioned-pages --help
Generate lightweight versioned pages
The following command will create a folder named public
at the current
location and place an index HTML file inside.
This index file contains a simple list of Bootstrap cards with all previously built tags and the URL to the public pages archive files.
generate-versioned-pages \
--private_token asdf-carlTheLamaIsHere \
--project-id 43170198 \
--job-name pages
Then use this generated folder in the pages
job. The job configuration in the
file .gitlab-ci.yml
can look like the following example and is used in that
way for this package.
pages:
stage: deploy
before_script:
- pip install lightweight-versioned-gitlab-pages
script:
- generate-versioned-pages
--private_token ${GITLAB_API_TOKEN}
--project-id ${CI_PROJECT_ID}
--job-name generate-docs
artifacts:
expire_in: never
paths:
- public
only:
- main
How it works
First, the available tags of the repo are requested/gathered by the
get_project_tags
function. For each tag, the corresponding pipeline job is requested based on
the provided job-name
argument. The job status must be successful to avoid
erroneous or currently generated artifacts. For each job, the URL to the index
file of the public
folder is generated, see
get_artifact_url
The generated list of
TagInfos will then be
used to create a simple index.html
file inside a generated public
folder,
unless it is to be generated elsewhere.
The template is rendered with Jinja2.
Limitations
- Only links to tagged and archived data of
public
folders are included in the index - Job artifacts must be publicly accessible
- Make sure that
CI/CD
is activated and set toEveryone With Access
atSettings -> General -> Visibility
- Make sure that
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file lightweight-versioned-gitlab-pages-0.2.1.tar.gz
.
File metadata
- Download URL: lightweight-versioned-gitlab-pages-0.2.1.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bdbd1b7fdcdd533295c7977e2cc40f60261478bfd67218c49e2d13bbd351c14 |
|
MD5 | 556433333f5b7b8435d55d683ae15be0 |
|
BLAKE2b-256 | 04ac608b7192ea711c5a8f580fde8bd4a38a509892f93dda70be426690b7ff10 |
File details
Details for the file lightweight_versioned_gitlab_pages-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: lightweight_versioned_gitlab_pages-0.2.1-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7a5fcd3a89aaa8434a466bc18a3c8dd11ae3225603439dabfd4035a61a48a6c |
|
MD5 | 24b9aefa9694ee8e62c8a509d14b9c4b |
|
BLAKE2b-256 | 495cf69b0bb399cb76425a1f9001a21590ccb13245dc3f0aba1a3eb63425d97a |