Commit a1376b7f authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

Merge branch 'add-go-project-dir-variable' into 'master'

Add GO_PROJECT_DIR variable

See merge request to-be-continuous/golang!11
parents 33ced230 ce66c088
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ The Go template uses some global configuration used throughout all jobs.
| --------------------- | ---------------------------------------------- | ----------------- |
| `GO_IMAGE`            | The Docker image used to run Go for `go-build` <br/>:warning: **set the version required by your project** | `golang:buster`   |
| `GO_TEST_IMAGE`       | The Docker image used to run Go for `go-test` <br/>:warning: **set the version required by your project**  | _none_            |
| `GO_PROJECT_DIR`      | Go project root directory                      | `.`               |
| `GOPROXY`             | URL of Go module proxy                         | _none_            |

## Jobs
+35 −51
Original line number Diff line number Diff line
@@ -9,6 +9,12 @@
      "description": "The Docker image used to run Go (build+test or build only) - **set the version required by your project**",
      "default": "golang:buster"
    },
    {
      "name": "GO_PROJECT_DIR",
      "description": "Go project root directory",
      "default": ".",
      "advanced": true
    },
    {
      "name": "GOPROXY",
      "description": "URL of Go module proxy (see [Go env](https://golang.org/cmd/go/#hdr-Environment_variables))",
@@ -19,25 +25,6 @@
      "description": "Specific Docker image used to run Go tests (as a separate job)",
      "advanced": true
    },
    {
      "name": "GO_TEST_ARGS",
      "description": "Arguments used by the test command",
      "default": "test -mod=readonly -v -coverprofile=reports/coverage.out -race ./...",
      "advanced": true
    },
    {
      "name": "GO_LIST_ARGS",
      "description": "Arguments used by the list command",
      "default": "list -u -m -mod=readonly -json all",
      "advanced": true
    }
  ],
  "features": [
    {
      "id": "go-build",
      "name": "go build",
      "description": "[go build](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies)",
      "variables": [
    {
      "name": "GO_BUILD_FLAGS",
      "description": "Flags used by the [go build command](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies)",
@@ -47,8 +34,7 @@
    {
      "name": "GO_BUILD_PACKAGES",
      "description": "Packages to build with the [go build command](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies)",
          "default": "./...",
          "advanced": true
      "default": "./..."
    },
    {
      "name": "GO_TARGET_OS",
@@ -59,14 +45,7 @@
      "name": "GO_TARGET_ARCH",
      "description": "The `$GOARCH` target [see available values](https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63)\n\nFallbacks to default `$GOARCH` from the Go Docker image",
      "advanced": true
        }
      ]
    },
    {
      "id": "go-test",
      "name": "go test",
      "description": "[go test](https://pkg.go.dev/cmd/go#hdr-Test_packages)",
      "variables": [
    {
      "name": "GO_TEST_FLAGS",
      "description": "Flags used by the [go test command](https://pkg.go.dev/cmd/go#hdr-Test_packages)",
@@ -76,11 +55,16 @@
    {
      "name": "GO_TEST_PACKAGES",
      "description": "Packages to test with the [go test command](https://pkg.go.dev/cmd/go#hdr-Test_packages)",
          "default": "./...",
      "default": "./..."
    },
    {
      "name": "GO_LIST_ARGS",
      "description": "Arguments used by the list command",
      "default": "list -u -m -mod=readonly -json all",
      "advanced": true
    }
      ]
    },
  ],
  "features": [
    {
      "id": "golangci-lint",
      "name": "GolangCI-Lint",
+15 −11
Original line number Diff line number Diff line
@@ -14,6 +14,9 @@
# Floor, Boston, MA  02110-1301, USA.
# =========================================================================================
variables:
  # Default Go project root directory
  GO_PROJECT_DIR: .

  # Default Docker image (can be overridden)
  GO_IMAGE: "golang:buster"

@@ -282,16 +285,17 @@ stages:
      command: ["--service", "golang", "2.0.3" ]
  variables:
    # The directory where 'go install' will install a command.
    GOBIN: "$CI_PROJECT_DIR/bin"
    GOBIN: "$CI_PROJECT_DIR/$GO_PROJECT_DIR/bin"
    # The directory where the go command will store cached information for reuse in future builds.
    GOCACHE: "$CI_PROJECT_DIR/.cache"
    GOCACHE: "$CI_PROJECT_DIR/$GO_PROJECT_DIR/.cache"
  cache:
    key: "$CI_COMMIT_REF_SLUG-golang"
    paths:
      - .cache/
      - $GO_PROJECT_DIR/.cache/
  before_script:
    - *go-scripts
    - install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}"
    - cd ${GO_PROJECT_DIR}

go-build:
  extends: .go-base
@@ -302,7 +306,7 @@ go-build:
    name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
    expire_in: 1 day
    paths:
      - bin/
      - $GO_PROJECT_DIR/bin/
  rules:
    # exclude merge requests
    - if: $CI_MERGE_REQUEST_ID
@@ -322,9 +326,9 @@ go-test:
    expire_in: 1 day
    reports:
      junit:
        - "reports/junit-*.xml"
        - "$GO_PROJECT_DIR/reports/junit-*.xml"
    paths:
      - reports/
      - $GO_PROJECT_DIR/reports/
  rules:
    # exclude merge requests
    - if: $CI_MERGE_REQUEST_ID
@@ -344,10 +348,10 @@ go-build-test:
    expire_in: 1 day
    reports:
      junit:
        - "reports/junit-*.xml"
        - "$GO_PROJECT_DIR/reports/junit-*.xml"
    paths:
      - bin/
      - reports/
      - $GO_PROJECT_DIR/bin/
      - $GO_PROJECT_DIR/reports/
  rules:
    # exclude merge requests
    - if: $CI_MERGE_REQUEST_ID
@@ -367,7 +371,7 @@ go-ci-lint:
    expire_in: 1 day
    when: always
    paths:
      - reports/
      - $GO_PROJECT_DIR/reports/
  rules:
    # exclude merge requests
    - if: $CI_MERGE_REQUEST_ID
@@ -394,7 +398,7 @@ go-mod-outdated:
    expire_in: 1 day
    when: always
    paths:
      - reports/
      - $GO_PROJECT_DIR/reports/
  rules:
    # exclude merge requests
    - if: $CI_MERGE_REQUEST_ID