Commit 2b4b52be authored by Thomas Boni's avatar Thomas Boni
Browse files

Merge branch '456-new-job-create-go-fmt-job' into 'latest'

Resolve "[New job] Create go fmt job"

Closes #456

See merge request r2devops/hub!275
parents dd91a9d6 0506a7d2
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ ENV
eslint
exe
fka
fmt
fontawesome
Fortran
frontend
@@ -93,6 +94,8 @@ Gitleaks
gitleaks
glibc
globals
Gofmt
gofmt
Golang
golangci
gosec
@@ -394,4 +397,3 @@ Hotjar
Hotjar's
pseudonymized
de

jobs/gofmt/README.md

0 → 100644
+32 −0
Original line number Diff line number Diff line
## Objective

Gofmt formats Go programs. It uses tabs for indentation and blanks for alignment. Alignment assumes that an editor is using a fixed-width font.

⚠️ A golang code must be compliant with go fmt so when job catches something to update, it fails.

## How to use it

1. Add this job URL 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`.
    ```yaml
      - remote: 'https://jobs.r2devops.io/latest/gofmt.yml'
    ```
1. If you need to customize the job (stage, variables, ...) 👉 check the [jobs
   customization](/use-the-hub/#jobs-customization)
1. Well done, your job is ready to work ! 😀

## Job details

* Job name: `gofmt`
* Docker image:
[`golang:1.17-alpine3.14`](https://hub.docker.com/layers/golang/library/golang/1.17-alpine3.14/images/sha256-0bf16905b2757f1dcf6e78b1d14c223a38ade123c97bdd61a5cfcc4e77136040)
* Default stage: `static_tests`
* When: `always`

### Variables

| Name | Description | Default |
| ---- | ----------- | ------- |
| `GOFMT_OPTIONS` <img width=100/> | List of options to pass to gofmt <img width=175/>| ` ` <img width=100/>|
| `PROJECT_ROOT` <img width=100/> | Path to the directory containing your Go project root| `.` |
| `GOFMT_PRINT_DIFF` <img width=100/> | Print diffs to standard output| `true` |
| `GOFMT_PRINT_FILENAME` <img width=100/> | Print filenames to standard output| `false` |

jobs/gofmt/gofmt.yml

0 → 100644
+33 −0
Original line number Diff line number Diff line
stages:
  - static_tests

gofmt:
    image: golang:1.17-alpine3.14
    stage: static_tests
    variables:
        # List of option to pass to the cmdline
        GOFMT_OPTIONS: ""
        # Path to run gofmt tool
        PROJECT_ROOT: "."
        #  Print diffs to standard output -d
        GOFMT_PRINT_DIFF: "true"
        # Print filenames to standard output -l
        GOFMT_PRINT_FILENAME: "false"
        # Generate a temporary file as an output.
        GOFMT_OUTPUT_FILE: "gofmt_output_file"


    script:
      - if [ "$GOFMT_PRINT_DIFF" == "true" ]; then
      -      GOFMT_OPTIONS="$GOFMT_OPTIONS -d"
      - fi
      - if [ "$GOFMT_PRINT_FILENAME" == "true" ]; then
      -     GOFMT_OPTIONS="$GOFMT_OPTIONS -l"
      - fi
      - cd $PROJECT_ROOT
      - gofmt $GOFMT_OPTIONS . >> $GOFMT_OUTPUT_FILE
      - cat $GOFMT_OUTPUT_FILE
      - value=$( cat $GOFMT_OUTPUT_FILE | wc -l )
      - if [ $value -gt 1 ]; then
      -     exit 1
      - fi

jobs/gofmt/job.yml

0 → 100644
+12 −0
Original line number Diff line number Diff line
name: gofmt
description: Gofmt formats Go programs. It uses tabs for indentation and blanks for alignment. Alignment assumes that an editor is using a fixed-width font.
default_stage: static_tests
icon: 📃
maintainer: coconux
license: MIT
images:
  golang:1.17-alpine3.14
tools:
labels:
    - Go
    - Lint
+0 −0

Empty file added.

Loading