Add a GO_PROJECT_DIR variable to be compatible with monorepo projects

Description

Today, in a project having multiple apps (Go and non-Go apps) in dedicated folders, the template won't work as it expects the go.mod to be at the project's root. As a workaround, we can override all the Go jobs to add a cd to the source folder as follows:

include:
  - project: "to-be-continuous/golang"
    ref: "1.3.0"
    file: "templates/gitlab-ci-golang.yml"

stages:
  - build
  - test

.go-base:
  parallel:
    matrix:
      - GO_TARGET_OS: "windows"
        GO_TARGET_ARCH: "amd64"
        GO_PROJECT_DIR: "backend"
      - GO_TARGET_OS: "linux"
        GO_TARGET_ARCH: "amd64"
        GO_PROJECT_DIR: "backend"
      - GO_TARGET_OS: "linux"
        GO_TARGET_ARCH: "arm"
        GO_PROJECT_DIR: "backend"
      - GO_TARGET_OS: "windows"
        GO_TARGET_ARCH: "amd64"
        GO_PROJECT_DIR: "authserver"
      - GO_TARGET_OS: "linux"
        GO_TARGET_ARCH: "amd64"
        GO_PROJECT_DIR: "authserver"
      - GO_TARGET_OS: "linux"
        GO_TARGET_ARCH: "arm"
        GO_PROJECT_DIR: "authserver"

go-build:
  before_script:
    - !reference [.go-base, before_script]
    - cd ${GO_PROJECT_DIR}

go-test:
  before_script:
    - !reference [.go-base, before_script]
    - cd ${GO_PROJECT_DIR}

go-ci-lint:
  before_script:
    - !reference [.go-base, before_script]
    - cd ${GO_PROJECT_DIR}

go-mod-outdated:
  before_script:
    - !reference [.go-base, before_script]
    - cd ${GO_PROJECT_DIR}

But it gets the YAML complex and moveover, it forces to know and synchronize the job names with the template's ones. If a job is renamed, removed or added in the template, the pipeline will fail.

Implementation ideas

It would be better to have a GO_PROJECT_DIR variable in the template that would be used to change the current directory before running the job.

The YAML would be much more simple:

include:
  - project: "to-be-continuous/golang"
    ref: "1.3.0"
    file: "templates/gitlab-ci-golang.yml"

stages:
  - build
  - test

.go-base:
  parallel:
    matrix:
      - GO_TARGET_OS: "windows"
        GO_TARGET_ARCH: "amd64"
        GO_PROJECT_DIR: "backend"
      - GO_TARGET_OS: "linux"
        GO_TARGET_ARCH: "amd64"
        GO_PROJECT_DIR: "backend"
      - GO_TARGET_OS: "linux"
        GO_TARGET_ARCH: "arm"
        GO_PROJECT_DIR: "backend"
      - GO_TARGET_OS: "windows"
        GO_TARGET_ARCH: "amd64"
        GO_PROJECT_DIR: "authserver"
      - GO_TARGET_OS: "linux"
        GO_TARGET_ARCH: "amd64"
        GO_PROJECT_DIR: "authserver"
      - GO_TARGET_OS: "linux"
        GO_TARGET_ARCH: "arm"
        GO_PROJECT_DIR: "authserver"
Edited by Boris