Skip to content
Snippets Groups Projects
Unverified Commit 4fa37824 authored by Andrew Newdigate's avatar Andrew Newdigate
Browse files

feat: add shfmt task

parent 228e5635
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -20,7 +20,7 @@ stages:
 
include:
- project: 'gitlab-com/gl-infra/common-ci-tasks'
ref: v1.11.0 # renovate:managed
ref: v1.12.0 # renovate:managed
file: 'gitlab-scanners.yml'
```
 
Loading
Loading
@@ -34,7 +34,7 @@ stages:
 
include:
- project: 'gitlab-com/gl-infra/common-ci-tasks'
ref: v1.11.0 # renovate:managed
ref: v1.12.0 # renovate:managed
file: 'golangci-lint.yml'
```
 
Loading
Loading
@@ -50,7 +50,7 @@ stages:
 
include:
- project: 'gitlab-com/gl-infra/common-ci-tasks'
ref: v1.11.0 # renovate:managed
ref: v1.12.0 # renovate:managed
file: 'editorconfig-check.yml'
```
 
Loading
Loading
@@ -91,7 +91,7 @@ stages:
 
include:
- project: 'gitlab-com/gl-infra/common-ci-tasks'
ref: v1.11.0 # renovate:managed
ref: v1.12.0 # renovate:managed
file: 'semantic-release.yml'
```
 
Loading
Loading
@@ -173,7 +173,7 @@ variables:
include:
# build binary release artifacts with goreleaser
- project: 'gitlab-com/gl-infra/common-ci-tasks'
ref: v1.11.0 # renovate:managed
ref: v1.12.0 # renovate:managed
file: goreleaser.yml
```
 
Loading
Loading
@@ -202,7 +202,7 @@ include:
# and that ASDF is generally working
# see https://gitlab.com/gitlab-com/gl-infra/common-ci-tasks/-/blob/main/README.md#asdf-tool-versions
- project: 'gitlab-com/gl-infra/common-ci-tasks'
ref: v1.11.0 # renovate:managed
ref: v1.12.0 # renovate:managed
file: asdf-tool-versions.yml
```
 
Loading
Loading
@@ -235,7 +235,7 @@ include:
 
# Runs tflint on all terraform module directories
- project: 'gitlab-com/gl-infra/common-ci-tasks'
ref: v1.11.0 # renovate:managed
ref: v1.12.0 # renovate:managed
file: tflint.yml
```
 
Loading
Loading
@@ -259,7 +259,7 @@ include:
 
# Ensures that all terraform files are correctly formatted
- project: 'gitlab-com/gl-infra/common-ci-tasks'
ref: v1.11.0 # renovate:managed
ref: v1.12.0 # renovate:managed
file: terraform-format.yml
```
 
Loading
Loading
@@ -283,7 +283,7 @@ include:
 
# Ensures that all terraform files are syntactically valid
- project: 'gitlab-com/gl-infra/common-ci-tasks'
ref: v1.11.0 # renovate:managed
ref: v1.12.0 # renovate:managed
file: terraform-validate.yml
```
 
Loading
Loading
@@ -318,7 +318,7 @@ include:
# Upgrades dependencies on a schedule
# see https://gitlab.com/gitlab-com/gl-infra/common-ci-tasks/-/blob/main/README.md#renovate-bot
- project: 'gitlab-com/gl-infra/common-ci-tasks'
ref: v1.11.0 # renovate:managed
ref: v1.12.0 # renovate:managed
file: renovate-bot.yml
```
 
Loading
Loading
@@ -343,11 +343,10 @@ include:
# Runs Go unit tests
# see https://gitlab.com/gitlab-com/gl-infra/common-ci-tasks/-/blob/main/README.md#go-unittests
- project: 'gitlab-com/gl-infra/common-ci-tasks'
ref: v1.11.0 # renovate:managed
ref: v1.12.0 # renovate:managed
file: go-unittests.yml
```
 
### [`go-mod-tidy`](./go-mod-tidy.yml)
 
Ensures that [`go mod tidy`](https://go.dev/ref/mod) is up-to-date and `go.mod` and `go.sum` are tidy.
Loading
Loading
@@ -372,3 +371,29 @@ include:
ref: v1.12.0 # renovate:managed
file: go-mod-tidy.yml
```
### [`shfmt`](./shfmt.yml)
Validates that shell-scripts use a canonical formatting.
1. Ensure that the `GL_ASDF_SHFMT_VERSION` version for Go is configured.
```yaml
stages:
- validate
# Not needed if .gitlab-ci-asdf-versions.yml is included...
variables:
GL_ASDF_SHFMT_VERSION: ...
include:
# Not required, but recommended
- local: .gitlab-ci-asdf-versions.yml
# Ensure that all shell-scripts are formatted according to a
# standard canonical format
- project: 'gitlab-com/gl-infra/common-ci-tasks'
ref: v1.13.0 # renovate:managed
file: shfmt.yml
```
shfmt:
stage: validate
needs: []
image:
name: golang:1.17 # Client project doesn't need Golang, so don't use ASDF vars here.
entrypoint: [""]
script:
- go install mvdan.cc/sh/v3/cmd/shfmt@v${GL_ASDF_SHFMT_VERSION}
# Find all *.sh files, and any executable script files
- (
find . -type f \( -perm -u=x -not -name "*.sh" \) -not -path "*/.*/*" -print0 | xargs -0 grep -rIzlE '^#![[:blank:]]*(/usr/bin/env sh|/usr/bin/env bash|/bin/sh|/bin/bash)';
find . -type f -name "*.sh" -not -path "*/.*/*"
) | xargs shfmt -w -l -s -i 2 -d
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment