Skip to main content

Lightweight Versioned GitLab Pages

Downloads pipeline status Documentation Status codecov PyPI - Python Version License: MIT

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.

For interaction with GitLab the python-gitlab package is used.

A 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 second 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.

In case the CICD artifacts are not publicly available, the script requires an API token to make all requests through the API. This token must then be specified via the --private-token argument. The token can be generated via Settings -> Access Tokens and requires api scope.

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 \
--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
      --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.

Advanced Usage

Custom index file

To allow users the usage of a different style index file, the --template-file is there to help.

By default the index template file delivered with this package is used for rendering. A list of TagInfos and the base URL of tags (tag_base_url) is handed over to the Jinj2 render function.

The following informations are availabe for individual usage:

Name Type Description
tag_base_url str URL to the project tags, e.g. https://gitlab.com/brainelectronics/lightweight-versioned-gitlab-pages/-/tags/
items List[TagInfos] List of TagInfo elements

Each TagInfo element contains the following fields

Name Type Description
tag ProjectTag GitLab ProjectTag
commit ProjectCommit GitLab ProjectCommit
created_at datetime Datetime object with the datetime of the tag creation
job_id int ID of the Job created the tag
pages_url str Full URL to the generated public index file of the job
job_ids List[Dict[str, int]] List of pipeline IDs which ran during the job

Custom output directory

Save the rendered index file to a different folder than the default public folder in the directory where the script is executed.

generate-versioned-pages \
--project-id 43170198 \
--job-name pages \
--output-dir somewhere/else

The folder and it's may required parent directories are automatically generated. The output file name is fixed as index.html

Version info file

To get more informations about the used tags, the --create-version-info-file argument can be used. This will generate a versions.json file in the output directory containing all GitLab ProjectTag and GitLab ProjectCommit attributes, the Job ID and the Pages URL.

Limitations

  • Only links to tagged and archived data of public folders are included in the index
  • Job artifacts must be publicly accessible if no API token is used
    • Make sure that CI/CD is activated and set to Everyone With Access at Settings -> General -> Visibility

Metadata

Release files for lightweight-versioned-gitlab-pages 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lightweight-versioned-gitlab-pages 0.3.2
File Size Uploaded Provenance Actions
lightweight-versioned-gitlab-pages-0.3.2.tar.gz 18.1 kB Without provenance Details for lightweight-versioned-gitlab-pages-0.3.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lightweight-versioned-gitlab-pages 0.3.2
File Interpreter ABI Platform Actions
lightweight_versioned_gitlab_pages-0.3.2-py3-none-any.whl Python 3 none any Details for lightweight_versioned_gitlab_pages-0.3.2-py3-none-any.whl

Total release size: 29.4 kB

Release files / lightweight-versioned-gitlab-pages-0.3.2.tar.gz

Download URL lightweight-versioned-gitlab-pages-0.3.2.tar.gz
Size 18.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9d1c1386ce61aa377f05a8df7f9e13b25b51edab5b7b287d846fe60be9d9b076
BLAKE2b-256 checksum
How to use checksums
4026ce9e5379dc4e128d27952ed78920317a2987051e139c43c17b0f80da4aef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Release files / lightweight_versioned_gitlab_pages-0.3.2-py3-none-any.whl

Download URL lightweight_versioned_gitlab_pages-0.3.2-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4e175cb6682dcef80f6c55afb2af08b2dc5064c59cf0fe049511fc4cc43ef307
BLAKE2b-256 checksum
How to use checksums
2c79e63c024f60be713977c01244b9a02ce3e73cf64018ac9ab2e8c8fe885d93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Security for lightweight-versioned-gitlab-pages 0.3.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page