Skip to content

Commit 05e90fb

Browse files
RothAndrewjeff-mccoy
authored andcommitted
Pre-commit and linting (zarf-dev#112)
Signed-off-by: Jeff McCoy <code@jeffm.us>
1 parent 0ca3d5f commit 05e90fb

28 files changed

+132
-85
lines changed

.editorconfig

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ trim_trailing_whitespace = true
1010
max_line_length = 120
1111
tab_width = 4
1212

13+
[{Makefile,go.mod,go.sum,*.go,.gitmodules}]
14+
indent_style = tab
15+
indent_size = 4
16+
1317
[*.md]
1418
trim_trailing_whitespace = false
15-
16-
[Makefile]
17-
indent_style = tab

.gitlab-ci.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ stages:
99
only:
1010
- master
1111
- merge_requests
12-
- tags
12+
- tags
1313

1414
compile:
15-
only:
15+
only:
1616
- branches
1717
- merge_requests
1818
- tags
@@ -42,7 +42,7 @@ package:
4242
- echo "PACKAGE_JOB_ID=$CI_JOB_ID" >> job.env
4343
artifacts:
4444
reports:
45-
dotenv: job.env
45+
dotenv: job.env
4646
paths:
4747
- build/
4848

@@ -54,7 +54,7 @@ e2e:
5454
artifacts: true
5555
tags:
5656
- bigbang
57-
- packages
57+
- packages
5858
before_script:
5959
- yum install openssh-clients -y
6060
- eval $(ssh-agent -s)

.pre-commit-config.yaml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.0.1
4+
hooks:
5+
- id: check-added-large-files
6+
- id: check-merge-conflict
7+
- id: detect-aws-credentials
8+
args:
9+
- "--allow-missing-credentials"
10+
- id: detect-private-key
11+
exclude: "^examples/big-bang/template/bigbang/values.yaml$"
12+
- id: end-of-file-fixer
13+
- id: fix-byte-order-marker
14+
- id: trailing-whitespace
15+
args: [--markdown-linebreak-ext=md]
16+
- repo: https://github.com/sirosen/fix-smartquotes
17+
rev: 0.2.0
18+
hooks:
19+
- id: fix-smartquotes
20+
- repo: https://github.com/dnephin/pre-commit-golang
21+
rev: v0.4.0
22+
hooks:
23+
- id: go-fmt
24+
# Commenting this one out for now since it fails
25+
## Normally we wouldn't need to do a local hook but we need to modify the shell script that gets run to first change directories into the `cli` folder
26+
# - repo: local
27+
# hooks:
28+
# - id: golangci-lint
29+
# name: golangci-lint
30+
# entry: hooks/run-golangci-lint.sh
31+
# types: [ go ]
32+
# language: script
33+
# pass_filenames: false
34+
# description: "Runs `golangci-lint`, requires https://github.com/golangci/golangci-lint"

.vscode/launch.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
},
2020

2121
]
22-
}
22+
}

CONTRIBUTING.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ Here's what a typical "day in the life" of a Zarf developer might look like. Kee
3838

3939
This section dives deeper into how we test Zarf
4040

41+
### Pre-Commit Hooks and Linting
42+
43+
In this repo we use [pre-commit](https://pre-commit.com/) hooks for automated validation and linting. The CI pipeline will validate that all of the hooks pass so we strongly recommend that you install the hooks locally or you'll be spending a lot of time manually fixing issues that could be fixed automatically very quickly.
44+
45+
#### Pre-Commit Prerequisites
46+
47+
1. Install [pre-commit](https://pre-commit.com/)
48+
1. Install [go](https://golang.org/)
49+
1. Install [golangci-lint](https://github.com/golangci/golangci-lint)
50+
1. Run `pre-commit install` in the repo to install the pre-commit hooks. This will make the hooks run automatically each time you `git commit`. If you want to skip the hooks for any reason you can run `git commit --no-verify` to skip them.
51+
52+
> **HINT:** *Consider [automatically enabling the hooks in every Git repository](https://pre-commit.com/#automatically-enabling-pre-commit-on-repositories)*
53+
4154
### End2End Testing
4255

4356
Our E2E tests utilize [Terratest](https://terratest.gruntwork.io/). They create real infrastructure in AWS that the tests get run on. By doing this we are able to make the test environments ephemeral and allow them to be run in parallel so that we can do more testing more quickly.
@@ -50,4 +63,4 @@ We're still working on building out the test suite. If you want to help check ou
5063
- [#99](https://github.com/defenseunicorns/zarf/issues/99): Writing additional tests
5164
- [#100](https://github.com/defenseunicorns/zarf/issues/100): Each test should be runnable locally
5265
- [#101](https://github.com/defenseunicorns/zarf/issues/101): Run E2E tests on multiple distros
53-
- [#102](https://github.com/defenseunicorns/zarf/issues/102): Make the E2E tests more efficient
66+
- [#102](https://github.com/defenseunicorns/zarf/issues/102): Make the E2E tests more efficient

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ General usage steps below. For various ways to use Zarf, see [the examples fold
1818

1919
[![asciicast](https://asciinema.org/a/427846.svg)](https://asciinema.org/a/427846)
2020
### 2. Create the zarf cluster
21-
- Move the `zarf`, `zarf-init.tar.zst` files to the system you will install the cluster to.
21+
- Move the `zarf`, `zarf-init.tar.zst` files to the system you will install the cluster to.
2222
- Login or sudo/su to root.
2323
- Run `./zarf init` and follow the wizard.
2424
[![asciicast](https://asciinema.org/a/427721.svg)](https://asciinema.org/a/427721)
2525

26-
### 3. Add resources to the zarf cluster
26+
### 3. Add resources to the zarf cluster
2727
- Following step 1b, make any necessary edits to the `zarf.yaml` file.
2828
- Then run `./zarf package create` to produce an `zarf-package-*.tar.zst` package.
2929
- Move the `zarf-package` into the same folder on the running zarf cluster as in step 2a.
@@ -43,10 +43,10 @@ This tool utilizes software pulled from multiple sources and _some_ of them requ
4343
- [Iron Bank](https://registry1.dso.mil/) : Platform One's authorized, hardened, and approved container repository. ([product](https://p1.dso.mil/#/products/iron-bank/) | [pages](https://ironbank.dso.mil/) | [register](https://login.dso.mil/register))
4444

4545
#### Local Environment
46-
- MacOS or Linux Operating System
46+
- MacOS or Linux Operating System
4747
- [`make`](https://www.gnu.org/software/make/) : We use Makefiles for build automation
4848
- [`vagrant`](https://www.vagrantup.com/) : Easy creation and management of clean dev/test environments
49-
- [`go`](https://golang.org/) : The programming language. Right now we are using v1.16.x
49+
- [`go`](https://golang.org/) : The programming language. Right now we are using v1.16.x
5050

5151
---
5252

@@ -103,7 +103,7 @@ All OS options:
103103
- centos7
104104
- centos8
105105
- ubuntu
106-
- debian
106+
- debian
107107
- rocky
108108

109109
In less than a minute, you'll have a kubernetes cluster running all the pre-requisites needed to host and deploy multiple other downstream clusters.

assets/manifests/common/traefik-tls.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ spec:
1616
redirectRegex:
1717
regex: ^http://(.*)
1818
replacement: https://${1}
19-
permanent: true
19+
permanent: true

assets/manifests/logging/pgl-stack.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ spec:
6363
extraVolumeMounts:
6464
- name: journal
6565
mountPath: /var/log/journal
66-
readOnly: true
66+
readOnly: true
6767
image:
6868
pullPolicy: Never

assets/misc/k9s-theme.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,4 @@ k9s:
108108
bgColor: *background
109109
indicator:
110110
fgColor: *foreground
111-
bgColor: *purple
111+
bgColor: *purple

assets/scripts/k3s-remove.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,4 @@ rm -f /usr/local/bin/k9s
9696
rm -f /usr/local/bin/k3s-remove.sh
9797
rm -fr zarf-pki
9898

99-
echo -e '\033[0m'
99+
echo -e '\033[0m'

assets/scripts/k3s.service

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ RestartSec=5s
2424
ExecStartPre=/bin/sh -xc '! /usr/bin/systemctl is-enabled --quiet nm-cloud-setup.service'
2525
ExecStartPre=-/sbin/modprobe br_netfilter
2626
ExecStartPre=-/sbin/modprobe overlay
27-
ExecStart=/usr/local/bin/k3s server --write-kubeconfig-mode=700
27+
ExecStart=/usr/local/bin/k3s server --write-kubeconfig-mode=700

cli/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ build
77
.env
88
.image-cache/
99
.DS_Store
10-
bundle/
10+
bundle/

cli/.gitlab-ci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,3 @@ release-from-tag:
3737
- echo "Creating a release for $CI_COMMIT_TAG"
3838
- release-cli create --name "Zarf CLI ${CI_COMMIT_TAG}" --tag-name "${CI_COMMIT_TAG}" --description "CLI for Zarf"
3939
--assets-link "{\"name\":\"zarf\",\"url\":\"https://repo1.dso.mil/platform-one/big-bang/apps/product-tools/zarf/cli/-/jobs/${JOB_ID}/artifacts/raw/zarf\"}"
40-

0 commit comments

Comments
 (0)