Unverified Commit 6f3c4a2a authored by GridexX's avatar GridexX
Browse files

feat: update pages job

* Add variable `PAGES_REDIRECTION_FILE`
parent 34cea735
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
# Changelog
All notable changes to this job will be documented in this file.

## [0.5.0] - 2022-07-22
* Add variable `PAGES_REDIRECTION_FILE`
## [0.4.0] - 2022-06-13
* Add docker image tag in variable 

+12 −13
Original line number Diff line number Diff line
## Objective

Publish HTML documentation located in `public` folder, retrieved as an artifact
from previous job named `documentation`.
Deploy a static website using GitLab Pages.  
This job can be used to deploy documentation, a static website or a Single Page Application.  

## How to use it

!!! note "Requirements"
    You have to use a job which build your documentation in a previous stage.
    We recommend you to use a documentation job available on the hub in [build
    📦 stage](/jobs/#build). They build documentation and publish it as
    artifact in `website_build/` folder.

!!! note "Documentation jobs list:"
    * [ApiDoc](/jobs/build/apidoc/)
    * [Mkdocs](/jobs/build/mkdocs/)
    * [Doxygen](/jobs/build/doxygen/)
    * [PHPDocumentor](/jobs/build/phpdocumentor/)
    * [OpenAPI](/jobs/build/openapi/)
    You have to use a job which build your website in a previous stage. *We recommend you to use a jobs available on the hub in `build`*. They build a static site of your application and publish it as artifact in `website_build/` folder .  
    📗 To generate documentation you could use [mkdocs](https://r2devops.io/_/r2devops-bot/mkdocs)  
    🕸️ To deploy a SPA, you could use [npm_build](https://r2devops.io/_/r2devops-bot/npm_build) or [yarn_build](https://r2devops.io/_/r2devops-bot/yarn_build). 
      
!!! info "How to deploy a SPA ?"
    In case, you want to deploy a SPA, you will only have one root file `index.html`, with your own rooting system. **Therefore, it's important that all requests are rewritten to this file.**  
    To do so create a `_redirects` file inside the root of your repository and set the variable `PAGES_REDIRECTION_FILE` to `_redirects`. Finally add this content inside the file :  
    `/* /index.html 200`   
    For more information, check the [documentation](https://docs.gitlab.com/ee/user/project/pages/redirects.html#rewrite-all-requests-to-a-root-indexhtml).

1. Copy the job URL located in the `Install` part of the right panel and add it inside the `include` list of your `.gitlab-ci.yml` file (see the [quick setup](/use-the-hub/#quick-setup)). You can specify [a fixed version](#changelog) instead of `latest`.
2. If you need to customize the job (stage, variables, ...) 👉 check the [jobs
@@ -34,6 +32,7 @@ from previous job named `documentation`.
| Name | Description | Default |
| ---- | ----------- | ------- |
| `PAGES_BUILD_PATH` | Path to folder which contains the static website files to publish | `website_build/` |
| `PAGES_REDIRECTION_FILE` | Path to file which contains [redirection routes](https://docs.gitlab.com/ee/user/project/pages/redirects.html#create-redirects) for the website. | ` `



+4 −1
Original line number Diff line number Diff line
@@ -7,12 +7,15 @@ pages:
  stage: deploy
  variables:
    PAGES_BUILD_PATH: 'website_build/'
    PAGES_REDIRECTION_FILE: ""
  script:
    - if [ "$PAGES_BUILD_PATH" != "public" -a "$PAGES_BUILD_PATH" != "public/" ]; then
    -   if [ -d "public" ]; then rm -rf public; fi
    -   mv "$PAGES_BUILD_PATH" public
    - fi

    - if [ ! -z $PAGES_REDIRECTION_FILE ]; then
    -   cat $PAGES_REDIRECTION_FILE > public/_redirects
    - fi
    - if [ ! -d "public" ]; then echo "Nothing to deploy"; exit 1; fi
  artifacts:
    paths: